Jump to content

English MsgBox button texts for everyone


funkey
 Share

Recommended Posts

I don't know if there is some need, but I made a simple function to use only english button names in MsgBox.

#include <WinAPI.au3>
Opt("MustDeclareVars", 1)
Global $hHookMsgBox
_MsgBoxEnglish(0, "Title", "Text")
_MsgBoxEnglish(1, "Title", "Text")
_MsgBoxEnglish(2, "Title", "Text")
_MsgBoxEnglish(3, "Title", "Text")
_MsgBoxEnglish(4, "Title", "Text")
_MsgBoxEnglish(5, "Title", "Text")
_MsgBoxEnglish(6, "Title", "Text")
_MsgBoxEnglish(7, "Title", "Text")
#region English Button text for MsgBox!!
;##########################################################
Func _MsgBoxEnglish($flag, $title, $text, $timeout = 0, $hwnd = 0)
 Local $hProcMsgBox = DllCallbackRegister("CbtHookProcMsgBox", "int", "int;int;int")
 Local $TIDMsgBox = _WinAPI_GetCurrentThreadId()
 $hHookMsgBox = _WinAPI_SetWindowsHookEx($WH_CBT, DllCallbackGetPtr($hProcMsgBox), 0, $TIDMsgBox)
 Local $iRet = MsgBox($flag, $title, $text, $timeout, $hwnd)
 _WinAPI_UnhookWindowsHookEx($hHookMsgBox)
 DllCallbackFree($hProcMsgBox)
 Return $iRet
EndFunc   ;==>_MsgBoxEnglish
Func CbtHookProcMsgBox($nCode, $wParam, $lParam, $hHookMsgBox)
 Local $RET = 0, $hBitmap = 0, $xWnd = 0
 Local $sButtonText
 If $nCode < 0 Then
  $RET = _WinAPI_CallNextHookEx($hHookMsgBox, $nCode, $wParam, $lParam)
  Return $RET
 EndIf
 Switch $nCode
  Case 5 ;5=HCBT_ACTIVATE
   _WinAPI_SetDlgItemText($wParam, 1, "OK")
   _WinAPI_SetDlgItemText($wParam, 2, "Cancel")
   _WinAPI_SetDlgItemText($wParam, 3, "&Abort")
   _WinAPI_SetDlgItemText($wParam, 4, "&Retry")
   _WinAPI_SetDlgItemText($wParam, 5, "&Ignore")
   _WinAPI_SetDlgItemText($wParam, 6, "&Yes")
   _WinAPI_SetDlgItemText($wParam, 7, "&No")
   _WinAPI_SetDlgItemText($wParam, 8, "Help")
   _WinAPI_SetDlgItemText($wParam, 10, "&Try Again")
   _WinAPI_SetDlgItemText($wParam, 11, "&Continue")
 EndSwitch
 Return
EndFunc   ;==>CbtHookProcMsgBox
Func _WinAPI_SetDlgItemText($hDlg, $nIDDlgItem, $lpString)
 Local $aRet = DllCall('user32.dll', "int", "SetDlgItemText", _
   "hwnd", $hDlg, _
   "int", $nIDDlgItem, _
   "str", $lpString)
 Return $aRet[0]
EndFunc   ;==>_WinAPI_SetDlgItemText
;##########################################################
#endregion English Button text for MsgBox!!

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

Really nice, thanks for this example ;)!

Edit: The same approach works fine to replace the button texts of an InputBox with a custom language.

#include <WinAPI.au3>
Opt("MustDeclareVars", 1)
Global $hHookInputBox

InputBox("Test", "Eingabe")
_InputBox("Test", "Eingabe")

Func _InputBox($title, $prompt, $default = Default, $passwordchar = Default, $width = Default, $height = Default, $left = Default, $top = Default, $timeout = Default, $hwnd = Default)
    Local $hProcInputBox = DllCallbackRegister("CbtHookProcInputBox", "int", "int;int;int")
    Local $TIDInputBox = _WinAPI_GetCurrentThreadId()
    $hHookInputBox = _WinAPI_SetWindowsHookEx($WH_CBT, DllCallbackGetPtr($hProcInputBox), 0, $TIDInputBox)
    Local $iRet = InputBox($title, $prompt, $default, $passwordchar, $width, $height, $left, $top, $timeout, $hwnd)
    Local $ierror = @error
    _WinAPI_UnhookWindowsHookEx($hHookInputBox)
    DllCallbackFree($hProcInputBox)
    Return SetError($ierror, "", $iRet)
EndFunc   ;==>_InputBox

Func CbtHookProcInputBox($nCode, $wParam, $lParam, $hHookInputBox)
    Local $RET = 0, $hBitmap = 0, $xWnd = 0
    Local $sButtonText
    If $nCode < 0 Then
        $RET = _WinAPI_CallNextHookEx($hHookInputBox, $nCode, $wParam, $lParam)
        Return $RET
    EndIf
    Switch $nCode
        Case 5 ;5=HCBT_ACTIVATE
            _WinAPI_SetDlgItemText($wParam, 1, "OK")
            _WinAPI_SetDlgItemText($wParam, 2, "Abbrechen")
    EndSwitch
    Return
EndFunc   ;==>CbtHookProcInputBox

Func _WinAPI_SetDlgItemText($hDlg, $nIDDlgItem, $lpString)
    Local $aRet = DllCall('user32.dll', "int", "SetDlgItemText", _
            "hwnd", $hDlg, _
            "int", $nIDDlgItem, _
            "str", $lpString)
    Return $aRet[0]
EndFunc   ;==>_WinAPI_SetDlgItemText
Edited by KaFu
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...