Control parameter can't be a variable if empty? Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
SAbboushi
Posts: 252
Joined: 08 Dec 2014, 22:13

Control parameter can't be a variable if empty?

11 Jan 2024, 17:54

Although documentation does indeed say "Omitted" (vs. "empty"), is there a way to use a variable for the Control parameter when its value is empty? When Control = "", an error is thrown:
Error: Target control not found.
Borrowing from https://www.autohotkey.com/docs/v2/lib/SendMessage.htm#ExPID as example:

Code: Select all

SetTitleMatchMode 2
DetectHiddenWindows true

MsgNumber      := 0x0044  ; WM_COMMNOTIFY
wParam         := 0x405
lParam         := 0
Control        := ""
WinTitle       := "SomeOtherScript.ahk - AutoHotkey v"
WinText        := ""
ExcludeTitle   := ""
ExcludeText    := ""
Timeout        := 0

RetValue := SendMessage(
    MsgNumber,
    wParam,
    lParam,
    Control,
    ;,  ; uncomment this line and comment line above and script doesn't throw an error
    WinTitle,
    WinText,
    ExcludeTitle,
    ExcludeText,
    Timeout,
)
(Edited to add ";" before "uncomment" i.e. "; uncomment..."
User avatar
mikeyww
Posts: 26972
Joined: 09 Sep 2014, 18:38

Re: Control parameter can't be a variable if empty?  Topic is solved

11 Jan 2024, 18:06

I did not try it, but perhaps this helps.

https://www.autohotkey.com/docs/v2/Variables.htm#maybe
Permits the variable to be unset. This is valid only when passing a variable to an optional parameter, array element or object literal; or on the right-hand side of a direct assignment.
SAbboushi
Posts: 252
Joined: 08 Dec 2014, 22:13

Re: Control parameter can't be a variable if empty?

11 Jan 2024, 20:25

Thanks - problem resolved by making two changes (marked below):

Code: Select all

SetTitleMatchMode 2
DetectHiddenWindows true

MsgNumber      := 0x0044  ; WM_COMMNOTIFY
wParam         := 0x405
lParam         := 0
Control        := unset	; CHANGE #1
WinTitle       := "SomeOtherScript.ahk - AutoHotkey v"
WinText        := ""
ExcludeTitle   := ""
ExcludeText    := ""
Timeout        := 0

RetValue := SendMessage(
    MsgNumber,
    wParam,
    lParam,
    Control?,	; CHANGE #2
    WinTitle,
    WinText,
    ExcludeTitle,
    ExcludeText,
    Timeout,
)
(Edited to fix display problem in Codebox)

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: No registered users and 71 guests