I wanted to share with you this short piece of code where InputBox will always be on top (it's important to have it on top, kind of "MsgBox style") . It's the shortest way I found to make it happen, with few lines of code :
Do $sNb_Quest = InputBox("Quiz", "How many questions to answer ? (1-99)", "10", " M2", _ 220, 140, Default, Default, 0, GUICreate("", 0, 0, 0, 0, Default, @SW_SHOWDEFAULT)) If @error = 1 Then MsgBox(4096, "End of script", "You choosed to Quit") Exit EndIf GUIDelete() ; place this line here, not just after InputBox, or @error will be reset to 0 $iNb_Quest = Number($sNb_Quest) Until $iNb_Quest > 0 And IsInt($iNb_Quest) = 1 MsgBox(4096, "Result", "Your choice : " & $iNb_Quest) In the precedent code, the user can't type more than 2 characters. Inputs like "0" or ".5" or "-1" will be automatically rejected, also the Input is mandatory, default is 10. The last parameter, GUICreate, is the key to have this InputBox always on top (in a quick way)
My question is : should GUIDelete() be present in the code or can we delete that line ?
It seems to work fine without the GUIDelete() line, but in case the loop repeats several times (because of bad inputs), then we will have several GUICreate() without a single GUIDelete() ?
Thanks for... your input
I'm wondering if, once again, I might be able to get some assistance from those of you who are much more knowledgeable than I. I have written a function that uses an InputBox and asks for the name of the adapter the user wants to manipulate. The script is designed to assign the name of the adapter to the entire program (a global variable) for use in other functions throughout its use. It can also be called again to change the adapter or, if it mistakenly didn't get set, set it. The issue I'm having is that I can't figure out a way to keep the function from "clearing" or "deleting" the variable if the cancel button is pressed. The idea is that if the user assigns the variable at the start of the program running (the function is called before anything else happens in the script) then, mistakenly/accidentally, runs the function again and, at the InputBox, the user clicks "Cancel" it will leave the variable alone. Currently, I've been able to (after much trial, tribulation, and troubleshooting) get it actually cancel the operation when "Cancel" is pressed or assign the variable as needed/preferred when the information is entered and "OK" is pressed. However, if "Cancel" is pressed (again, after the variable has already been assigned), it completely clears the variable's assignment (as evidenced by calling the variable in another function. Below is the code for the function. Please let me know if more functions are needed for diagnosis.
$adapterName = InputBox("Select Adapter", "Please input the adapter name" & @CRLF & @CRLF & "or leave it at the default:", "Ethernet")
If @error = 1 Then
it's quite often, that someone asks how to change the texts of the MsgBox buttons or the InputBox buttons or how to change the position of ta MsgBox. Since years I use CBT hooks for that, but now I made a small UDF out of it for the ease of use. Of course you can build your own GUI or use already existing UDFs to do the same, but I like this way and you can hack (hook) the inbuild InputBox.
#include-once #include <WinAPI.au3> Global Const $tagCBT_CREATEWND = "ptr lpcs;HWND tagCBT_CREATEWND" Global Const $tagCREATESTRUCT = "ptr lpCreateParams;handle hInstance;HWND hMenu;HWND hwndParent;int cy;int cx;int y;int x;LONG style;ptr lpszName;ptr lpszClass;DWORD dwExStyle" Global $g__hProcDlgBox = DllCallbackRegister("__DlgBox_CbtHookProc", "int", "int;int;int") Global $g__TIdDlgBox = _WinAPI_GetCurrentThreadId() Global $g__hHookDlgBox = _WinAPI_SetWindowsHookEx($WH_CBT, DllCallbackGetPtr($g__hProcDlgBox), 0, $g__TIdDlgBox) Global Const $g__MaxDlgBtns = 5 ; maximum of 5 buttons to rename text Global Const $g__MaxDlgItemId = 11 ; maximun ID of buttons to search is 11 as this is the maximun used in Messagebox Global $g__DlgBoxPosX, $g__DlgBoxPosY, $g__DlgBoxWidth, $g__DlgBoxHeight Global $g__aDlgBoxBtnText[$g__MaxDlgBtns] Global $g__DlgBtnCount = 0 _DlgBox_SetDefaults() OnAutoItExitRegister("__DlgBox_UnregisterHook") Func _DlgBox_SetButtonNames($TxtBtn1 = Default, $TxtBtn2 = Default, $TxtBtn3 = Default, $TxtBtn4 = Default, $TxtBtn5 = Default) $g__aDlgBoxBtnText = $TxtBtn1 $g__aDlgBoxBtnText = $TxtBtn2 $g__aDlgBoxBtnText = $TxtBtn3 $g__aDlgBoxBtnText = $TxtBtn4 $g__aDlgBoxBtnText = $TxtBtn5 $g__DlgBtnCount = @NumParams EndFunc ;==>_DlgBox_SetButtonNames Func _DlgBox_SetPosition($x = Default, $y = Default) ;only for MsgBox, not working and not needed for InputBox $g__DlgBoxPosX = $x $g__DlgBoxPosY = $y EndFunc ;==>_DlgBox_SetPosition Func _DlgBox_SetSize($w = Default, $h = Default) $g__DlgBoxWidth = $w $g__DlgBoxHeight = $h EndFunc ;==>_DlgBox_SetSize Func _DlgBox_SetDefaults() $g__DlgBoxPosX = Default $g__DlgBoxPosY = Default $g__DlgBoxWidth = Default $g__DlgBoxHeight = Default For $i = 0 To UBound($g__aDlgBoxBtnText) - 1 $g__aDlgBoxBtnText[$i] = Default Next EndFunc ;==>_DlgBox_SetDefaults Func __DlgBox_CbtHookProc($nCode, $wParam, $lParam) Local $tcw, $tcs Local $iSearch = 0 Local $ahBtn[$g__DlgBtnCount] If $nCode < 0 Then Return _WinAPI_CallNextHookEx($g__hHookDlgBox, $nCode, $wParam, $lParam) EndIf Switch $nCode Case 3 ;5=HCBT_CREATEWND If _WinAPI_GetClassName(HWnd($wParam)) = "#32770" Then ;Dialoig window class $tcw = DllStructCreate($tagCBT_CREATEWND, $lParam) $tcs = DllStructCreate($tagCREATESTRUCT, DllStructGetData($tcw, "lpcs")) If $g__DlgBoxPosX <> Default Then DllStructSetData($tcs, "x", $g__DlgBoxPosX) If $g__DlgBoxPosY <> Default Then DllStructSetData($tcs, "y", $g__DlgBoxPosY) If $g__DlgBoxWidth <> Default Then DllStructSetData($tcs, "cx", $g__DlgBoxWidth) If $g__DlgBoxHeight <> Default Then DllStructSetData($tcs, "cy", $g__DlgBoxHeight) EndIf Case 5 ;5=HCBT_ACTIVATE For $i = 1 To $g__MaxDlgItemId If IsHWnd(_WinAPI_GetDlgItem($wParam, $i)) Then If $g__aDlgBoxBtnText[$iSearch] <> Default Then _WinAPI_SetDlgItemText($wParam, $i, $g__aDlgBoxBtnText[$iSearch]) $iSearch += 1 If $iSearch >= UBound($ahBtn) Then ExitLoop EndIf Next EndSwitch Return _WinAPI_CallNextHookEx($g__hHookDlgBox, $nCode, $wParam, $lParam) EndFunc ;==>__DlgBox_CbtHookProc Func __DlgBox_UnregisterHook() _WinAPI_UnhookWindowsHookEx($g__hHookDlgBox) DllCallbackFree($g__hProcDlgBox) EndFunc ;==>__DlgBox_UnregisterHook Func _WinAPI_SetDlgItemText($hDlg, $nIDDlgItem, $lpString) Local $aRet = DllCall('user32.dll', "int", "SetDlgItemText", _ "hwnd", $hDlg, _ "int", $nIDDlgItem, _ "str", $lpString) Return $aRet EndFunc ;==>_WinAPI_SetDlgItemText
Simple example to see how to use it
#include "HookDlgBox.au3" _DlgBox_SetButtonNames("1", "two", "3") MsgBox(4, "Test 1", "Custom button texts") _DlgBox_SetPosition(20, 20) MsgBox(66, "Test 2", "Custom position and button texts") _DlgBox_SetButtonNames("Submit", "Don't submit", "Don't know") InputBox("Test 3", "Where were you born?", "Planet Earth") _DlgBox_SetSize(800, 800) InputBox("Test 4", "Where were you born?", "Planet Earth") _DlgBox_SetSize(Default, 800) MsgBox(66, "Test 5", "Strange but working") _DlgBox_SetButtonNames(Default, "Wait", "What?") _DlgBox_SetSize(Default, Default) _DlgBox_SetPosition(500, 500) MsgBox(66, "Test 6", "So far so good!") _DlgBox_SetDefaults() MsgBox(6, "Test 7", "Default position and button texts") Hope you like it.
I know you can set flags, e.g. 1, 2, 3 to change the buttons in a MsgBox from "OK" + "Cancel" to "Yes" + "No" + "Cancel", etc...
1- Is it possible to manually say what the buttons say? E.g. "Pass" + "Fail"?
2- Is it possible to do that with an InputBox rather than a MsgBox?
3- What in your opinion would be better design for the user? A ) Pressing "Fail" on a MsgBox creates a "InputBox" with only a textbox and "Submit" button? B ) Only being able to press "Fail" on an InputBox if the textbox is not empty?
Thank you in advance.
Hey anyone knows how i can have a inputbox that is connected to an HotKeySet? Like if u put in like "a" in the inputbox it sets the hotkey to "a"?