how to determine if variable is gui var or hwnd?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
smarq8
Posts: 69
Joined: 16 Jan 2016, 00:33

how to determine if variable is gui var or hwnd?

17 Jun 2018, 03:12

i want to write function where as param i can pass control var or hwnd. So can I somehow determine when I pass hwnd or control var?

Code: Select all

LB_GetCount(Byref control){
	GuiControlGet,hLB,Hwnd,control
	return DllCall("SendMessage", "uint", hLB, "uint", 0x18B) ; LB_GETCOUNT
}
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: how to determine if variable is gui var or hwnd?

17 Jun 2018, 05:49

You could include an indicator with your calls, since at the time of calling, it should be known.

example:

Code: Select all

LB_GetCount(Byref control, indicator := ""){
    if (indicator = "HANDLE")
        hLB := control
    else
        GuiControlGet,hLB,Hwnd,control
	return DllCall("SendMessage", "uint", hLB, "uint", 0x18B) ; LB_GETCOUNT
}


Gui, Add, ListBox, vLB hwndhLB, A|B|C|D
Gui, Add, Button,, Test
Gui, Show
Return

GuiClose:
GuiEscape:
ExitApp

ButtonTest:
    MsgBox, % LB_GetCount(LB)
    MsgBox, % LB_GetCount(hLB, "HANDLE")
Return
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

Re: how to determine if variable is gui var or hwnd?

17 Jun 2018, 07:49

Alternative way without added indicator:

Code: Select all

LB_GetCount(Byref control){
    if control is number
        hLB := control
    else
        GuiControlGet,hLB,Hwnd,control
	return DllCall("SendMessage", "uint", hLB, "uint", 0x18B) ; LB_GETCOUNT
}
imustbeamoron
Posts: 44
Joined: 18 Aug 2016, 22:56

Re: how to determine if variable is gui var or hwnd?

17 Jun 2018, 09:31

returns true if its a hwnd, false if not.

Code: Select all

isHwnd(hwnd){
	return DllCall("IsWindow", "Ptr", hwnd)
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 328 guests