代碼:
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 Long
Private 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
uj5u.com熱心網友回復:
為啥不用setparent?uj5u.com熱心網友回復:
看不懂但是把第二句改成這個就沒有邊框
rv = SendMessage(Frame1.hwnd, WM_PRINT, Picture1.hdc, PRF_CHILDREN + PRF_NONCLIENT + PRF_OWNED)
uj5u.com熱心網友回復:
不行啊,第二句改成rv = SendMessage(Frame1.hwnd, WM_PRINT, Picture1.hdc, PRF_CHILDREN + PRF_NONCLIENT + PRF_OWNED)
是沒有邊框,但是frame中的text、frame控制元件全部都沒有加載到picture1容器中,只加載label控制元件。等同于我把第二句注釋掉
uj5u.com熱心網友回復:
setparent是可以加載到picture1容器中,但是似乎是直接拷貝到picture1中,用Printer.PaintPicture Picture2.Image, 100, -50列印是空白
uj5u.com熱心網友回復:
在frame里面再放一個 picture控制元件,把所有控制元件都放picture上uj5u.com熱心網友回復:
事先就用兩個 PictureBox,其中一種作表單控制元件的容器,另一個作列印媒介(空)。注意:兩個不要互相嵌套,將第二個隱藏的第一個后面。SendMessage 發送的是 PictureBox1。下面是有兩個 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 Long
Private 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
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/123917.html
標籤:API
