Option Explicit
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 CreateCompatibleDC Lib "gdi32" (ByVal lDC As Long) As Long Private Declare Function DeleteDC Lib "gdi32" (ByVal lDC As Long) As Long Private Declare Function SelectObject Lib "gdi32" (ByVal lDC As Long, ByVal hObject As Long) As Long
Const TILE_IMAGE = 1
Dim pic As StdPicture, hMemDC As Long, pHeight As Long, pWidth As Long
Public Sub InitMDIBackground() On Error Resume Next MDIForm1.Picture1.Visible = False MDIForm1.Picture1.AutoRedraw = True MDIForm1.Picture1.AutoSize = True
pHeight = MDIForm1.Picture1.Height pWidth = MDIForm1.Picture1.Width
Set pic = MDIForm1.Picture1.Picture Set MDIForm1.Picture1.Picture = Nothing MDIForm1.Picture1.AutoSize = False
hMemDC = CreateCompatibleDC(MDIForm1.Picture1.hDC) SelectObject hMemDC, pic.Handle End Sub
Public Sub DrawBackground() On Error GoTo errHandler If MDIForm1.WindowState <> vbMinimized Then Dim X As Long, Y As Long
If TILE_IMAGE = 1 Then
MDIForm1.Picture1.Move 0, 0, MDIForm1.ScaleWidth, MDIForm1.ScaleHeight For X = 0 To MDIForm1.ScaleWidth Step pWidth For Y = 0 To MDIForm1.ScaleHeight Step pHeight BitBlt MDIForm1.Picture1.hDC, X \ Screen.TwipsPerPixelX, Y \ Screen.TwipsPerPixelX, pWidth \ Screen.TwipsPerPixelX, pHeight \ Screen.TwipsPerPixelY, hMemDC, 0, 0, vbSrcCopy Next Next Else
X = (MDIForm1.ScaleWidth - pWidth) \ 2: X = X \ Screen.TwipsPerPixelX Y = (MDIForm1.ScaleHeight - pHeight) \ 2: Y = Y \ Screen.TwipsPerPixelY
MDIForm1.Picture1.Height = MDIForm1.Height MDIForm1.Picture1.Width = MDIForm1.Width
BitBlt MDIForm1.Picture1.hDC, X, Y, pWidth \ Screen.TwipsPerPixelX, pHeight \ Screen.TwipsPerPixelY, hMemDC, 0, 0, vbSrcCopy
End If
Set MDIForm1.Picture = MDIForm1.Picture1.Image End If
Set pic = Nothing DeleteDC hMemDC errHandler: End Sub
Private Sub MDIForm_Load() Picture1.Visible = True InitMDIBackground End Sub
Private Sub MDIForm_Resize() DrawBackground End Sub |