Sunday, June 17, 2012

Bagaimana Cara Mem-Print RichTextBox Yang Memiliki Image

Option Explicit

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 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 Sub Command1_Click()
RichTextBox1.OLEObjects.Add , , "c:\windows\triangles.bmp"
End Sub

Private Sub Command2_Click()
Dim rv As Long
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
Command1.SetFocus
End Sub

Private Sub Command3_Click()
Printer.PaintPicture Picture2.Picture, 0, 0
Printer.EndDoc
End Sub