什么直接打印PictureBox里面的内容?

解决方案 »

  1.   

    Private Const SRCCOPY = &HCC0020
    Private Declare Function Escape Lib "gdi32" (ByVal hdc As Long, _
         ByVal nEscape As Long, ByVal nCount As Long, lpInData As Any, _
         lpOutData As Any) As Long
    Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
    Private Declare Function StretchBlt Lib "gdi32" (ByVal hdc 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 nSrcWidth As Long, _
         ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
    Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, _
         ByVal hObject As Long) As Long
    Private Declare Function CreateCompatibleDC Lib "gdi32" _
         (ByVal hdc As Long) As LongPrivate Sub cmdPrintPicture_Click()
    Dim hMemoryDC As Long
    Dim hOldBitMap As Long
    Dim x As Long
    Const NEWFRAME = 1    Picture1.Picture = Picture1.Image
        '* StretchBlt requires pixel coordinates.
        
        Picture1.ScaleMode = vbPixels
        Printer.ScaleMode = vbPixels
        Printer.Print ""; ' init printer object
        
        hMemoryDC = CreateCompatibleDC(Picture1.hdc)
        hOldBitMap = SelectObject(hMemoryDC, Picture1.Picture)
        x = StretchBlt(Printer.hdc, 0, 0, Printer.ScaleWidth, Printer.ScaleHeight, _
             hMemoryDC, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, SRCCOPY)
        hOldBitMap = SelectObject(hMemoryDC, hOldBitMap)
        x = DeleteDC(hMemoryDC)
        x = Escape(Printer.hdc, NEWFRAME, 0, 0&, 0&)
        
        Printer.EndDocEnd Sub