Page 1 of 1

Windows MessageBox_() with custom buttons text

Posted: Thu Aug 13, 2015 3:39 am
by Keya
This is for the Windows MessageBox_() API, not MessageRequester.

Instead of "Yes", "No" etc default MessageBox buttons we can set a simple windows hook and change their text

Code: Select all

Global hHook.l

Procedure.l HookProc(lMsg.l, wParam.l, lParam.l)
  If lMsg = #HCBT_ACTIVATE
    SetWindowText_ (GetDlgItem_(wParam, #IDYES), "Male")
    SetWindowText_ (GetDlgItem_(wParam, #IDNO),  "Female")
    UnhookWindowsHookEx_ (hHook)
  EndIf
EndProcedure

;Have to call this is we havent already created a window
InitCommonControls_()    

hHook = SetWindowsHookEx_(#WH_CBT, @HookProc(), GetModuleHandle_(0), GetCurrentThreadId_())
MsgReply.l = MessageBox_(#HWND_DESKTOP, "What is your gender?", "Custom Msgbox", #MB_YESNO + #MB_ICONINFORMATION) 

Select MsgReply
  Case #IDYES
    MessageRequester("Result", "You clicked Male")
  Case #IDNO
    MessageRequester("Result", "You clicked Female")
EndSelect

Another example using ABORTRETRYIGNORE for 3 buttons (you can also use YESNOCANCEL but caveat of that is the "X" Close button is enabled and clicking that is the same as clicking Cancel)

Code: Select all

Global hHook.l

Procedure.l HookProc(lMsg.l, wParam.l, lParam.l)
  If lMsg = #HCBT_ACTIVATE
    SetWindowText_ (GetDlgItem_(wParam, #IDABORT),  "Male")
    SetWindowText_ (GetDlgItem_(wParam, #IDRETRY),  "Female")
    SetWindowText_ (GetDlgItem_(wParam, #IDIGNORE), "Other")
    UnhookWindowsHookEx_ (hHook)
  EndIf
EndProcedure

;Have to call this is we havent already created a window
InitCommonControls_()    

hHook = SetWindowsHookEx_(#WH_CBT, @HookProc(), GetModuleHandle_(0), GetCurrentThreadId_())
MsgReply.l = MessageBox_(#HWND_DESKTOP, "What is your gender?", "Custom Msgbox", #MB_ABORTRETRYIGNORE + #MB_ICONINFORMATION) 

Select MsgReply
  Case #IDABORT
    MessageRequester("Result", "You clicked Male")
  Case #IDRETRY
    MessageRequester("Result", "You clicked Female")
  Case #IDIGNORE
    MessageRequester("Result", "You clicked Other")
EndSelect

Re: Windows MessageBox_() with custom buttons text

Posted: Thu Aug 13, 2015 10:30 am
by Kwai chang caine
Very interesting
Thanks for sharing 8)

Re: Windows MessageBox_() with custom buttons text

Posted: Thu Jan 04, 2018 1:17 pm
by Dude
Thanks for your code, Keya! :) I needed the #MB_YESNO version today.