Jump to content

MsgBoxEx and InputBoxEx


Ward
 Share

Recommended Posts

In my new program, I need custom buttons of system dialog. After search on the internet, I found the way.

Instead of using GUICreate, this code just hook the system dialog.

The hook type is WH_CBT, See MSDN for more information.

Except button text, is there any other interesting thing can be modified ?

; =============================================================================
;  MsgBoxEx And InputBoxEx Examples
;  Purpose: Custom Buttons Of System Dialog
;  Author: Ward
; =============================================================================

#Include <WinAPI.au3>

MsgBoxEx("Button1|Button2", 1, "MsgBoxEx", "Test")
MsgBoxEx("|Button3||||Button1|Button2", 3, "MsgBoxEx", "Test")
InputBoxEx("Button1|Button2", "InputBoxEx", "Prompt")

Func MsgBoxEx($CustomButton, $Flag, $Title, $Text, $Timeout = 0, $Hwnd = 0)
    Assign("MsgBoxEx:CustomButton", $CustomButton, 2)
    Local $CBT_ProcCB = DllCallbackRegister("MsgBoxEx_CBT_Proc", "long", "int;hwnd;lparam")
    Local $CBT_Hook = _WinAPI_SetWindowsHookEx($WH_CBT, DllCallbackGetPtr($CBT_ProcCB), 0, _WinAPI_GetCurrentThreadId())
    Local $Ret = MsgBox($Flag, $Title, $Text, $Timeout, $Hwnd)
    Local $Error = @Error
    _WinAPI_UnhookWindowsHookEx($CBT_Hook)
    DllCallbackFree($CBT_ProcCB)
    Assign("MsgBoxEx:CustomButton", 0, 2)
    Return SetError($Error, 0, $Ret)
EndFunc

Func MsgBoxEx_CBT_Proc($nCode, $wParam, $lParam)
    If $nCode = 5 Then ; HCBT_ACTIVATE
        Local $CustomButton = StringSplit(Eval("MsgBoxEx:CustomButton"), "|")
        For $i = 1 To $CustomButton[0]
            ControlSetText($wParam, "", $i, $CustomButton[$i])
        Next
    EndIf
    Return _WinAPI_CallNextHookEx(0, $nCode, $wParam, $lParam)
EndFunc

Func InputBoxEx($CustomButton, $Title, $Prompt, $Default = "", $Password = "", $Width = Default, $Height = Default, $Left = Default, $Top = Default, $Timeout = Default, $Hwnd = Default)
    Assign("InputBoxEx:CustomButton", $CustomButton, 2)
    Local $CBT_ProcCB = DllCallbackRegister("InputBoxEx_CBT_Proc", "long", "int;hwnd;lparam")
    Local $CBT_Hook = _WinAPI_SetWindowsHookEx($WH_CBT, DllCallbackGetPtr($CBT_ProcCB), 0, _WinAPI_GetCurrentThreadId())
    Local $Ret = InputBox($Title, $Prompt, $Default, $Password, $Width, $Height, $Left, $Top, $Timeout, $Hwnd)
    Local $Error = @Error
    _WinAPI_UnhookWindowsHookEx($CBT_Hook)
    DllCallbackFree($CBT_ProcCB)
    Assign("InputBoxEx:CustomButton", 0, 2)
    Return SetError($Error, 0, $Ret)
EndFunc

Func InputBoxEx_CBT_Proc($nCode, $wParam, $lParam)
    If $nCode = 5 Then ; HCBT_ACTIVATE
        Local $CustomButton = StringSplit(Eval("InputBoxEx:CustomButton"), "|")
        For $i = 1 To $CustomButton[0]
            ControlSetText($wParam, "", $i, $CustomButton[$i])
        Next
    EndIf
    Return _WinAPI_CallNextHookEx(0, $nCode, $wParam, $lParam)
EndFunc

新版 _ArrayAdd 的白痴作者,不管是誰,去死一死好了

 

Link to comment
Share on other sites

Very nice!

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Looks familiar! Anyway nice functions.

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

"Except button text, is there any other interesting thing can be modified ?"

Hi,

thanks for this code. I just have the need for an input box with own buttons, but also I want to have it "onTop".

Can that be set?

best regards, Reinhard

Link to comment
Share on other sites

@ReFran: Something like this=

#include <WinAPI.au3>
#include <Constants.au3>
Local $hProcInputBox = DllCallbackRegister("CbtHookProcInputBox", "int", "int;int;int")
Local $TIDInputBox = _WinAPI_GetCurrentThreadId()
Local $hHookInputBox = _WinAPI_SetWindowsHookEx($WH_CBT, DllCallbackGetPtr($hProcInputBox), 0, $TIDInputBox)
Local $answer = InputBox("Question", "Where were you born?", "Planet Earth", "", -1, -1);, 0, 0)
_WinAPI_UnhookWindowsHookEx($hHookInputBox)
DllCallbackFree($hProcInputBox)

#region Just for fun(key)!!
;##########################################################
Func CbtHookProcInputBox($nCode, $wParam, $lParam)
 Static $iWindowIndex = 0
    Local $RET = 0, $hBitmap = 0, $xWnd = 0
    If $nCode < 0 Then
        $RET = _WinAPI_CallNextHookEx($hHookInputBox, $nCode, $wParam, $lParam)
        Return $RET
    EndIf
    Switch $nCode
 Case 3 ;3=HCBT_CREATEWND
  If $iWindowIndex = 2 Then
   _WinAPI_SetWindowLong($wParam, $GWL_STYLE, 0x50010081)
  EndIf
  $iWindowIndex += 1
  Case 5 ;5=HCBT_ACTIVATE
            _WinAPI_SetDlgItemText($wParam, 1, "Accept")
            _WinAPI_SetDlgItemText($wParam, 2, "Abort")
   _WinAPI_SetWindowPos($wParam, -1, 0, 0, 0, 0, BitOR(0x10, 0x2, 0x1))   ;WinSetOnTop
    EndSwitch
    Return
EndFunc   ;==>CbtHookProcInputBox
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(key)!!

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

How about just modify my code by add one line:

Func InputBoxEx_CBT_Proc($nCode, $wParam, $lParam)
    If $nCode = 5 Then ; HCBT_ACTIVATE
        Local $CustomButton = StringSplit(Eval("InputBoxEx:CustomButton"), "|")
        For $i = 1 To $CustomButton[0]
            ControlSetText($wParam, "", $i, $CustomButton[$i])
        Next
        WinSetOnTop($wParam, "", 1)
    EndIf
    Return _WinAPI_CallNextHookEx(0, $nCode, $wParam, $lParam)
EndFunc

新版 _ArrayAdd 的白痴作者,不管是誰,去死一死好了

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...