Snipper - Window Snipping Tool

Post your working scripts, libraries and tools.
User avatar
JoeSchmoe
Posts: 129
Joined: 08 Dec 2014, 08:58

Re: Snipper - Window Snipping Tool

Post by JoeSchmoe » 09 Apr 2023, 12:50

Looks terrific! I can see a couple of ways this will improve upon my current software.

As many others may do, I'm customizing the hotkeys and menu. Would you consider splitting this script into two files?
  • Lines 135 and after would become a 'library' file. This wouldn't contain any hotkeys or menus, so that when a new version is released, we just replace this file
  • Lines 1-134 would become a 'user' file. The user would put all of their customizations in there.
The library file would be #included in the user file.

Thanks again for posting!

Also, in my workflows, I often just want to copy a snip to the clipboard without leaving a floating window on the screen. Would you consider allowing us to call SnipArea(Area, 'cliponly') and have it only put the image on the clipboard and not creating a floating window?

esperanza despina
Posts: 2
Joined: 03 Apr 2023, 05:13

Re: Snipper - Window Snipping Tool

Post by esperanza despina » 10 Apr 2023, 04:16

guest3456 wrote:
03 Apr 2023, 13:25
what are advantages over Windows built-in snipping tool (WIN + SHIFT + S) ?
Hey it' is similar to screenshot that we take o you mobile phone. In window we can take screenshot with the help of snipping tool

User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Snipper - Window Snipping Tool

Post by FanaticGuru » 10 Apr 2023, 16:35

JoeSchmoe wrote:
09 Apr 2023, 12:50
As many others may do, I'm customizing the hotkeys and menu. Would you consider splitting this script into two files?
  • Lines 135 and after would become a 'library' file. This wouldn't contain any hotkeys or menus, so that when a new version is released, we just replace this file
  • Lines 1-134 would become a 'user' file. The user would put all of their customizations in there.
The library file would be #included in the user file.

Also, in my workflows, I often just want to copy a snip to the clipboard without leaving a floating window on the screen. Would you consider allowing us to call SnipArea(Area, 'cliponly') and have it only put the image on the clipboard and not creating a floating window?

Added a hotkey for clipboard only.

Also, removed all global variables from the functions below ;; CLASSES & FUNCTIONS. Everything below there should be able to be used independently in other scripts if wanted.

The SnipArea function could be useful to have a script programmatically snip areas of the screen without using the mouse.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks

User avatar
JoeSchmoe
Posts: 129
Joined: 08 Dec 2014, 08:58

Re: Snipper - Window Snipping Tool

Post by JoeSchmoe » 10 Apr 2023, 17:10

Many thanks!

User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Snipper - Window Snipping Tool

Post by FanaticGuru » 13 Apr 2023, 01:47

Added a Beta version to the end of the first post.

The Beta adds many features, mostly having to do with the selection process.

Holding down Shift when releasing the mouse button on a drag selection, delays the selection and leaves the selection rectangle to be manipulated. This is Advanced Selection Mode. Shift brings up dimension text in middle of the Advanced Selection that can be used to drag the selection rectangle. The dimension text can be right clicked to bring up a dialog where specific dimensions can be entered, and aspect ratio can be locked. Snipping only at 6x4 or 8.5x11 ratio is very useful for me. While the Advanced Selection window is active pressing Enter confirms and ends the selection process.

Also, ScreenPrint now toggles hide/show for all Snips. You can still create Snips even when they are set not to display. This allows you to Snip the same area over and over that might be changing without Snips blocking the view. Like snipping from a video. The Snips just stackup until display is toggled back on. I will probably add some code to tile or arrange snips.

The beta also shows several techniques using OnMessage and involved with resizing a gui window. Resizing a borderless window is pretty specific but the locking aspect ratio could be useful for normal gui windows especially ones containing pictures. I tried lots of different techniques to control the aspect ratio of a window before I worked out this one that works pretty smoothly.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks

User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Snipper - Window Snipping Tool

Post by boiler » 13 Apr 2023, 04:05

I like the recent changes, especially the fixes to the context menu operation and adding the tray icon. Thanks for those updates.

A suggestion regarding the beta version: Rather than using another key on the keyboard so it can't be used by other applications (which is used by one I use) or its native function is lost, it seems to me that toggling hide/show for all snips isn't needed so often as to require a dedicated hotkey and would be well suited to be either selected from the current context menu or from the tray icon's context menu (or both). Or have an option (persistent between sessions) to turn off the hotkey and just use the context menu or at least change the hotkey. Of course, I would just be able to edit the script to comment out the hotkey or change it, which I would then need to do every time I grab a new update. And if there are snips that are hidden, a change to the tray icon to indicate that would be helpful. Perhaps the handles on the scissors turn red when snips are hidden.

One other feature suggestion: I would find it useful for the active snip to have a different color border so it's clear whether any of the snips are the active window, and if so, which one. That is especially useful so one doesn't accidentally close a snip or close the wrong one with the Esc key, and without having to always click on a snip to make sure it's the active one before pressing the Esc key. Not that you need my advice on how to implement it, but I imagine both color borders could be drawn for each snip when created, and a toggle between which one is visible would be made when one becomes active or inactive.

User avatar
kczx3
Posts: 1640
Joined: 06 Oct 2015, 21:39

Re: Snipper - Window Snipping Tool

Post by kczx3 » 13 Apr 2023, 07:33

That last suggestion is a good one

User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Snipper - Window Snipping Tool

Post by FanaticGuru » 13 Apr 2023, 12:30

@boiler I did at least remap the native function of ScreenPrint to Shift+ScreenPrint but on retrospect, it is a little presumptuous to overwrite a key like ScreenPrint that others might use a lot. I don't use ScreenPrint's native function often, but I do toggle Snips very often so wanted it easy. But Shift+ScreenPrint is probably better as to avoid confusion and Shift does connote that something is shifting or changing.

So, i changed it so that Shift+ScreenPrint will toggle the hide/show and don't mess with the native ScreenPrint. Shift+ScreenPrint appears to be available without a Windows hotkey being overwritten.

@kczx3 now that I have done a lot on the selection process, I am going to work on some features for the Snips. Indicating if a Snip is active would be helpful.

I am not really happy that borders are drawn on the same bitmap as the snip. The borders need to be more independent. I need to work on this.

Thanks for the feedback.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks

User avatar
boiler
Posts: 16902
Joined: 21 Dec 2014, 02:44

Re: Snipper - Window Snipping Tool

Post by boiler » 13 Apr 2023, 18:52

This is one thing that I initially thought was changed with the context menu operation with a recent update, but I'm seeing like that it still acts as before. Apparently, the right-click to bring up the context menu or pressing Esc to dismiss only works when the snip is active. That makes sense especially for Esc, but the issue is that immediately after taking a snip, that snip is not the active window, and it seems that it should be. If I take a snip and immediately right-click on it, no menu appears. That right-click only serves to activate that snip, then I have to right click on it again to get the menu to appear. So if I want to create a snip and then immediately want to bring up the context menu, I have to click on it (left or right) to activate it, then right-lick again. It is much more intuitive (and efficient) to me to be able to create a snip and immediately be able to right-click on it to bring up the context menu.

Along those lines, you should be able to right-click on any snip, active or not, and bring up its context menu. It seems it should be based on what the mouse pointer is over, not which snip is active when you right-click no matter where the mouse is, which is its current state of operation. I would think this would be pretty easily achieved by using the tilde prefix so all right-clicks keep their native function, and the script would in addition to allowing that, check if it's over a clip and bring up its context menu.

gbb
Posts: 3
Joined: 27 Apr 2018, 09:41

Re: Snipper - Window Snipping Tool

Post by gbb » 14 Apr 2023, 16:57

Great script! Using the menu is a huge improvement over having to remember additional hotkeys. I have a few code suggestions below.

Some of the context menu labels didn't make sense to me, so I updated them to better reflect their primary action. I also tweaked the last item to show as "CLOSE: Snipped Image" because I kept thinking of "Snip" as a verb rather than a noun and it was throwing me for a loop.

Code: Select all


;; INITIALIZATION - GUI
;{-----------------------------------------------
;
ContextSnipMenu := Menu()
ContextSnipMenu.Add('SNIP INFO', ContextSnipMenu_Handler)
ContextSnipMenu.Add('')
ContextSnipMenu.Add('')
ContextSnipMenu.Add('COPY:  &Clipboard', ContextSnipMenu_Handler)
ContextSnipMenu.Add('COPY:  Clipboard (with Border)', ContextSnipMenu_Handler)
ContextSnipMenu.Add('')
ContextSnipMenu.Add('COPY:  Acrobat &PDF', ContextSnipMenu_Handler)
ContextSnipMenu.Add('COPY:  Acrobat PDF (with Border)', ContextSnipMenu_Handler)
ContextSnipMenu.Add('SAVE:  Acrobat P&DF', ContextSnipMenu_Handler)
ContextSnipMenu.Add('SAVE:  Acrobat PDF (with Border)', ContextSnipMenu_Handler)
ContextSnipMenu.Add('')
ContextSnipMenu.Add('SAVE:  ' Settings_SavePath_Image_Ext ' &File', ContextSnipMenu_Handler)
ContextSnipMenu.Add('SAVE:  ' Settings_SavePath_Image_Ext ' File (with Border)', ContextSnipMenu_Handler)
ContextSnipMenu.Add('SAVE:  ' Settings_SavePath_Image_Ext ' File && Outlook Email', ContextSnipMenu_Handler)
ContextSnipMenu.Add('')
ContextSnipMenu.Add('')
ContextSnipMenu.Add('CLOSE:  Snipped Image', ContextSnipMenu_Handler)
ContextSnipMenu.SetIcon('1&', A_WinDir '\system32\shell32.dll', 260, 32)
ContextSnipMenu.SetIcon('17&', A_WinDir '\system32\shell32.dll', 220)
;}

I also couldn't figure out why the save PDF option wasn't working. Turns out there is an Acrobat security feature you have to disable. Maybe add this link in as a comment? : https://stackoverflow.com/a/72133153

I also added

Code: Select all

Run(SavePath)
in the end of the Snip2File function and at the end of the If block of Clipboard2Acrobat to open the folder the file was saved within.

I hope these are useful.

User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Snipper - Window Snipping Tool

Post by FanaticGuru » 14 Apr 2023, 18:14

gbb wrote:
14 Apr 2023, 16:57
I also couldn't figure out why the save PDF option wasn't working. Turns out there is an Acrobat security feature you have to disable. Maybe add this link in as a comment? : https://stackoverflow.com/a/72133153

Now that you mention it, I do remember there was an update that broke all my Acrobat scripts. It was quite awhile ago but I did have to do quite a bit of research to resolve it at the time because the update just came out. I will add a note about it.

I appreciate the feedback. I have been tweaking some wording but need to do a little more. Also, some type of option to open the save file location would probably be good. I also often need to open that location after saving but I don't want it to do it every time.

I plan to add a 'Settings' dialog at some point that saves various settings like colors, paths, etc without having to modify the actual script.

Appreciate the feedback.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks

ahk7
Posts: 575
Joined: 06 Nov 2013, 16:35

Re: Snipper - Window Snipping Tool

Post by ahk7 » 15 Apr 2023, 06:37

Just for those who don't have Acrobat but still would like to have a PDF option, img2pdf.exe is a command line utility that can convert an image to a PDF.

Download: https://gitlab.mister-muffin.de/josch/img2pdf/releases
Example: img2pdf img1.png -o out.pdf

You would need to call SavedFile:=Snip2File(Settings_SavePath_Image) to be able to create the PDF of course.
The https://gitlab.mister-muffin.de/josch/img2pdf/ readme describes other options incl. ImageMagick and Tesseract, so if you already have those installed that might be an option to explore. But a single file (img2pdf.exe) seems like a nice enough solution.

User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: Snipper - Window Snipping Tool

Post by flyingDman » 15 Apr 2023, 13:16

I use Word for that:

Code: Select all

fl2pdf := A_ScriptDir "\" A_Year . A_MM . A_DD "_" A_Hour . A_min . A_sec ".pdf"
oWord := ComObject("Word.Application")
doc := oWord.Documents.Add
oword.selection.Paste                        ; assume image is in the clipboard
doc.InlineShapes.Item(1).ScaleWidth := 30
doc.ExportAsFixedFormat(fl2pdf,17)   ; https://learn.microsoft.com/en-us/office/vba/api/word.wdexportformat
doc.close(0)
oword.quit()
oword := ""
run fl2pdf
You might want to set the margins like so (just before pasting):

Code: Select all

doc := oWord.Documents.Add
doc.PageSetup.LeftMargin := 25
doc.PageSetup.RightMargin := 25
doc.PageSetup.TopMargin := 30
doc.PageSetup.BottomMargin := 30
14.3 & 1.3.7

User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Snipper - Window Snipping Tool

Post by FanaticGuru » 15 Apr 2023, 21:51

Updated in First Post

Change Log: 2023 04 15
Moved beta version into main Snipper version.

Lots of changes and improvements. Beta seems to be working well enough to release as the main version.

Most of the new features are accessed by holding Shift when releasing the mouse on selection drag and right clicking on the dimension text.

I especially find the Locking Aspect Ratio to be useful. I bring up the dialog, enter 850 width by 1100 height, then click Lock Aspect Ratio. This then allows for very good ratios for clips to convert to PDFs. 600 x 400 is also very useful. The dialog can also be left open between snips to just hit apply to produce multiple snips of the same size or ratio.

I am still working on the exact ergonomics of everything, but it is improving. I probably need to create a settings dialog and save some settings between sessions. I tried to make the functions where the colors and transparencies could be set from a dialog at some point; the selection background, border colors, etc.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks

ahk7
Posts: 575
Joined: 06 Nov 2013, 16:35

Re: Snipper - Window Snipping Tool

Post by ahk7 » 16 Apr 2023, 03:35

flyingDman wrote:
15 Apr 2023, 13:16
I use Word for that:...
Just a thought, perhaps consider keeping these "specific" functions such as PDF, Outlook which are currently in the main script, as plugins to make it easier for people to "install" the plugin of their choice, I don't use Outlook for example.
Keep up the good work :)

ahk7
Posts: 575
Joined: 06 Nov 2013, 16:35

Re: Snipper - Window Snipping Tool

Post by ahk7 » 16 Apr 2023, 03:51

FanaticGuru wrote:
15 Apr 2023, 21:51
Change Log: 2023 04 15
Moved beta version into main Snipper version.
I notice a difference in the following with the previous version:

1. Create a Snip near the Start menu (bottom left usually)
2. Make it active (so click on it)
3. Now press the winkey/start menu button so if folds out and over the Snip, close the start menu
4. Now the Snip is painted over and has (for me) a solid color (for me black as that is my taskbar/start menu background color)
If I save the Snip, it is also solid color so the original contents is lost. In previous versions this doesn't happen, the Snip remains intact.

The Snip also remains intact if it isn't active.

ahk7
Posts: 575
Joined: 06 Nov 2013, 16:35

Re: Snipper - Window Snipping Tool

Post by ahk7 » 16 Apr 2023, 10:45

Another bug report:

1. Create a Snip
2. Move it partially off screen
3. Click somewhere else on the screen
4. Move the Snip back into full view
5. The part that was off screen is now gone and no longer part of the Snip (solid black for me)

User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Snipper - Window Snipping Tool

Post by FanaticGuru » 16 Apr 2023, 17:01

ahk7 wrote:
16 Apr 2023, 10:45
Another bug report:

1. Create a Snip
2. Move it partially off screen
3. Click somewhere else on the screen
4. Move the Snip back into full view
5. The part that was off screen is now gone and no longer part of the Snip (solid black for me)

I appreciate the bug report.

That is disappointing. I was so pleased when I got the borders changing colors on the activate/deactivate but the method I use to change the border color is fundamentally flawed.

I commented out OnMessage(0x6, WM_ACTIVATE) to disable this feature until I can find a different solution for changing the border color.

I was recreating the bitmap each time from the snip instead of storing it. The speed was ok and it was less memory intensive.

Need to see about getting a bitmap from a layered window that is not fully displayed because something is on top of it or off screen. Or storing a copy of the bitmaps separate from the window.

At least I got the detecting working well which was tricker that it seems because you have to be careful not to get the WM_ACTIVATE function in a recursive loop by doing something in the function that would cause it to be called again. Which is problematic when you are trying to change stuff about windows in the function.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks

iseahound
Posts: 1444
Joined: 13 Aug 2016, 21:04
Contact:

Re: Snipper - Window Snipping Tool

Post by iseahound » 17 Apr 2023, 20:00

FanaticGuru wrote:
16 Apr 2023, 17:01
Need to see about getting a bitmap from a layered window that is not fully displayed because something is on top of it or off screen. Or storing a copy of the bitmaps separate from the window.
Yeah same issue here. The images when I save to file are all cropped with black borders: You need to use something like this:

Code: Select all

  from_window(image) {
      ; Thanks tic - https://www.autohotkey.com/boards/viewtopic.php?t=6517

      ; Get the handle to the window.
      image := WinExist(image)

      ; Restore the window if minimized! Must be visible for capture.
      if DllCall("IsIconic", "ptr", image)
         DllCall("ShowWindow", "ptr", image, "int", 4)

      ; Get the width and height of the client window.
      dpi := DllCall("SetThreadDpiAwarenessContext", "ptr", -3, "ptr")
      DllCall("GetClientRect", "ptr", image, "ptr", Rect := Buffer(16)) ; sizeof(RECT) = 16
         , width  := NumGet(Rect, 8, "int")
         , height := NumGet(Rect, 12, "int")
      DllCall("SetThreadDpiAwarenessContext", "ptr", dpi, "ptr")

      ; struct BITMAPINFOHEADER - https://docs.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-bitmapinfoheader
      hdc := DllCall("CreateCompatibleDC", "ptr", 0, "ptr")
      bi := Buffer(40, 0)                    ; sizeof(bi) = 40
         NumPut(  "uint",        40, bi,  0) ; Size
         NumPut(   "int",     width, bi,  4) ; Width
         NumPut(   "int",   -height, bi,  8) ; Height - Negative so (0, 0) is top-left.
         NumPut("ushort",         1, bi, 12) ; Planes
         NumPut("ushort",        32, bi, 14) ; BitCount / BitsPerPixel
      hbm := DllCall("CreateDIBSection", "ptr", hdc, "ptr", bi, "uint", 0, "ptr*", &pBits:=0, "ptr", 0, "uint", 0, "ptr")
      obm := DllCall("SelectObject", "ptr", hdc, "ptr", hbm, "ptr")

      ; Print the window onto the hBitmap using an undocumented flag. https://stackoverflow.com/a/40042587
      DllCall("user32\PrintWindow", "ptr", image, "ptr", hdc, "uint", 0x3) ; PW_RENDERFULLCONTENT | PW_CLIENTONLY
      ; Additional info on how this is implemented: https://www.reddit.com/r/windows/comments/8ffr56/altprintscreen/

      ; Convert the hBitmap to a Bitmap using a built in function as there is no transparency.
      DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", "ptr", hbm, "ptr", 0, "ptr*", &pBitmap:=0)

      ; Cleanup the hBitmap and device contexts.
      DllCall("SelectObject", "ptr", hdc, "ptr", obm)
      DllCall("DeleteObject", "ptr", hbm)
      DllCall("DeleteDC",     "ptr", hdc)

      return pBitmap
   }
Modified from: https://github.com/iseahound/ImagePut/blob/51f4370209a84f575af2526fe351040845b02a5c/ImagePut.ahk#L1147

You can probably delete:

Code: Select all

      ; Restore the window if minimized! Must be visible for capture.
      if DllCall("IsIconic", "ptr", image)
         DllCall("ShowWindow", "ptr", image, "int", 4)
Oh, and please rename it to SAVE: PNG File from COPY: PNG File

Also, you can allow the user to select a filepath with FileSelect() as in SaveToFile(FileSelect()) I think? Yep use 8: Prompt to Create New File

User avatar
FanaticGuru
Posts: 1906
Joined: 30 Sep 2013, 22:25

Re: Snipper - Window Snipping Tool

Post by FanaticGuru » 17 Apr 2023, 20:09

iseahound wrote:
17 Apr 2023, 20:00
FanaticGuru wrote:
16 Apr 2023, 17:01
Need to see about getting a bitmap from a layered window that is not fully displayed because something is on top of it or off screen. Or storing a copy of the bitmaps separate from the window.
Yeah same issue here. The images when I save to file are all cropped with black borders: You need to use something like this:

Code: Select all

  from_window(image) {
      ; Thanks tic - https://www.autohotkey.com/boards/viewtopic.php?t=6517

      ; Get the handle to the window.
      image := WinExist(image)

      ; Restore the window if minimized! Must be visible for capture.
      if DllCall("IsIconic", "ptr", image)
         DllCall("ShowWindow", "ptr", image, "int", 4)

      ; Get the width and height of the client window.
      dpi := DllCall("SetThreadDpiAwarenessContext", "ptr", -3, "ptr")
      DllCall("GetClientRect", "ptr", image, "ptr", Rect := Buffer(16)) ; sizeof(RECT) = 16
         , width  := NumGet(Rect, 8, "int")
         , height := NumGet(Rect, 12, "int")
      DllCall("SetThreadDpiAwarenessContext", "ptr", dpi, "ptr")

      ; struct BITMAPINFOHEADER - https://docs.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-bitmapinfoheader
      hdc := DllCall("CreateCompatibleDC", "ptr", 0, "ptr")
      bi := Buffer(40, 0)                    ; sizeof(bi) = 40
         NumPut(  "uint",        40, bi,  0) ; Size
         NumPut(   "int",     width, bi,  4) ; Width
         NumPut(   "int",   -height, bi,  8) ; Height - Negative so (0, 0) is top-left.
         NumPut("ushort",         1, bi, 12) ; Planes
         NumPut("ushort",        32, bi, 14) ; BitCount / BitsPerPixel
      hbm := DllCall("CreateDIBSection", "ptr", hdc, "ptr", bi, "uint", 0, "ptr*", &pBits:=0, "ptr", 0, "uint", 0, "ptr")
      obm := DllCall("SelectObject", "ptr", hdc, "ptr", hbm, "ptr")

      ; Print the window onto the hBitmap using an undocumented flag. https://stackoverflow.com/a/40042587
      DllCall("user32\PrintWindow", "ptr", image, "ptr", hdc, "uint", 0x3) ; PW_RENDERFULLCONTENT | PW_CLIENTONLY
      ; Additional info on how this is implemented: https://www.reddit.com/r/windows/comments/8ffr56/altprintscreen/

      ; Convert the hBitmap to a Bitmap using a built in function as there is no transparency.
      DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", "ptr", hbm, "ptr", 0, "ptr*", &pBitmap:=0)

      ; Cleanup the hBitmap and device contexts.
      DllCall("SelectObject", "ptr", hdc, "ptr", obm)
      DllCall("DeleteObject", "ptr", hbm)
      DllCall("DeleteDC",     "ptr", hdc)

      return pBitmap
   }
Modified from: https://github.com/iseahound/ImagePut/blob/51f4370209a84f575af2526fe351040845b02a5c/ImagePut.ahk#L1147

You can probably delete:

Code: Select all

      ; Restore the window if minimized! Must be visible for capture.
      if DllCall("IsIconic", "ptr", image)
         DllCall("ShowWindow", "ptr", image, "int", 4)
Oh, and please rename it to SAVE: PNG File from COPY: PNG File

Also, you can allow the user to select a filepath with FileSelect() as in SaveToFile(FileSelect()) I think?

I tried pulling that function from_window(image) a couple of hours ago and integrating it with my script. No luck, just end up with a solid white rectangle. I have read that any use of PrintWindow requires the application to know how to correctly print the window which apparently Autohotkey does not.

I really appreciate the attempt at help, if you can get it to work I would be very happy.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks

Post Reply

Return to “Scripts and Functions (v2)”