Jump to content

Recommended Posts

Hello,

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.

 

HookDlgBox.au3

#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[0] = $TxtBtn1
    $g__aDlgBoxBtnText[1] = $TxtBtn2
    $g__aDlgBoxBtnText[2] = $TxtBtn3
    $g__aDlgBoxBtnText[3] = $TxtBtn4
    $g__aDlgBoxBtnText[4] = $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[0]
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.

 

Best regards

funkey

HookDlgBox Example.au3

HookDlgBox.au3

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

Thanks.

I was quite sure I repaired this. I first used DlgWnd but then I found out that Microsoft is talking about Dialog Boxes.

Here another example with other dialog boxes

 

#include <Misc.au3>
#include "HookDlgBox.au3"


; force german custum button texts for FileOpenDialog
_DlgBox_SetButtonNames("Datei öffnen", "Auswahl abbrechen")
FileOpenDialog("Test", @ScriptDir, "AutoIt scriptses (*.au3)")


_DlgBox_SetButtonNames(Default)
 _DlgBox_SetPosition(500, 100)
_ChooseColor()


_DlgBox_SetButtonNames("Lets go", "No no")
_ChooseFont()

 

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

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 lee321987
      Sometimes when I call several MsgBox's they start popping up under other windows, which the requires ALT + TAB or click the taskbar icon.
      I just wanted to share this workaround:
      Just add a simple GUI in your program:
      #include <GUIConstantsEx.au3> $Form1 = GUICreate("Form1", 1, 1, 0, 0) GUISetState(@SW_SHOW) The GUI window size here is 1x1 so it will be nearly invisible, and at the top-left of your screen.
      It seems as long as that GUI is there all MsgBox's appear on top!
      I only tend to create several MsgBox's in a row when I'm actually writing and testing scripts, so the GUI being there is no big deal (I just remove/comment the GUI creation right before I build the .EXE).
      Have a great day!!!
       
       
×
×
  • Create New...