Page 1 of 1
Set MsgBox Button Text? a133
Posted: 30 Apr 2021, 17:09
by Larkal
Can someone tell me what I'm doing wrong and how to get a message box with customized button text?
Code: Select all
OnMessage(0x44, OnMsgBox)
msgboxResult := MsgBox("Hello, world!", "This is AutoHotkey", 0x4243)
OnMsgBox(wParam, lParam, msg, hwnd) {
wintitle := "ahk_id " hwnd
ControlSetText "This", "Button1", wintitle
ControlSetText "is", "Button2", wintitle
ControlSetText "a", "Button3", wintitle
ControlSetText "test", "Button4", wintitle
}
I'm getting
Error: Target window not found.
I think I'm misunderstanding what the hwnd id is for.
Re: Set MsgBox Button Text? a133
Posted: 30 Apr 2021, 20:47
by kczx3
What if you just use the hwnd and don’t prepend ahk_id?
Re: Set MsgBox Button Text? a133
Posted: 30 Apr 2021, 22:51
by Larkal
If I try just using hwnd it complains
Error: Target control not found.
Re: Set MsgBox Button Text? a133 Topic is solved
Posted: 01 May 2021, 02:47
by lexikos
That's because there are no buttons on the window identified by
hwnd, which is probably the
script's main window, not the MsgBox. You need to be more selective with your OnMessage. You also might need to find the MsgBox by using WinExist (with
DetectHiddenWindows true).
The error is different if you use ahk_id because then it is restricted by DetectHiddenWindows, and the window is hidden.
(But if used correctly, OnMessage is probably better than the timer used in the example, as it can act earlier.)
Re: Set MsgBox Button Text? a133
Posted: 04 May 2021, 04:30
by Larkal
Thanks
@lexikos, that was exactly right.
I was able to get it working using DetectHiddenWindows true and WinExist.
Here's what I finally got working
Code: Select all
OnMessage(0x44, OnMsgBox)
gMsgBoxTitle := "Hello Autohotkey"
MsgBox("Hello, world!", gMsgBoxTitle, 0x4243)
OnMsgBox(wParam, lParam, msg, hwnd) {
global gMsgBoxTitle
DetectHiddenWindows true
msgBoxHwnd := WinExist(gMsgBoxTitle)
if (msgBoxHwnd) {
ControlSetText "First", "Button1", msgBoxHwnd
ControlSetText "Second", "Button2", msgBoxHwnd
ControlSetText "Third", "Button3", msgBoxHwnd
ControlSetText "Fourth", "Button4", msgBoxHwnd
}
DetectHiddenWindows false
}