Results 1 to 2 of 2

Thread: Printing MDI form

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2000
    Posts
    12

    Question


    How can I print the contents of a MDI form ?
    I have 3 child forms inside this MDI form, each containing
    a graphical display. I can print each of these individual
    forms by using the Form.Printform method.
    But I am trying to find a way of printing all the 3 graphs
    exactly as they appear on the MDI form.

    Thanks.

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    You can use the BitBlt API to copy the Image of the MDI Form's Client Area to a Hidden Picturebox on the MDIForm, then Print it, i.e.
    Code:
    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 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 Const SRCCOPY = &HCC0020 ' (DWORD) dest = source
    
    Private Sub Command1_Click()
        Dim W As Long, H As Long, lDC As Long
        
        'Make the Picturebox as big as the MDIForm's Client Area
        MDIForm1.Picture1.Move 0, 0, MDIForm1.ScaleWidth, MDIForm1.ScaleHeight
        
        'Make sure the Image we draw is persistent
        MDIForm1.Picture1.AutoRedraw = True
        
        'Get the MDI Client Area Dimensions in Pixels
        W = MDIForm1.ScaleWidth / Screen.TwipsPerPixelX
        H = MDIForm1.ScaleHeight / Screen.TwipsPerPixelY
        
        'Get a Device Context for the MDI Client Area
        lDC = GetDC(MDIForm1.hwnd)
        
        'Copy an Image of the MDI Client Area and Everything in it to the Picturebox
        BitBlt MDIForm1.Picture1.hdc, 0, 0, W, H, lDC, 0, 0, SRCCOPY
        
        'Release the Device Context
        Call ReleaseDC(MDIForm1.hwnd, lDC)
        
        'Make the Image Persistent
        MDIForm1.Picture1 = MDIForm1.Picture1.Image
        
        'Print the Image
        Printer.PaintPicture MDIForm1.Picture1, 0, 0
        Printer.EndDoc
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width