User:Dee/Flicker handling

From HashVB
< User:Dee
Revision as of 21:32, 5 April 2010 by Dee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
 This article is currently work in progress. Please come back later.
float
 This article is based on Visual Basic 6. Find other Visual Basic 6 articles.

VB6 seems to ignores the WM_ERASEBKGND message and deso its background drawing internally in the WM_PAINT message. This can cause flickering so to "fix" this, we handle both messages and override VB's own WM_PAINT handling, set everything up and call the paint event ourselves. We make sure the messages are not passed on to the next handler by telling the subclasser not to call CallWindowProc() but return immediately.

Private Function SubClassed_WindowProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long, Handled As Boolean) As Long
Dim PaintInfo As PAINTSTRUCT
Dim hDC As Long
 
  Select Case hWnd
  Case GraphFrame.hWnd
    Select Case Msg
    Case &HF 'WM_PAINT
      'We handle WM_PAINT ourselves as VB6 seems to explicitly draw the background in its handler
      hDC = BeginPaint(hWnd, PaintInfo)
      GraphFrame_Paint
      EndPaint hWnd, PaintInfo
      'We've handled it so VB doesn't do anything further
      SubClassed_WindowProc = 0
      Handled = True
 
    Case &H14 'WM_ERASEBKGND
      'WM_ERASEBKGND seems to be a noop, but we handle it here anyway
      SubClassed_WindowProc = -1
      Handled = True
 
    Case &H137 'WM_CTLCOLORSCROLLBAR
      'Ignore the message to fix the scrollbar background
      Handled = True
 
    End Select
  End Select
End Function