Author Topic: Screenshotter  (Read 150 times)

jj2007

  • Member
  • *****
  • Posts: 10437
  • Assembler is fun ;-)
    • MasmBasic
Screenshotter
« on: June 07, 2020, 03:07:58 PM »
Inspired by Hutch's keybd_event discovery:

Code: [Select]
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
« Last Edit: June 07, 2020, 08:32:16 PM by jj2007 »

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 7416
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Screenshotter
« Reply #1 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.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

jj2007

  • Member
  • *****
  • Posts: 10437
  • Assembler is fun ;-)
    • MasmBasic
Re: Screenshotter
« Reply #2 on: June 07, 2020, 08:31:42 PM »
Even better: MB_TOPMOST style for the MessageBox - see new attachment above :thumbsup:

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 7416
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Screenshotter
« Reply #3 on: June 07, 2020, 09:17:54 PM »
It works but has an unusual logic.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy: