Jump to content

Recommended Posts

Posted (edited)

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
Posted

1. ChrisL did something similar with a message box here

2. You maybe able to modify this to work with an input or easy option would be to create your own GUI

3. Depends on the context. What leads to the msgbox prompt.?,  what are pass and fail supposed to do?

Posted

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

Posted

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

 

Posted

@benners Oh, I was trying to strip it down as much as possible.

I guess I'll just include that function so as to keep my code clean.

Thank you for your help.

Posted

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

Posted

As for as I know there isn't a method to move the message box before showing it.

3 hours ago, IAMK said:

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

It would be the best option in my opinion

Posted

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.

Posted (edited)

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.

  • 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
×
×
  • Create New...