It is currently Sun May 31, 2020 1:44 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Question about #WM_PRINT Message
PostPosted: Fri Aug 30, 2019 4:55 pm 
Offline
Enthusiast
Enthusiast

Joined: Fri Apr 25, 2003 11:08 pm
Posts: 453
I use the following code to capture an image of a window for printing:
Code:
  ; 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?


Top
 Profile  
Reply with quote  
 Post subject: Re: Question about #WM_PRINT Message
PostPosted: Fri Aug 30, 2019 7:45 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat May 05, 2007 5:31 pm
Posts: 732
Location: Linz, Austria
ebs wrote:
Does anyone have a suggestion as to how to fix this?
BitBlt_(...)
Code:
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


Last edited by chi on Sat Aug 31, 2019 2:15 am, edited 2 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Question about #WM_PRINT Message
PostPosted: Sat Aug 31, 2019 2:12 am 
Offline
Enthusiast
Enthusiast

Joined: Fri Apr 25, 2003 11:08 pm
Posts: 453
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!


Top
 Profile  
Reply with quote  
 Post subject: Re: Question about #WM_PRINT Message
PostPosted: Sat Aug 31, 2019 2:21 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat May 05, 2007 5:31 pm
Posts: 732
Location: Linz, Austria
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)


Top
 Profile  
Reply with quote  
 Post subject: Re: Question about #WM_PRINT Message
PostPosted: Sat Aug 31, 2019 3:50 pm 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Apr 12, 2009 6:27 am
Posts: 3604
You can use PrintWindow
Run first
Code:
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:
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

_________________
Egypt my love


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 23 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye