工具:VB 
    操作系统: PWIN95 
    VB 5.0下开发的应用程序,如何实现整个窗体的打印(包括标题、菜单、边框)? 回答:     VB的Form对象有一个PrintForm方法可以做到整个窗体的打印。但只能打印看得见的部分,看不见的部分无法打印。 
     
    高手的意见: 
    取得窗口的hdc,直接映射到元文件中,然后就能全窗口打印了。(以上是在问专家里看到的,请问:取得窗口的hdc,直接映射到元文件中,然后就能全窗口打印了。  具体如何实现?

解决方案 »

  1.   

    '一个Form,加一个PictureBox,一个Command,粘贴如下代码Option ExplicitPrivate 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 Declare Function GetWindowRect Lib "user32" _
       (ByVal hwnd As Long, _
        lpRect As RECT) As LongPrivate Const SRCCOPY = &HCC0020Private Type RECT
            Left As Long
            Top As Long
            Right As Long
            Bottom As Long
    End TypePrivate Sub Command1_Click()
        Dim lngDesktopDC As Long
        Dim rc As RECT
        
        Picture1.Visible = False
        Picture1.AutoRedraw = True
        Picture1.BorderStyle = 0
        Picture1.Width = Me.Width
        Picture1.Height = Me.Height
        
        DoEvents
        
        lngDesktopDC = GetDC(0)
        Call GetWindowRect(Me.hwnd, rc)
        Call BitBlt(Picture1.hdc, 0, 0, rc.Right - rc.Left, rc.Bottom - rc.Top, lngDesktopDC, rc.Left, rc.Top, SRCCOPY)
        Call ReleaseDC(0, lngDesktopDC)
        
        Printer.PaintPicture Picture1.Image, 0, 0
        Printer.EndDoc
    End Sub