Page 1 of 1
Question about #WM_PRINT Message
Posted: Fri Aug 30, 2019 4:55 pm
by ebs
I use the following code to capture an image of a window for printing:
Code: Select all
; print window to image
hdc.L = StartDrawing(ImageOutput(PrintImage))
If hdc
SendMessage_(WindowID(Window), #WM_PRINT, hdc, #PRF_CLIENT|#PRF_NONCLIENT|#PRF_CHILDREN|#PRF_ERASEBKGND|#PRF_OWNED)
EndIf
StopDrawing()
I then send the image to the printer using PrinterLib.
This works fine for
almost all windows, but there's a problem with EditorGadgets, which don't show up in the image.
Does anyone have a suggestion as to how to fix this?
Re: Question about #WM_PRINT Message
Posted: Fri Aug 30, 2019 7:45 pm
by chi
ebs wrote:Does anyone have a suggestion as to how to fix this?
BitBlt_(...)
Code: Select all
CompilerIf #PB_Compiler_Debugger = 0
MessageRequester("", "Enable the Debugger...")
End
CompilerEndIf
OpenWindow(0, 0, 0, 320, 200, "", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_ScreenCentered)
SetWindowColor(0, #Gray)
ButtonGadget(0, 10, 10, 100, 30, "capture")
EditorGadget(1, 10, 50, 300, 140, #PB_Editor_WordWrap)
SetGadgetText(1, "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")
OpenWindow(1, 0, 0, 100, 100, "", #PB_Window_SystemMenu|#PB_Window_ScreenCentered, WindowID(0))
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_Gadget
Select EventGadget()
Case 0
CreateImage(0, 320, 200)
wdc = GetDC_(WindowID(0))
idc = StartDrawing(ImageOutput(0))
BitBlt_(idc, 0, 0, 320, 200, wdc, 0, 0, #SRCCOPY)
StopDrawing()
ReleaseDC_(WindowID(0), wdc)
ShowLibraryViewer("Image", 0)
EndSelect
EndSelect
Until event = #PB_Event_CloseWindow
[/size]
Re: Question about #WM_PRINT Message
Posted: Sat Aug 31, 2019 2:12 am
by ebs
You're right. I changed the #WM_PAINT message to a BitBlt_ call and the image now includes the EditorGadgets.
I think there's a chance that the image might contain portions of any overlapping windows, but in my case there aren't any. Thanks!
Re: Question about #WM_PRINT Message
Posted: Sat Aug 31, 2019 2:21 am
by chi
ebs wrote:I think there's a chance that the image might contain portions of any overlapping windows, but in my case there aren't any.
No overlapping windows with BitBlt
(check out the code above)
Re: Question about #WM_PRINT Message
Posted: Sat Aug 31, 2019 3:50 pm
by RASHAD
You can use PrintWindow
Run first
Code: Select all
OpenWindow(0, 0, 0, 400, 200, "Test", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget| #PB_Window_ScreenCentered)
SetWindowColor(0, #Gray)
ButtonGadget(0, 10, 10, 100, 30, "capture")
EditorGadget(1, 10, 50, 300, 140, #PB_Editor_WordWrap)
SetGadgetText(1, "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")
ImageGadget(2,10,210,400,400,0)
Repeat
event = WaitWindowEvent()
Until event = #PB_Event_CloseWindow
Then run
Code: Select all
Prototype.i ptPrintWindow(hWnd, hdc, flags)
OpenLibrary(0, "User32.dll")
PrintWindow.ptPrintWindow = GetFunction(0, "PrintWindow")
Repeat
hwnd = FindWindow_(0,"Test")
Until hwnd
OpenWindow(0, 0, 0, 510, 310, "", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget| #PB_Window_ScreenCentered)
SetWindowColor(0, #Gray)
ButtonGadget(0, 10, 10, 100, 30, "capture")
ImageGadget(2,10,50,410,210,0)
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_Gadget
Select EventGadget()
Case 0
CreateImage(0, 406, 230)
hdc = StartDrawing(ImageOutput(0))
PrintWindow(hwnd, hdc,0)
StopDrawing()
SetGadgetState(2,ImageID(0))
EndSelect
EndSelect
Until event = #PB_Event_CloseWindow