Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Declare Function GetObjectAPI Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
Private Declare Function GetClientRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hBrush As Long) As Long
Private Declare Function SelectClipRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long) As Long
Private Declare Function ExcludeClipRect Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function ValidateRectBynum Lib "user32" Alias "ValidateRect" (ByVal hwnd As Long, ByVal lpRect As Long) As Long
Const COLOR_BACKGROUND = 1
Private Const SRCCOPY = &HCC0020 ' (DWORD) dest = source
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
' Bitmap Header Definition
Private Type BITMAP
bmType As Long
bmWidth As Long
bmHeight As Long
bmWidthBytes As Long
bmPlanes As Integer
bmBitsPixel As Integer
bmBits As Long
End Type
Private Sub MDIForm_Load()
' Subclass the MDI client window
SubClass1.HwndParam = GetWindow(hwnd, GW_CHILD)
Form1.Show
End Sub
Private Sub SubClass1_WndMessage(hwnd As OLE_HANDLE, msg As OLE_HANDLE, wp As OLE_HANDLE, lp As Long, retval As Long, nodef As Integer)
Dim tdc&
Dim usedc&
Dim oldbm&
Dim bm As BITMAP
Dim rc As RECT
Dim offsx&, offsy&
Debug.Print "Erasebkgnd"
' Get a DC to draw into
usedc = GetDC(hwnd)
' Create a compatible DC to use
tdc = CreateCompatibleDC(usedc)
' Gets the bitmap handle of the background bitmap
oldbm = SelectObject(tdc, Picture1.Picture)
Call GetObjectAPI(Picture1.Picture, Len(bm), bm)
Call GetClientRect(hwnd, rc)
' Decide where to place the MDI client logo
offsx = 20
offsy = 20
' Set the clipping region to the entire window -
' necessary because the hDC provided has a clipping
' region set.
Call SelectClipRgn(usedc, 0)
' We exclude the bitmap area - this reduces flicker (try removing it)