Putting a screenshot from the clipboard onto a GUI

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Putting a screenshot from the clipboard onto a GUI

17 Mar 2018, 19:37

Many thanks for this info burque505, did you come across it just now, or at some point in the past? Thanks.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: Putting a screenshot from the clipboard onto a GUI

17 Mar 2018, 19:58

:D Actually, when I saw your post I Googled "cf_dib cf_bitmap" and it was the second hit.
Regards,
burque505
just me
Posts: 9482
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Putting a screenshot from the clipboard onto a GUI

18 Mar 2018, 04:21

IMO, you don't need GDIP at all to perform this task. If you look at the GDIP code, you see it's solely using GDI functions to create the bitmap.

I'm using a Snapshot() function adopted from Sean's code and some ideas of SKAN. It's working without serious issues for me. You might want to give it a try:

Code: Select all

#NoEnv
; Define the position and size of the screen rectangle to copy and the position of the Gui
SysGet, P, MonitorPrimary
Sysget, M, Monitor, %P%
SnapX := MLeft
SnapY := MTop
SnapW := MRight - SnapX
SnapH := MBottom - SnapY
GuiX := MLeft
GuiY := MTop
Return

F1::
   Gui, New, -Caption +AlwaysOnTop +Owner
   HBM := Snapshot(SnapX, SnapY, SnapW, SnapH)
   Gui, Margin, 0, 0
   Gui, Add, Pic, , HBITMAP:%HBM%
   Gui, Show, x%GuiX% y%GuiY% NA, Snapshot
Return

Esc::
ExitApp

Snapshot(X, Y, W, H) {
   HDC := DllCall("GetDC", "Ptr", 0, "UPtr")
   MDC := DllCall("CreateCompatibleDC", "Ptr", HDC, "UPtr")
   MBM := DllCall("CreateBitmap", "Int", W, "Int", H, "UInt", 1, "UInt", 32, "Ptr", 0, "UPtr")
   MBM := DllCall("CopyImage", "Ptr", MBM, "UInt", 0, "Int", 0, "Int", 0, "UInt", 0x2008, "UPtr")
   OBM := DllCall("SelectObject", "Ptr", MDC, "Ptr", MBM)
   DllCall("BitBlt", "Ptr", MDC, "Int", 0, "Int", 0, "Int", W, "Int", H, "Ptr", HDC, "Int", X, "Int", Y, "UInt", 0x40CC0020)
   DllCall("SelectObject", "Ptr", MDC, "Ptr", OBM)
   DllCall("DeleteDC", "Ptr", MDC)
   DllCall("ReleaseDC", "Ptr", 0, "Ptr", HDC)
   Return MBM
}
User avatar
FanaticGuru
Posts: 1907
Joined: 30 Sep 2013, 22:25

Re: Putting a screenshot from the clipboard onto a GUI

19 Mar 2018, 12:58

just me wrote:I'm using a Snapshot() function adopted from Sean's code and some ideas of SKAN. It's working without serious issues for me.
Thanks for posting this just me.

I have tried quite a few different "snapshot" codes. This is the most compact and straight forward I have seen. I am surprised I have not seen this code somewhere before.

In preliminary testing the Snapshot() function seems to work really well.

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

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot] and 303 guests