Ward Posted August 28, 2011 Share Posted August 28, 2011 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 ?expandcollapse popup; ============================================================================= ; 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 GreenCan, Digisoul and mLipok 3 新版 _ArrayAdd 的白痴作者,不管是誰,去死一死好了。 Link to comment Share on other sites More sharing options...
guinness Posted August 28, 2011 Share Posted August 28, 2011 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 parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
mesale0077 Posted August 28, 2011 Share Posted August 28, 2011 Nice code Link to comment Share on other sites More sharing options...
funkey Posted August 29, 2011 Share Posted August 29, 2011 Looks familiar! Anyway nice functions. Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted August 30, 2011 Moderators Share Posted August 30, 2011 Nice, I had a similar concept: Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Ward Posted August 30, 2011 Author Share Posted August 30, 2011 Nice, I had a similar concept: Oh, I have not find your script before. If I did, I don't need googling so long 新版 _ArrayAdd 的白痴作者,不管是誰,去死一死好了。 Link to comment Share on other sites More sharing options...
ReFran Posted September 4, 2011 Share Posted September 4, 2011 "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 More sharing options...
funkey Posted September 4, 2011 Share Posted September 4, 2011 @ReFran: Something like this= expandcollapse popup#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)!! pixelsearch 1 Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning. Link to comment Share on other sites More sharing options...
Ward Posted September 4, 2011 Author Share Posted September 4, 2011 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 More sharing options...
ReFran Posted September 5, 2011 Share Posted September 5, 2011 Hi, thanks both, works perfect. best regards, Reinhard Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now