Double-Clicking on Image Control Saves the Path to Clipboard Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
Loop
Posts: 171
Joined: 07 Jan 2019, 14:51

Double-Clicking on Image Control Saves the Path to Clipboard

17 Apr 2024, 17:57

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!
User avatar
Seven0528
Posts: 375
Joined: 23 Jan 2023, 04:52
Location: South Korea
Contact:

Re: Double-Clicking on Image Control Saves the Path to Clipboard

17 Apr 2024, 18:23

 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
  • English is not my native language. Please forgive any awkward expressions.
  • 영어는 제 모국어가 아닙니다. 어색한 표현이 있어도 양해해 주세요.
Loop
Posts: 171
Joined: 07 Jan 2019, 14:51

Re: Double-Clicking on Image Control Saves the Path to Clipboard

18 Apr 2024, 05:43

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
    }
}
User avatar
Seven0528
Posts: 375
Joined: 23 Jan 2023, 04:52
Location: South Korea
Contact:

Re: Double-Clicking on Image Control Saves the Path to Clipboard  Topic is solved

18 Apr 2024, 12:01

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
    }
}
  • English is not my native language. Please forgive any awkward expressions.
  • 영어는 제 모국어가 아닙니다. 어색한 표현이 있어도 양해해 주세요.
User avatar
Seven0528
Posts: 375
Joined: 23 Jan 2023, 04:52
Location: South Korea
Contact:

Re: Double-Clicking on Image Control Saves the Path to Clipboard

18 Apr 2024, 18:08

 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):""
Last edited by Seven0528 on 18 Apr 2024, 20:29, edited 1 time in total.
  • English is not my native language. Please forgive any awkward expressions.
  • 영어는 제 모국어가 아닙니다. 어색한 표현이 있어도 양해해 주세요.
User avatar
Seven0528
Posts: 375
Joined: 23 Jan 2023, 04:52
Location: South Korea
Contact:

Re: Double-Clicking on Image Control Saves the Path to Clipboard

18 Apr 2024, 20:11

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
  • English is not my native language. Please forgive any awkward expressions.
  • 영어는 제 모국어가 아닙니다. 어색한 표현이 있어도 양해해 주세요.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Descolada, Draken, songdg and 23 guests