1. Daniel Vivier
  2. PowerBuilder
  3. Monday, 12 April 2021 20:02 PM UTC

Does anyone have code they can share for doing that? I'm thinking about creating the easiest possible way for our users to send us screenshots of windows they are having problems with, and a hotkey built into the window, that saved a screenshot of it to a graphic file, then initiated sending it as an attachment in an email to us (that the user could add text to) seems like it would be helpful. The part I'm not sure about it the screenshot.

Thanks.

Roland Smith Accepted Answer Pending Moderation
  1. Tuesday, 13 April 2021 16:21 PM UTC
  2. PowerBuilder
  3. # 1

My Bitmap program can capture a control, window, or screen to a blob variable and also to the clipboard.

Comment
  1. Mark Goldsmith
  2. Tuesday, 13 April 2021 17:06 PM UTC
For sure, some great options Roland!
  1. Helpful
  1. Daniel Vivier
  2. Tuesday, 13 April 2021 17:39 PM UTC
Thanks, Roland, Chris Pollach mentioned that too. Seems to work great. A complexity for me is we want to integrate that both into our PB windows and our C-language HtmlMessageBox DLL which means I will have to take your code and re-code it in C - which should be easy. (But it's a bit harder to see how to adjust the UI, when using our messagebox replacement, to allow both for screenshots and for answering the displayed buttons.)
  1. Helpful
There are no comments made yet.
Mark Goldsmith Accepted Answer Pending Moderation
  1. Tuesday, 13 April 2021 15:41 PM UTC
  2. PowerBuilder
  3. # 2

Hi Dan,

You could still use Chris' idea but change the printer to Microsoft Print To PDF but there may still be some user interaction required, that you don't want, to choose the file name, save location etc. which, without invoking a number of additional APIs, I don't recall can easily be done.

As also suggested by Chris, Roland's code will allow you to do what you want and probably with a few more options than what I'm going to suggest. However, if you don't need the extra options you can accomplish this with one windows API and then do what you need to do by way of e-mailing the image etc.

This approach simulates keyboard key presses using the Windows keybd_event API. It's pretty simple to use and you can capture the entire screen via the Windows key + PrintScreen key...this will save the file automatically in C:\Users\USERNAME\Pictures\Screenshots. You can also use the Windows + Alt + PrintScreen keys which will save the active window in C:\Users\USERNAME\Videos\Captures. So the code would look something like this:

External Subroutine Declaration
     Subroutine keybd_event(uint bVk,uint bScan,long dwFlags,long dwExtraInfo ) library 'user32.dll'

I've highlighted Subroutine above as this does not return a value so it needs to be declared as a Subroutine versus a Function.

Code for first approach
   Integer li_windows_key = 91, li_print_screen_key = 44

   //Press the keys
   keybd_event(li_windows_key,0,0,0)
   keybd_event(li_print_screen_key,0,0,0)

   //Release the keys
   keybd_event(li_windows_key,0,2,0)
   keybd_event(li_print_screen_key,0,2,0)

Just another approach...HTH.

Regards,

Mark

Comment
  1. Daniel Vivier
  2. Tuesday, 13 April 2021 17:37 PM UTC
Nice idea! One thing though, Windows+Alt+PrtScn saves on my computer at least to \users\username\videos\captures, not \users\username\pictures\screenshots (which is where Windows+PrtScn saves to). I think the problem with this approach, however, is that you don't get the filename, so to use the file, I'd have to go to that folder and look for the newest file in it - which could be error prone. So it's probably better to use Roland's code.
  1. Helpful
  1. Mark Goldsmith
  2. Tuesday, 13 April 2021 18:23 PM UTC
Yes you are correct Dan, which I mentioned above, they do save to different locations...gotta love MS :(

They also use a different approach to the file naming convention where saving in ...\videos\... uses the window name that was captured and ...\pictures\... uses an ever increasing number with its standard filename convention (EG Screenshot (6).png) so it's a little easier to grab (do a DirList into a hidden listbox and grab the last one).

No question I see there may be some challenges to ensure you get the correct file with Windows+Alt+PrtScn.

Best of luck...
  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Monday, 12 April 2021 20:24 PM UTC
  2. PowerBuilder
  3. # 3

Hi Dan;

  Basically, from the Window itself ...

li_rc    =    THIS.Print ( ll_jobno, THIS.x, THIS.y, THIS.Width, THIS.Height )  // - OR -

li_rc    =    THIS.Print ( ll_jobno, THIS.x, THIS.y )

Regards ... Chris

FWIW: You can use a hidden menu item with a short-cut key defined to fire a Window User Event for this. ;-)

Comment
  1. Daniel Vivier
  2. Monday, 12 April 2021 20:29 PM UTC
How does that allow me to save it to a bitmap file Chris? That seems to be for printing to a printer.
  1. Helpful
  1. Chris Pollach @Appeon
  2. Monday, 12 April 2021 20:58 PM UTC
Hi Dan;

Yes, that would be for printing. For the clipboard, try Roland's code ...

http://www.topwizprogramming.com/freecode_bitmap.html

Regards ... Chris
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.