VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "CMDIPicture"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Private Declare Function SetWindowPos Lib "user32" ( _
 ByVal hWnd As Long, _
 ByVal hWndInsertAfter As Long, _
 ByVal x As Long, ByVal y As Long, _
 ByVal cx As Long, ByVal cy As Long, _
 ByVal wFlags As Long) As Long

Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOZORDER = &H4
Private Const SWP_FRAMECHANGED = &H20

Private WithEvents MDI As MDIForm
Attribute MDI.VB_VarHelpID = -1
Private pic As PictureBox
Private img As StdPicture

Private Sub Redraw()
    Dim nWidth As Long, nHeight As Long
    Dim x As Long, y As Long
    Const SWPFlags As Long = SWP_FRAMECHANGED Or SWP_NOMOVE Or _
     SWP_NOZORDER Or SWP_NOSIZE
     
    If Not MDI Is Nothing Then
        If Not pic Is Nothing Then
            With pic
                nWidth = pic.ScaleX(img.Width, vbHimetric, vbTwips)
                nHeight = pic.ScaleY(img.Height, vbHimetric, vbTwips)
                x = (MDI.ScaleWidth - nWidth) \ 2
                y = (MDI.ScaleHeight - nHeight) \ 2
                .Cls
                .PaintPicture img, x, y
                MDI.Picture = .Image
                Call SetWindowPos(MDI.hWnd, 0, 0, 0, 0, 0, SWPFlags)
            End With
        End If
    End If
End Sub

Public Sub Init(frmMDI As MDIForm, picImage As StdPicture)
    'MDI.Visible = True
    Set pic = frmMDI.Controls.Add("VB.PictureBox", "picMDI")
    pic.AutoRedraw = True
    pic.BorderStyle = vbBSNone
    pic.BackColor = frmMDI.BackColor
    Set img = picImage
    pic.Move 0, 0, frmMDI.ScaleWidth, frmMDI.ScaleHeight
    Set MDI = frmMDI
    Redraw
End Sub

Private Sub MDI_Resize()
    If Not pic Is Nothing Then
        If MDI.WindowState <> vbMinimized Then
            pic.Move 0, 0, MDI.ScaleWidth, MDI.ScaleHeight
            Redraw
        End If
    End If
End Sub
