CYCho Posted December 1, 2019 Share Posted December 1, 2019 (edited) Suppose I have the following MsgBox: #include <MsgBoxConstants.au3> MsgBox($MB_OKCANCEL, "MUI Question", "Click 'OK' to continue, 'Cancel' to quit") The captions of the buttons will dynamically change depending on the default language of the Windows. How can I get hold of these captions and replace 'OK' and 'Cancel' with them in the text of the above MsgBox? Edited December 2, 2019 by CYCho zPlayer - A Small Audio and Video Player Time Sync + SystemTimeAdjustment Link to comment Share on other sites More sharing options...
Nine Posted December 1, 2019 Share Posted December 1, 2019 Just create your own GUI message box. I believe there are some already written UDFs that you could use (at least as a basis). “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Musashi Posted December 1, 2019 Share Posted December 1, 2019 50 minutes ago, CYCho said: How can I get hold of these captions and replace 'OK' and 'Cancel' with them in the text of the above MsgBox? Have a look at @funkey 's solution : english-msgbox-button-texts-for-everyone Code : expandcollapse popup#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!! "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
CYCho Posted December 1, 2019 Author Share Posted December 1, 2019 @Nine and @Musashi, Thank you for your responses. It seems that it is not easy to make my text to change dynamically according as the captions change. English-only maybe a viable alternative. zPlayer - A Small Audio and Video Player Time Sync + SystemTimeAdjustment Link to comment Share on other sites More sharing options...
alienclone Posted December 2, 2019 Share Posted December 2, 2019 you could check the OS language and use Switch...Case...EndSwitch to display your text accordingly. this by itself would require you to use a translator before hand and manually write every language case into your code, or you could try to make the code translate on the fly by using the Google Translate API but that would require a LOT of effort. If @error Then MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!") EndIf "Yeah yeah yeah patience, how long will that take?" -Ed Gruberman REAL search results | SciTE4AutoIt3 Editor Full Version Link to comment Share on other sites More sharing options...
CYCho Posted December 2, 2019 Author Share Posted December 2, 2019 (edited) @alienclone, Thanks for your comment. I was wondering if there was a way to intercept the internal process of MsgBox function and get the translated captions of the buttons. As I cannot predefine OS languages, Switch...EndSwitch would not be an option. PS: I understand that Windows provides Multilanguage User Interface function, but using it would be too large a task for my small application, and I don't know how. Edited December 2, 2019 by CYCho zPlayer - A Small Audio and Video Player Time Sync + SystemTimeAdjustment Link to comment Share on other sites More sharing options...
alienclone Posted December 2, 2019 Share Posted December 2, 2019 (edited) came up with a messy but easy way... have the beginning of your script create a stand alone msgbox so that your running script does not pause, then get the text displayed on the buttons stored in variables, then close the test msgbox. Run(@AutoItExe & ' /AutoIt3ExecuteLine "MsgBox(4097, ''test msgbox title'', ''test msgbox text'')"') WinWait("test msgbox title") $okButtonText = ControlGetText("test msgbox title","test msgbox text",1) $cancelButtonText = ControlGetText("test msgbox title","test msgbox text",2) WinClose("test msgbox title") then later on in msgbox replace 'ok' and 'cancel' with your variables and they should be in whatever language the OS made the buttons MsgBox($MB_OKCANCEL, "MUI Question", "Click '"& $okButtonText &"' to continue, '"& $cancelButtonText &"' to quit") you could also just run it all back to back so that the test msgbox flashes for just a second and then is immediately replaced with the final msgbox. Edited December 2, 2019 by alienclone If @error Then MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!") EndIf "Yeah yeah yeah patience, how long will that take?" -Ed Gruberman REAL search results | SciTE4AutoIt3 Editor Full Version Link to comment Share on other sites More sharing options...
CYCho Posted December 2, 2019 Author Share Posted December 2, 2019 @alienclone Nice job! You have come up with a very clever solution. One drawback is that this code, even when compiled, will not run in a PC where there is no AutoIt installed. If we have to make another exe and fileinstall it, it would be too much cumbersome. zPlayer - A Small Audio and Video Player Time Sync + SystemTimeAdjustment Link to comment Share on other sites More sharing options...
CYCho Posted December 2, 2019 Author Share Posted December 2, 2019 (edited) With the help of some friends in the Korean AutoIt community, I found a solution. #include <MsgBoxConstants.au3> #include <WinAPIRes.au3> $hInstance = _WinAPI_LoadLibrary("USER32.DLL") $text = "Click '" & _WinAPI_LoadString($hInstance, 800) & "' to continue, '" & _WinAPI_LoadString($hInstance, 801) & "' to quit" _WinAPI_FreeLibrary($hInstance) MsgBox($MB_OKCANCEL, "MUI Question", $text) #cs String ID's in User32.dll OK 800 Cancel 801 Abort 802 Retry 803 Ignore 804 Yes 805 No 806 Close 807 Help 808 TryAgain 809 #ce Edited December 2, 2019 by CYCho pixelsearch, alienclone and Musashi 3 zPlayer - A Small Audio and Video Player Time Sync + SystemTimeAdjustment Link to comment Share on other sites More sharing options...
alienclone Posted December 2, 2019 Share Posted December 2, 2019 nice, so the OS will just automatically show the desired string based on ID in its default language? that is cool. If @error Then MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!") EndIf "Yeah yeah yeah patience, how long will that take?" -Ed Gruberman REAL search results | SciTE4AutoIt3 Editor Full Version Link to comment Share on other sites More sharing options...
CYCho Posted December 2, 2019 Author Share Posted December 2, 2019 Yes, User32.dll and Shell32.dll contain many Windows system messages in default language. zPlayer - A Small Audio and Video Player Time Sync + SystemTimeAdjustment Link to comment Share on other sites More sharing options...
pixelsearch Posted December 2, 2019 Share Posted December 2, 2019 (edited) Hi CYCho, Great find in your preceding post ! Here is another way... never ask the user to press on this or that That one should show "Ok", "Cancel" with an english OS... and in case user press Enter too quickly / mistakenly, "Cancel" got the focus... Edited December 2, 2019 by pixelsearch Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now