Jump to content

Recommended Posts

Hello,

 

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...

However...

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.

Edited by IAMK
Link to post
Share on other sites

@benners I have tried using ChrisL's ControlSetText on both MsgBox and InputBox, but I must not understand it properly.
E.g. ControlSetText("AutoIT_TestChecker", "", "Button2", "FAIL")

My understanding is that ControlSetText overrides the text in the buttons (in this case the button called "Button2") with the text "FAIL" in windows with the title "AutoIT_TestChecker". I have tried this both before opening the InputBox and while it is open.

 

As for 3 ) , a tester will read what the InputBox/ToolTip says, then press "Pass" or "Fail" accordingly, typing a comment if they press "Fail".

Link to post
Share on other sites

You only need to use the function _MsgBoxChangeButtons() to change the button text.

#include <MsgBoxConstants.au3>

$i_Ret = _MsgBoxChangeButtons(BitOR($MB_ICONQUESTION, $MB_OKCANCEL), 'AutoIT_TestChecker', 'some text here', 'Pass', 'Fail')

; do something based on the return ($i_Ret)
If $i_Ret = 1 Then
    MsgBox(0, 'Reply', 'You pressed pass')
Elseif $i_Ret = 2 then
    MsgBox(0, 'Reply', 'You pressed fail')
EndIf

Func _MsgBoxChangeButtons($iFlag, $sTitle, $sText, $sButton1, $sButton2 = '', $sButton3 = '', $iMBTimeOut = 0, $xMBpos = "", $yMBpos = "")
    If Not IsNumber($iFlag) Then
        SetError(1)
        Return -1
    ElseIf Not IsNumber($iMBTimeOut) Then
        SetError(2)
        Return -1
    ElseIf $xMBpos <> "" And IsNumber($xMBpos) = 0 Then
        SetError(3)
        Return -1
    ElseIf $yMBpos <> "" And IsNumber($yMBpos) = 0 Then
        SetError(4)
        Return -1
    EndIf

    Local $MBFile = FileOpen(@TempDir & '\MiscMMB.txt', 2)
    Local $MBLine0 = ''
    Local $MBLine1 = '#NoTrayIcon'
    Local $MBLine2 = 'Opt("WinWaitDelay", 0)'
    Local $MBLine3 = 'WinWait("' & $sTitle & '")'
    Local $MBLine4 = 'ControlSetText("' & $sTitle & '", "", "Button1", "' & $sButton1 & '")'
    Local $MBLine5 = 'ControlSetText("' & $sTitle & '", "", "Button2", "' & $sButton2 & '")'
    Local $MBLine6 = 'ControlSetText("' & $sTitle & '", "", "Button3", "' & $sButton3 & '")'
    Local $MBline7 = 'WinMove("' & $sTitle & '", ""' & ', ' & $xMBpos & ', ' & $yMBpos & ')'
    Local $MBline8 = '$pos = WingetPos("' & $sTitle & '", "")'
    Local $MBline9 = 'WinMove("' & $sTitle & '", ""' & ', ' & $xMBpos & ',$pos[1])'
    Local $MBline10 = 'WinMove("' & $sTitle & '", ""' & ', $pos[0], ' & $yMBpos & ')'

    If $sButton2 = '' Then
        FileWrite(@TempDir & '\MiscMMB.txt', $MBLine0 & @CRLF & $MBLine1 & @CRLF & $MBLine2 & @CRLF & $MBLine3 & @CRLF & $MBLine4)
    ElseIf $sButton2 <> '' And $sButton3 = '' Then
        FileWrite(@TempDir & '\MiscMMB.txt', $MBLine0 & @CRLF & $MBLine1 & @CRLF & $MBLine2 & _
                @CRLF & $MBLine3 & @CRLF & $MBLine4 & @CRLF & $MBLine5)
    ElseIf $sButton2 <> '' And $sButton3 <> '' Then
        FileWrite(@TempDir & '\MiscMMB.txt', $MBLine0 & @CRLF & $MBLine1 & @CRLF & $MBLine2 & @CRLF & _
                $MBLine3 & @CRLF & $MBLine4 & @CRLF & $MBLine5 & @CRLF & $MBLine6)
    EndIf
    If $xMBpos <> "" And $yMBpos <> "" Then
        FileWriteLine(@TempDir & '\MiscMMB.txt', @CRLF & $MBline7)
    ElseIf $xMBpos <> "" And $yMBpos = "" Then
        FileWriteLine(@TempDir & '\MiscMMB.txt', @CRLF & $MBline8)
        FileWriteLine(@TempDir & '\MiscMMB.txt', @CRLF & $MBline9)
    ElseIf $xMBpos = "" And $yMBpos <> "" Then
        FileWriteLine(@TempDir & '\MiscMMB.txt', @CRLF & $MBline8)
        FileWriteLine(@TempDir & '\MiscMMB.txt', @CRLF & $MBline10)
    EndIf


    $MBPID1 = Run(@AutoItExe & ' /AutoIt3ExecuteScript ' & EnvGet('TEMP') & '\MiscMMB.txt')
    $MBBox = MsgBox($iFlag, $sTitle, $sText, $iMBTimeOut)
    FileClose($MBFile)

    Do
        FileDelete(@TempDir & '\MiscMMB.txt')
    Until Not FileExists(@TempDir & '\MiscMMB.txt')

    Return $MBBox
EndFunc   ;==>_MsgBoxChangeButtons

It would be better to create your own GUI with the button  and input box. you'd have more control

 

Link to post
Share on other sites

@benners It works just fine for normal applications made.

However, trying to improve on it, is there a way to set the pos at the start rather than to move the window to the pos? Seeing the MsgBox flash is not a nice thing, especially since the default location is on screen 1, and I don't want anything being seen on screen 1 during testing (I just set the pos to -y (top screen)).

Also, I can't seem to find any AutoIT call/variable to set for width/height like InputBox does.

It seems I need to resort to my own GUI...

Link to post
Share on other sites

Try this:

 

#include <WinAPI.au3>
#include <Constants.au3>

Global $MsgBoxX = @DesktopWidth + 20    ;Adjust position here
Global $MsgBoxY = 20                    ;and here

Local $hProcMsgBox = DllCallbackRegister("CbtHookProcMsgBox", "int", "int;int;int")
Local $TIDMsgBox = _WinAPI_GetCurrentThreadId()
Local $hHookMsgBox = _WinAPI_SetWindowsHookEx($WH_CBT, DllCallbackGetPtr($hProcMsgBox), 0, $TIDMsgBox)



Local $iRet = MsgBox(34, "Select example", "Please select the skin you want to try")



_WinAPI_UnhookWindowsHookEx($hHookMsgBox)
DllCallbackFree($hProcMsgBox)



#region Just for fun!!
;##########################################################
Func CbtHookProcMsgBox($nCode, $wParam, $lParam)
    Local $RET = 0
    If $nCode < 0 Then
        $RET = _WinAPI_CallNextHookEx($hHookMsgBox, $nCode, $wParam, $lParam)
        Return $RET
    EndIf
    Switch $nCode
        Case 5 ;5=HCBT_ACTIVATE
            _WinAPI_SetDlgItemText($wParam, 3, "1")
            _WinAPI_SetDlgItemText($wParam, 4, "2")
            _WinAPI_SetDlgItemText($wParam, 5, "3")
            _WinAPI_SetWindowPos($wParam, $HWND_TOP, $MsgBoxX, $MsgBoxY, _WinAPI_GetWindowWidth($wParam), _WinAPI_GetWindowHeight($wParam), $SWP_NOZORDER)
    EndSwitch
    Return $RET
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 Just for fun!!

 

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 post
Share on other sites

So this is the last chance ;)

 

#include <WinAPI.au3>
#include <Constants.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"

Local $hProcMsgBox = DllCallbackRegister("CbtHookProcMsgBox", "int", "int;int;int")
Local $TIDMsgBox = _WinAPI_GetCurrentThreadId()
Local $hHookMsgBox = _WinAPI_SetWindowsHookEx($WH_CBT, DllCallbackGetPtr($hProcMsgBox), 0, $TIDMsgBox)



#region Your code starts here

Global $MsgBoxX = @DesktopWidth + 20 ;Adjust position here
Global $MsgBoxY = 20 ;and here

Global $BtnDesc1 = "1", $BtnDesc2 = "2", $BtnDesc3 = "3"
Global $iRet = MsgBox(34, "Select example", "Please select the skin you want to try")

Global $BtnDesc1 = "4", $BtnDesc2 = "5", $BtnDesc3 = "6"
$iRet = MsgBox(34, "Select example 2", "Please select the skin you want to try")

#endregion Your code ends here



_WinAPI_UnhookWindowsHookEx($hHookMsgBox)
DllCallbackFree($hProcMsgBox)

#region Just for fun!!
;##########################################################
Func CbtHookProcMsgBox($nCode, $wParam, $lParam)
    Local $tcw, $tcs

    If $nCode < 0 Then
        Return _WinAPI_CallNextHookEx($hHookMsgBox, $nCode, $wParam, $lParam)
    EndIf

    Switch $nCode
        Case 3 ;5=HCBT_CREATEWND
            If _WinAPI_GetClassName(HWnd($wParam)) = "#32770" Then
                $tcw = DllStructCreate($tagCBT_CREATEWND, $lParam)
                $tcs = DllStructCreate($tagCREATESTRUCT, DllStructGetData($tcw, "lpcs"))

                DllStructSetData($tcs, "x", $MsgBoxX)
                DllStructSetData($tcs, "y", $MsgBoxY)
            EndIf
        Case 5 ;5=HCBT_ACTIVATE
            _WinAPI_SetDlgItemText($wParam, 3, $BtnDesc1)
            _WinAPI_SetDlgItemText($wParam, 4, $BtnDesc2)
            _WinAPI_SetDlgItemText($wParam, 5, $BtnDesc3)
    EndSwitch
    Return _WinAPI_CallNextHookEx($hHookMsgBox, $nCode, $wParam, $lParam)
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 Just for fun!!

 

Edited by funkey

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 post
Share on other sites
  • 2 weeks later...

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By nooneclose
      Why can I not click on either of my input fields?
      #Region ### START Koda GUI section ### Form= Global $Form1 = GUICreate("Form1", 730, 437, 192, 124) ;GUISetFont(14, 800, 0, "MS Sans Serif") GUISetBkColor(0xC0DCC0) Global $Label1 = GUICtrlCreateLabel("Enter your Password. UserName is auto filled", 62, 40, 604, 41, $SS_CENTER) GUICtrlSetFont(-1, 26, 800, 0, "MS Sans Serif") Global $Label2 = GUICtrlCreateLabel("User Name:", 120, 130, 604, 31, $SS_LEFT) GUICtrlSetFont(-1, 20, 800, 0, "MS Sans Serif") Global $Label3 = GUICtrlCreateLabel("Password:", 135, 210, 604, 31, $SS_LEFT) GUICtrlSetFont(-1, 20, 800, 0, "MS Sans Serif") Global $Input1 = GUICtrlCreateInput(@UserName, 274, 130, 185, 32) GUICtrlSetFont(-1, 14, 800, 1, "MS Sans Serif") Global $Input2 = GUICtrlCreateInput("Password", 274, 210, 185, 32, $ES_PASSWORD) GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif") Global $OK = GUICtrlCreateButton("OK", 274, 270, 185, 57) GUICtrlSetFont(-1, 20, 800, 0, "MS Sans Serif") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $OK Global $UserName = GUICtrlRead($Input1) Global $PassWord = GUICtrlRead($Input2) ExitLoop EndSwitch WEnd ; Delete the GUI window GUIDelete()  
    • By matwachich
      Hi AutoIters!
      Here is my new UDF about GUIs: it's an enhanced mixture of Advanced InputBox (deprecated) and KODA Parser (deprecated), with additional functions.
      What you can do with it:
      Parse KODA files and directly create GUIs (_GUIUtils_CreateFromKODA) Parse a simple JSON form definition to simply create advanced InputBoxes with any amount/type of input controls (_GUIUtils_CreateFromJSON) Created GUIs are returned as Scripting.Dictionary objects, and you have helper functions to access GUIs controls by their names (_GUIUtils_HWnd, _GUIUtils_CtrlID, _GUIUtils_HCtrl ...) A function that can make a GUI created from KODA/JSON (defined by it's $oForm object) and make it a modal InputDialogBox (just like InputBox, but returns all entered data as Scripting.Dictionary object) Functions are documented, and there are some examples.
      Consider this UDF as beta, but since I'm currently using it in a small commercial project, it should become production ready in near future.
      To always get the latest code version, get it from Github (more up to date than this topic).
      Update 04/02/2020:
      New simple application example Fixed focused control handling in _GUIUtils_InputDialog Reset input values before returning from _GUIUtils_InputDialog Fixed CloseOnEsc in _GUIUtils_InputDialog Fixed Input not reset Fixed all ListBox items are selected Project now on GitHub https://github.com/matwachich/autoit-guiutils/
      Update 05/02/2020:
      Support for nodate for Date and Time input controls (pass null value) New handling of focused control _GUIUtils_InputDialog: Now, you can specify the focused control in $oInitialData by setting "controlName:focus" = True Updated documentation of _GUIUtils_InputDialog Update 07/02/2020:
      Bug corrected when setting Data input control Added: abillity to read a single input control New functions (_GUIUtils_GetInputs, _GUIUtils_WriteInputs), documentation completion. Readme file and screenshots on Github Page  
      GUIUtils.zip
    • By matwachich
      DEPRECATED: see this new UDF
       
    • By robertocm
      I'm trying to use some inputboxes as radio buttons.
      This code seems to work ok, but don't know if there's is a better 'option'
      #include <GUIConstantsEx.au3> #include <GuiConstants.au3> GUIRegisterMsg($WM_COMMAND, "WM_COMMAND") Global $aInput[4] $hGUI = GUICreate("Test", 500, 500) $aInput[0] = GUICtrlCreateInput("Some text 1a", 10, 10, 200, 24) $aInput[1] = GUICtrlCreateInput("Some text 1b", 10, 40, 200, 24) $aInput[2] = GUICtrlCreateInput("Some text 2a", 10, 80, 200, 24) $aInput[3] = GUICtrlCreateInput("Some text 2b", 10, 110, 200, 24) GUISetState(@SW_SHOW, $hGUI) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func WM_COMMAND($hWnd, $msg, $wParam, $lParam) Local $nNotifyCode = BitShift($wParam, 16) ; high word Local $nID = BitAND($wParam, 0xFFFF) ; low word Local $hCtrl = $lParam Switch $nID Case $aInput[0] Switch $nNotifyCode Case $EN_SETFOCUS GUICtrlSetBkColor($aInput[0], 0x98FB98) GUICtrlSetBkColor($aInput[1], 0xD3D3D3) EndSwitch Case $aInput[1] Switch $nNotifyCode Case $EN_SETFOCUS GUICtrlSetBkColor($aInput[0], 0xD3D3D3) GUICtrlSetBkColor($aInput[1], 0x98FB98) EndSwitch Case $aInput[2] Switch $nNotifyCode Case $EN_SETFOCUS GUICtrlSetBkColor($aInput[2], 0x98FB98) GUICtrlSetBkColor($aInput[3], 0xD3D3D3) EndSwitch Case $aInput[3] Switch $nNotifyCode Case $EN_SETFOCUS GUICtrlSetBkColor($aInput[2], 0xD3D3D3) GUICtrlSetBkColor($aInput[3], 0x98FB98) EndSwitch EndSwitch ; Proceed the default Autoit3 internal message commands. ; You also can complete let the line out. ; !!! But only 'Return' (without any value) will not proceed ; the default Autoit3-message in the future !!! Return $GUI_RUNDEFMSG EndFunc ;==>WM_COMMAND Would you recommend using _WinAPI_GetFocus instead?
       
       
      Thanks,
       
    • By Ackerz
      Hi guys,
      So I am trying to automate a task and this task has an input box with an already set character "9". 
      I have just decided that I don't really need the input as an option but it's good to leave however for this instance I would like it to run past this point automatically. I've tried numerous ways to try and automate the use of the "OK" button using ControlClick and various other options. I just can't seem to see where this point in the script is. Scoured the forums for anything similar but didn't have any luck finding anything. Sorry to be a pain and I hope someone can help, if I haven't explained in enough detail please don't hesitate to ask for more.
      Many thanks,
      Ackerz
       
      Local $len Local $n Local $buff Local $aMyDate $Len = InputBox("Test",$msgPrompt,"9") $len = StringStripWS($len,$STR_STRIPALL) ;Check that user has entered a vaild password length if not StringIsDigit($len) or $len = 0 Then MsgBox(48,"Error","Invaild Integer was entered" & @CRLF & "Program will now exit.") Exit EndIf ;This creates the random password. for $i = 1 to $Len ;Pick a random char between 1 and the pwsMask Length $n = int(random(1,StringLen($pwsMask))) ;Concat each char that has been picked out of pwsMask to $buff $buff = $Buff & StringMid($pwsmask,$n,1) Next  
×
×
  • Create New...