News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Screenshotter

Started by jj2007, June 07, 2020, 03:07:58 PM

Previous topic - Next topic

jj2007

Inspired by Hutch's keybd_event discovery:

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

hutch--

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.

jj2007

Even better: MB_TOPMOST style for the MessageBox - see new attachment above :thumbsup:

hutch--

It works but has an unusual logic.