Syntax Problem

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
WantToKnow
Posts: 61
Joined: 28 Mar 2020, 08:46

Syntax Problem

Post by WantToKnow » 09 Dec 2021, 07:16

Hello,

this works fine:

Code: Select all

GuiControlGet, HWND_Number1, HWND, Button1
MsgBox % HWND_Number1,
but how can I do this:

Code: Select all

Get_HWND_Of_Control(Button1)

Get_HWND_Of_Control(vControl){
GuiControlGet, HWND_Number1 , HWND, %vControl%
MsgBox % HWND_Number1
}

Thanks for your advice.

User avatar
mikeyww
Posts: 26600
Joined: 09 Sep 2014, 18:38

Re: Syntax Problem

Post by mikeyww » 09 Dec 2021, 07:27

Code: Select all

Get_HWND_Of_Control("Button1")

WantToKnow
Posts: 61
Joined: 28 Mar 2020, 08:46

Re: Syntax Problem

Post by WantToKnow » 09 Dec 2021, 07:59

Hello Mike,
that is exactly what I have done before. I thought I was making a syntax error, but your code looks exactly like mine.
Unfortunately the code does not show me the wanted HWND number this way.

WantToKnow
Posts: 61
Joined: 28 Mar 2020, 08:46

Re: Syntax Problem

Post by WantToKnow » 09 Dec 2021, 08:01

WantToKnow wrote:
09 Dec 2021, 07:59
Hello Mike,
that is exactly what I have done before. I thought I was making a syntax error, but your code looks exactly like mine.
Unfortunately the code does not show me the wanted HWND number this way. Even if the post here says otherwise.
I have tried all the possibilities before.

User avatar
mikeyww
Posts: 26600
Joined: 09 Sep 2014, 18:38

Re: Syntax Problem

Post by mikeyww » 09 Dec 2021, 08:05

Code: Select all

Gui, Add, Button,, This test really works.
Gui, Show, x200 y200
SetTimer, Tip, 200
Get_HWND_Of_Control("Button1")
Tip:
MouseGetPos,,,, fc
GuiControlGet, hWnd, HWND, %fc%
ToolTip, % hWnd ? fc " = " hWnd : ""
Return

Get_HWND_Of_Control(vControl){
 GuiControlGet, HWND_Number1, HWND, %vControl%
 MsgBox, 64, HWND for %vControl%, %HWND_Number1%
}

teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: Syntax Problem

Post by teadrinker » 09 Dec 2021, 08:11

@mikeyww

Code: Select all

Gui, New
Gui, Add, Button,, This test really works.
Gui, Show, x200 y200
GuiControlGet, HWND_Number1, HWND, Button1
MsgBox, % HWND_Number1
Return

F11:: Get_HWND_Of_Control("Button1")

Get_HWND_Of_Control(vControl){
 GuiControlGet, HWND_Number1, HWND, %vControl%
 MsgBox % HWND_Number1
}

User avatar
mikeyww
Posts: 26600
Joined: 09 Sep 2014, 18:38

Re: Syntax Problem

Post by mikeyww » 09 Dec 2021, 08:14

Thanks.

Code: Select all

Gui, New, +Hwndgui1
Gui, Add, Button,, This test really works.
Gui, Show, x200 y200
SetTimer, Tip, 200
Get_HWND_Of_Control(gui1, "Button1")
Tip:
Gui, %gui1%:Default
MouseGetPos,,,, fc
GuiControlGet, hWnd, HWND, %fc%
ToolTip, % hWnd ? fc " = " hWnd : ""
Return

Get_HWND_Of_Control(guiHWND, vControl){
 Gui, %guiHWND%:Default
 GuiControlGet, HWND_Number1, HWND, %vControl%
 MsgBox, 64, HWND for %vControl%, %HWND_Number1%
}

teadrinker
Posts: 4309
Joined: 29 Mar 2015, 09:41
Contact:

Re: Syntax Problem

Post by teadrinker » 09 Dec 2021, 08:19

A more plain way is to pass hwnd to the function.

User avatar
mikeyww
Posts: 26600
Joined: 09 Sep 2014, 18:38

Re: Syntax Problem

Post by mikeyww » 09 Dec 2021, 08:23

Achieved (edited...)! :)

WantToKnow
Posts: 61
Joined: 28 Mar 2020, 08:46

Re: Syntax Problem

Post by WantToKnow » 09 Dec 2021, 08:58

Hello Mike,
thank you for your endless efforts.
Your code was of course correct!

But the error was somewhere else.
Previously I inserted this program line:
Gui, MainGui : new

Suddenly there were the strangest results with the determination
the HWN number.

User avatar
mikeyww
Posts: 26600
Joined: 09 Sep 2014, 18:38

Re: Syntax Problem

Post by mikeyww » 09 Dec 2021, 08:59

Teadrinker solved the puzzle. "New" creates a few challenges, one of which is often requiring the need to specify the GUI number subsequently.

Gui, New
Although the new window is set as the default for the current thread, non-GUI threads still default to GUI number 1. If the GUI has no name and is not the default GUI, it must be identified by its HWND.
If you have a GUI name as you do, then you can use that instead of the GUI HWND.

Code: Select all

Gui, MainGui:New
Gui, Add, Button,, This test really works.
Gui, Show, x200 y200
SetTimer, Tip, 200
Get_HWND_Of_Control("MainGui", "Button1")
Tip:
Gui, MainGui:Default
MouseGetPos,,,, fc
GuiControlGet, hWnd, HWND, %fc%
ToolTip, % hWnd ? fc " = " hWnd : ""
Return

Get_HWND_Of_Control(gui, vControl){
 Gui, %gui%:Default
 GuiControlGet, HWND_Number1, HWND, %vControl%
 MsgBox, 64, HWND for %vControl%, %HWND_Number1%
}

Post Reply

Return to “Ask for Help (v1)”