Page 1 of 1
Double-Clicking on Image Control Saves the Path to Clipboard
Posted: 17 Apr 2024, 17:57
by Loop
Hello everyone,
I've noticed that double-clicking on the image saves the image path to the clipboard. Could someone please explain why this happens?
Code: Select all
#Requires Autohotkey v2.0
#SingleInstance Force
bid := "2277"
SG := Gui("+Resize", "Yr")
SG.BackColor := "White"
SG.Add("Picture", "w150 h150 xm", "ICO\" bid ".jpg").OnEvent("DoubleClick", OpenPic)
SG.OnEvent("Close", SG_Close)
SG.OnEvent("Escape", SG_Close)
SG.Show("w600 h600")
OpenPic(CtrlObj, Info){
SG.Opt("+OwnDialogs")
MsgBox A_Clipboard
Run(A_ScriptDir "\" CtrlObj.Text)
}
SG_Close(*){
ExitApp()
}
Thank you very much!
Re: Double-Clicking on Image Control Saves the Path to Clipboard
Posted: 17 Apr 2024, 18:23
by Seven0528
Try read this.
It corresponds to v1, but with just a little effort, you should be able to translate it into v2. Check
return 0 part.
https://www.autohotkey.com/board/topic/94962-doubleclick-on-gui-pictures-puts-their-path-in-your-clipboard/?p=682595
Re: Double-Clicking on Image Control Saves the Path to Clipboard
Posted: 18 Apr 2024, 05:43
by Loop
Thank you very much.
Have I implemented this correctly?
it seems to work, but I am unsure
Code: Select all
OnLButtonDblClk(wParam, lParam, msg, hwnd) {
Class := WinGetClass("ahk_id " hwnd)
If (Class = "Static") {
If SG.Name
Return 0
SG.Opt("+LastFound")
Id := DllCall("GetDlgCtrlID", "ptr", hwnd)
static STN_DBLCLK := 1
PostMessage(0x111, Id | (STN_DBLCLK << 16), hwnd)
Return 0
}
}
Re: Double-Clicking on Image Control Saves the Path to Clipboard Topic is solved
Posted: 18 Apr 2024, 12:01
by Seven0528
Code: Select all
#Requires AutoHotkey v2.0
#SingleInstance Force
if (!fileExist(iconFileName := A_Temp "/autohotkey_favicon.ico"))
download("http://autohotkey.com/favicon.ico", iconFileName)
A_Clipboard := "Hello, World!"
onMessage(0x0203, WM_LBUTTONDBLCLK)
myGui := gui()
myGuiIcon := myGui.add("Picture",, iconFileName).onEvent("DoubleClick", myGuiIcon_DoubleClick)
myGui.show()
myGuiIcon_DoubleClick(ctrlObj, info) {
tooltip(" The icon has been double-clicked.`nThe text currently stored in the clipboard is as follows.`n`n" A_Clipboard)
setTimer tooltip, -1000
}
;-----------------------
WM_LBUTTONDBLCLK(wParam, lParam, Msg, hWnd) {
static GA_ROOT := 2, WM_COMMAND := 0x0111, STN_DBLCLK := 1
switch (winGetClass("ahk_id " hwnd))
{
case "Static":
hRootWnd := dllCall("User32.dll\GetAncestor", "Ptr",hWnd, "UInt",GA_ROOT, "Ptr")
id := dllCall("User32.dll\GetDlgCtrlID", "Ptr",hWnd, "Int")
postMessage(WM_COMMAND, (id & 0xffff) | ((STN_DBLCLK & 0xffff) << 16), hWnd,, "ahk_id " hRootWnd)
return 0
}
}
Re: Double-Clicking on Image Control Saves the Path to Clipboard
Posted: 18 Apr 2024, 14:15
by Loop
Thank you very much!
Re: Double-Clicking on Image Control Saves the Path to Clipboard
Posted: 18 Apr 2024, 18:08
by Seven0528
The code that's slightly maniacal (?) is as follows.
Code: Select all
WM_LBUTTONDBLCLK(wParam, lParam, Msg, hWnd) {
static GA_ROOT := 2, WM_COMMAND := 0x0111, STN_DBLCLK := 1
switch (lpClassName:=buffer(256,0), dllCall("User32.dll\GetClassNameW", "Ptr",hWnd, "Ptr",lpClassName.Ptr, "Int",lpClassName.Size, "Int"), strGet(lpClassName,"UTF-16")), false
{
case "Static":
return (dllCall("User32.dll\PostMessageW"
,"Ptr",dllCall("User32.dll\GetAncestor", "Ptr",hWnd, "UInt",GA_ROOT, "Ptr")
,"UInt",WM_COMMAND
,"UPtr",(dllCall("User32.dll\GetDlgCtrlID", "Ptr",hWnd, "Int") & 0xffff) | ((STN_DBLCLK & 0xffff) << 16)
,"Int",hWnd, "Int")
,false)
}
}
Code: Select all
WM_LBUTTONDBLCLK(wParam, lParam, Msg, hWnd) {
static WM_COMMAND := 0x0111, STN_DBLCLK := 1
switch (winGetClass("ahk_id " hwnd)), false
{
case "Static": return (postMessage(WM_COMMAND, (dllCall("User32.dll\GetDlgCtrlID", "Ptr",hWnd, "Int") & 0xffff) | ((STN_DBLCLK & 0xffff) << 16), hWnd), false)
}
}
Code: Select all
WM_LBUTTONDBLCLK(_*)=>winGetClass("ahk_id" _[4])="Static"?(postMessage(273,dllCall("GetDlgCtrlID","Ptr",_[4])|1<<16,_[4]),0):""
Re: Double-Clicking on Image Control Saves the Path to Clipboard
Posted: 18 Apr 2024, 20:11
by Seven0528
Code: Select all
onMessage 515,(_*)=>winGetClass("ahk_id" _[4])="Static"?(postMessage(273,dllCall("GetDlgCtrlID","Ptr",_[4])|1<<16,_[4]),0):""
Maybe, it can't be written any shorter than this based on character count. (Even though readability is completely sacrificed.)
Is there a point in cutting down the character count this much? Nope! Just did it for fun.
Spoiler
Code: Select all
#Requires AutoHotkey v2.0
#SingleInstance Force
if (!fileExist(iconFileName := A_Temp "/autohotkey_favicon.ico"))
download("http://autohotkey.com/favicon.ico", iconFileName)
A_Clipboard := "Hello, World!"
onMessage 515,(_*)=>winGetClass("ahk_id" _[4])="Static"?(postMessage(273,dllCall("GetDlgCtrlID","Ptr",_[4])|1<<16,_[4]),0):""
myGui := gui()
myGuiIcon := myGui.add("Picture",, iconFileName).onEvent("DoubleClick", myGuiIcon_DoubleClick)
myGui.show()
myGuiIcon_DoubleClick(ctrlObj, info) {
tooltip(" The icon has been double-clicked.`nThe text currently stored in the clipboard is as follows.`n`n" A_Clipboard)
setTimer tooltip, -1000
}