WildByDesign Posted 10 hours ago Posted 10 hours ago This is a continuation of a script from the SampleControls.au3 in Dark Mode and is a combination of the work of @UEZ and @MattyD. Some of the changes that I have made: Modified the parameters of MsgBoxEx() to match the parameters from the built-in AutoIt MsgBox() function Allows users to simply switch MsgBox() to MsgBoxEx() within their scripts DarkMode_DarkTheme is used for buttons on Win11 24H2/25H2 (builds 26100.6899 and higher) DarkMode_Explorer is used for buttons on Win10 and Win11 (builds 26100.6898 and lower) Added DPI scaling which was needed for some measurements Fixed issue with top background color around border of button(s) MsgBoxEx.au3 MsgBoxEx-Example.au3
WildByDesign Posted 10 hours ago Author Posted 10 hours ago @MattyD There is one area that I need help with if you have a moment. I really like the idea of adding the timer countdown to the button (as you have done) when a timer has been set. However, I don't necessarily like the idea of adding a custom text to the button in addition to that countdown. My idea would be to grab the original text for whichever button is to receive the countdown timer. I believe that we could use GetDlgItemText to obtain the original text from the button and append the [x] countdown timer to it. Does this sound like an idea that is technically feasible and, if so, would you please be able to help with this part? Thank you.
MattyD Posted 1 hour ago Posted 1 hour ago Yeah, its pretty straight forward. Func _WinAPI_GetDlgItemText($hDialog, $iDlgItem) Local $aCall = DllCall("user32.dll", "uint", "GetDlgItemTextW", "hwnd", $hDialog, "int", $iDlgItem, "wstr", "", "int", 65536) Return SetError(@error, @extended, @error ? "" : $aCall[3]) EndFunc When using "wstr", I believe autoit creates a buffer size of 65536 characters. This is fine - but its obviously overkill. GetDlgItemText is just a glorified WM_GETTEXT msg, so its also possible to get the required buffer size with WM_GETTEXTLENGTH. Func _WinAPI_GetDlgItemText($hDlg, $iDlgItem) Local $hCtrl, $iBuffLen, $tBuff, $sResult = "" $hCtrl = _WinAPI_GetDlgItem($hDlg, $iDlgItem) If Not @error Then $iBuffLen = _SendMessage($hCtrl, $WM_GETTEXTLENGTH) If Not @error Then $tBuff = DllStructCreate(StringFormat("wchar[%d]", $iBuffLen + 1)) _SendMessage($hCtrl, $WM_GETTEXT, $iBuffLen + 1, DllStructGetPtr($tBuff)) If Not @error Then $sResult = DllStructGetData($tBuff, 1) EndIf Return SetError(@error, @extended, $sResult) EndFunc WildByDesign 1
WildByDesign Posted 36 minutes ago Author Posted 36 minutes ago (edited) 1 hour ago, MattyD said: GetDlgItemText is just a glorified WM_GETTEXT msg, so its also possible to get the required buffer size with WM_GETTEXTLENGTH. This works perfectly. Thank you. I just noticed something that differs from your MsgBoxEx and the built-in MsgBox when using the timer. The built-in MsgBox returns $IDTIMEOUT (-1) if the message box timer runs out. Your MsgBoxEx returns 1. Is it possible to modify your MsgBoxEx to return the same? I understand that it would likely be done within the _TimerProc() function. I just don't know the proper way to accomplish it. EDIT: I think that I may have it. In MsgBoxEx() function, I added the $iTimeout variable instead of 0: (default being 0 anyway) Local Const $iReturn = MsgBox($iFlag, $sTitle, $sText, $iTimeout, $hParentHWND) And in _TimerProc() function I removed the following: If $g_Timeout <= 1 Then _WinAPI_PostMessage($hWnd, $WM_COMMAND, $IDOK + 1, 0) This way I still get your fancy countdown for the timer on the button and get the right return. Edited 19 minutes ago by WildByDesign
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