The MASM Forum

Members Gallery => Showcase => Topic started by: jj2007 on June 07, 2020, 03:07:58 PM

Title: Screenshotter
Post by: jj2007 on June 07, 2020, 03:07:58 PM
Inspired by Hutch's keybd_event discovery (http://masm32.com/board/index.php?topic=8588.0):

GuiParas equ "Copy & save a window", w900, h500, b GreenBlue ; centered, width+height, background
include \masm32\MasmBasic\Res\MbGui.asm
  invoke ShowWindow, hGui, SW_HIDE
  MsgBox 0, "Activate the window you want to copy & save, then come back here", "Screenshotter:", MB_OKCANCEL or MB_TOPMOST
  If_ eax==IDCANCEL Then invoke SendMessage, hGui, WM_CLOSE, 0, 0
  invoke Sleep, 100
  invoke keybd_event, VK_SNAPSHOT, 1, KEYEVENTF_EXTENDEDKEY, 0
  invoke ShowWindow, hGui, SW_SHOW
Event Paint
  GuiImageCallback SaveIt ; define a callback function
  GuiImage clipboard, fit ; display the current screenshot
  ShEx "window.jpg" ; open the default viewer, then quit
  invoke SendMessage, hGui, WM_CLOSE, 0, 0
EndOfEvents
SaveIt: SaveImageToFile "window.jpg"
  ret
GuiEnd
Title: Re: Screenshotter
Post by: hutch-- on June 07, 2020, 03:34:24 PM
Looks good, if you want to cheeky about it, try the SetCapture technique on a mouse down message which you drag to the window you want to activate and when you release the mouse button, it captures the image of the window.
Title: Re: Screenshotter
Post by: jj2007 on June 07, 2020, 08:31:42 PM
Even better: MB_TOPMOST style for the MessageBox - see new attachment above :thumbsup:
Title: Re: Screenshotter
Post by: hutch-- on June 07, 2020, 09:17:54 PM
It works but has an unusual logic.