Putting a screenshot from the clipboard onto a GUI
Re: Putting a screenshot from the clipboard onto a GUI
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
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Re: Putting a screenshot from the clipboard onto a GUI
Actually, when I saw your post I Googled "cf_dib cf_bitmap" and it was the second hit.
Regards,
burque505
Regards,
burque505
Re: Putting a screenshot from the clipboard onto a GUI
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:
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
}
- FanaticGuru
- Posts: 1907
- Joined: 30 Sep 2013, 22:25
Re: Putting a screenshot from the clipboard onto a GUI
Thanks for posting this just me.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.
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
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
Who is online
Users browsing this forum: Bing [Bot] and 303 guests