Difference between revisions of "User:Dee/Flicker handling"

From HashVB
Jump to: navigation, search
(Initial version)
 
m (Adjusted wording)
 
Line 2: Line 2:
 
{{VB6}}
 
{{VB6}}
  
VB6 seems to ignore the erasebackground message and do it's background drawing internally in wm_paint.
+
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 eat both messages and override VBs wm_paint handling, set everytign up and call the paint event ourselves.
+
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 immediatly.
+
We make sure the messages are not passed on to the next handler by telling the subclasser not to call CallWindowProc() but return immediately.
  
 
<pre>
 
<pre>

Latest revision as of 21:32, 5 April 2010

 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