tags:

views:

473

answers:

1

Edit: I updated version 2. Now It's monochrome. I tried to fix it by making sure to call CreateCOmpatibleBitmap with the window's DC rather than the memdc (as written), but it is still wrong :(

Below are 3 different simplified versions of functions I have written. Version 1 works perfectly (but has flicker, obviously), version 2 does nothing, and version 3 fills the entire form with black. What is wrong with version 2? Scalemode is set to vbPixels.

Version 1:

Private Sub Form_Paint()
    Me.Cls
    DrawStuff Me.hDc
End Sub

Version 2 (new):

Private Sub Form_Paint()
    Me.Cls
    If m_HDCmem = 0 then
        m_HDC = GetDC(hwnd)
        m_HDCmem = CreateCompatibleDC(m_HDC)
        m_HBitmap = CreateCompatibleBitmap(m_HDC, Me.ScaleWidth, Me.ScaleHeight)
        ReleaseDC Null, m_HDC
        SelectObject m_HDCmem, m_HBitmap
    End If
    DrawStuff m_HDCmem
    Debug.Print BitBlt(Me.hDc, 0, 0, Me.ScaleWidth, Me.ScaleHeight, m_HDCmem, 0, 0, SRCCOPY) 'During testing, this printed "1"
    Me.Refresh
End Sub

Version 3:

Private Sub Form_Paint()
    Me.Cls
    If m_HDC = 0 Then m_HDC = CreateCompatibleDC(Me.hDc)
    DrawStuff m_HDC
    BitBlt(Me.hDc, 0, 0, Me.ScaleWidth, Me.ScaleHeight, m_HDC, 0, 0, BLACKNESS) 'During testing, this printed "1"
    Me.Refresh
End Sub

Note: I stuck the code below in my resize function immediately before the call to paint. It did not help, but I'm pretty sure I should leave it there:

If m_HDC <> 0 Then DeleteDC m_HDC
m_HDC = 0
+1  A: 

in Version 2 & 3 your call to CreateCompatibleDC() builds a monochrome drawing surface that is 1 pixel by 1 pixel. You need to call CreateCompatibleBitmap() somewhere in there.

see here

Scott Evernden
It's monocrhome, but working. Apparently this issue is common, but the fix I saw did not help.
Brian