代码:
Private Const WM_PAINT = &HF
Private Const WM_PRINT = &H317
Private Const PRF_CLIENT = &H4&
Private Const PRF_CHILDREN = &H10&
Private Const PRF_OWNED = &H20&
Private Const PHYSICALOFFSETX As Long = 112
Private Const PHYSICALOFFSETY As Long = 113
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd _
As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nindex _
As Long) As LongPrivate Sub Command1_Click()
Dim rv As Long
rv = SendMessage(Frame1.hwnd, WM_PAINT, Picture1.hdc, 0)
rv = SendMessage(Frame1.hwnd, WM_PRINT, Picture1.hdc, PRF_CHILDREN + PRF_CLIENT + PRF_OWNED)
Printer.Print " "
Printer.PaintPicture Picture2.Image, 100, -50
Printer.EndDoc
End Sub
Private Const WM_PAINT = &HF
Private Const WM_PRINT = &H317
Private Const PRF_CLIENT = &H4&
Private Const PRF_CHILDREN = &H10&
Private Const PRF_OWNED = &H20&
Private Const PHYSICALOFFSETX As Long = 112
Private Const PHYSICALOFFSETY As Long = 113
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd _
As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nindex _
As Long) As LongPrivate Sub Command1_Click()
Dim rv As Long
rv = SendMessage(Frame1.hwnd, WM_PAINT, Picture1.hdc, 0)
rv = SendMessage(Frame1.hwnd, WM_PRINT, Picture1.hdc, PRF_CHILDREN + PRF_CLIENT + PRF_OWNED)
Printer.Print " "
Printer.PaintPicture Picture2.Image, 100, -50
Printer.EndDoc
End Sub
但是把第二句改成这个就没有边框
rv = SendMessage(Frame1.hwnd, WM_PRINT, Picture1.hdc, PRF_CHILDREN + PRF_NONCLIENT + PRF_OWNED)
rv = SendMessage(Frame1.hwnd, WM_PRINT, Picture1.hdc, PRF_CHILDREN + PRF_NONCLIENT + PRF_OWNED)
是没有边框,但是frame中的text、frame控件全部都没有加载到picture1容器中,只加载label控件。等同于我把第二句注释掉
打印是空白
Private Const twipFactor = 1440
Private Const WM_PAINT = &HF
Private Const WM_PRINT = &H317
Private Const PRF_CLIENT = &H4& ' Draw the window's client area.
Private Const PRF_CHILDREN = &H10& ' Draw all visible child windows.
Private Const PRF_OWNED = &H20& ' Draw all owned windows.Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As LongPrivate Sub Form_Load()
Dim sWide As Single, sTall As Single
Dim rv As Long Me.ScaleMode = vbTwips ' default
sWide = 8.5
stall = 11 ' or 14, etc.
Me.Width = twipFactor * sWide
Me.Height = twipFactor * stall
With Picture1
.Top = 0
.Left = 0
.Width = twipFactor * sWide
.Height = twipFactor * stall
End With
With Picture2
.Top = 0
.Left = 0
.Width = twipFactor * sWide
.Height = twipFactor * stall
End With
With Label1
.Caption = "Top"
.Left = Me.Width / 2
.Top = 0
End With
With Label2
.Caption = "Bottom"
.Top = (twipFactor * stall) - .Height * 2
.Left = Me.Width / 2
End With
Me.Visible = True
DoEvents Picture1.SetFocus
Picture2.AutoRedraw = True
rv = SendMessage(Picture1.hwnd, WM_PAINT, Picture2.hDC, 0)
rv = SendMessage(Picture1.hwnd, WM_PRINT, Picture2.hDC, _
PRF_CHILDREN + PRF_CLIENT + PRF_OWNED)
Picture2.Picture = Picture2.Image
Picture2.AutoRedraw = False Printer.Print ""
Printer.PaintPicture Picture2.Picture, 0, 0
Printer.EndDoc
End Sub