MrCreatoR Posted April 16, 2020 Share Posted April 16, 2020 I am trying to figure out how to make _WinAPI_BrowseForFolderDlg have more options. One of the main option i need is the ability to set checkboxes and return their state. This is what i have so far: expandcollapse popup#include <TreeViewConstants.au3> #include <WindowsConstants.au3> #include <WinAPIDlg.au3> #include <GUITreeView.au3> Global $ahWnds[2] Global $iState = 0 $sInitDir = @ProgramFilesDir $sRoot = _WinAPI_PathStripToRoot($sInitDir) ;Subclassing for _BrowseProc (taken from GUIRegisterMsg20 UDF) $hMsgProc = DllCallbackRegister("WM_MESSAGE", "lresult", "hwnd;uint;wparam;lparam;uint_ptr;dword_ptr" ) $pMsgProc = DllCallbackGetPtr($hMsgProc) $hBrowseProc = DllCallbackRegister('_BrowseProc', 'int', 'hwnd;uint;lparam;ptr') $pBrowseProc = DllCallbackGetPtr($hBrowseProc) $pText = _WinAPI_CreateString($sInitDir) $sPath = _WinAPI_BrowseForFolderDlg($sRoot, 'Select a folder from the list below.', BitOR($BIF_RETURNONLYFSDIRS, $BIF_UAHINT, $BIF_BROWSEINCLUDEFILES, $BIF_VALIDATE, $BIF_NEWDIALOGSTYLE, $BIF_NONEWFOLDERBUTTON), $pBrowseProc, $pText) _WinAPI_FreeMemory($pText) If $sPath Then ConsoleWrite('--------------------------------------------------' & @CRLF) ConsoleWrite($sPath & @CRLF) EndIf DllCallbackFree($hMsgProc) DllCallbackFree($hBrowseProc) For $i = 0 To 1 DllCall("comctl32.dll", "bool", "RemoveWindowSubclass", "hwnd", $ahWnds[$i], "ptr", $pMsgProc, "uint_ptr", $i) Next Func _BrowseProc($hWnd, $iMsg, $wParam, $lParam) Local $sPath Switch $iMsg Case $BFFM_INITIALIZED $hTV = ControlGetHandle($hWnd, '', 'SysTreeView321') ;Set checkboxes _WinAPI_SetWindowLong($hTV, $GWL_STYLE, BitOR(_WinAPI_GetWindowLong($hTV, $GWL_STYLE), $TVS_CHECKBOXES)) ;Set title _WinAPI_SetWindowText($hWnd, 'MyTitle') ;Set default selection _SendMessage($hWnd, $BFFM_SETSELECTIONW, 1, $lParam) $ahWnds[0] = _WinAPI_GetParent($hTV) $ahWnds[1] = $hWnd ;Subclassing to monitor treeview events DllCall("comctl32.dll", "bool", "SetWindowSubclass", "hwnd", $ahWnds[0], "ptr", $pMsgProc, "uint_ptr", 0, "dword_ptr", 0) DllCall("comctl32.dll", "bool", "SetWindowSubclass", "hwnd", $ahWnds[1], "ptr", $pMsgProc, "uint_ptr", 1, "dword_ptr", 0) Case $BFFM_SELCHANGED $sPath = _WinAPI_ShellGetPathFromIDList($wParam) ;Show the selected path If Not @error Then ConsoleWrite($sPath & @CRLF) EndIf EndSwitch Return 0 EndFunc ;WM messages handler Func WM_MESSAGE($hWnd, $iMsg, $wParam, $lParam, $iID, $pData) If $hWnd <> $ahWnds[$iID] Then Return DllCall( "comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam)[0] EndIf Switch $iMsg Case $WM_NOTIFY Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $iCode Case $NM_CLICK ; The user has clicked the left mouse button within the control Local $tMPos = _WinAPI_GetMousePos(True, $hWndFrom) Local $tHit = _GUICtrlTreeView_HitTestEx($hWndFrom, DllStructGetData($tMPos, 1), DllStructGetData($tMPos, 2)) Local $hItem = DllStructGetData($tHit, "Item") Local $iFlags = DllStructGetData($tHit, "Flags") If $hItem <> 0 And BitAND($iFlags, $TVHT_ONITEMSTATEICON) Then ;Current state of item checkbox $iState = Not _GUICtrlTreeView_GetChecked($hWndFrom, $hItem) EndIf Case $TVN_SELCHANGEDA, $TVN_SELCHANGEDW EndSwitch Case $WM_COMMAND ;Exit button clicked If _WinAPI_LoWord($wParam) = 1 Then ;Do something EndIf EndSwitch Return DllCall( "comctl32.dll", "lresult", "DefSubclassProc", "hwnd", $hWnd, "uint", $iMsg, "wparam", $wParam, "lparam", $lParam)[0] EndFunc Here i can get the state of the checkbox and currently selected item's path, but how i can collect all the states (including the real pathes) and return to the main caller? Or maybe there is a way to get all checked items paths once the Ok button clicked? Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
MrCreatoR Posted April 16, 2020 Author Share Posted April 16, 2020 (edited) Ok, first task completed (getting the selected checkboxes), it was easier then i thought. Even without the subclassing: expandcollapse popup#include <WindowsConstants.au3> #include <WinAPIDlg.au3> #include <GUITreeView.au3> Global $sPrev_Path, $sChecked $sInitDir = @ProgramFilesDir $sRoot = _WinAPI_PathStripToRoot($sInitDir) $hBrowseProc = DllCallbackRegister('_BrowseProc', 'int', 'hwnd;uint;lparam;ptr') $pBrowseProc = DllCallbackGetPtr($hBrowseProc) $pText = _WinAPI_CreateString($sInitDir) $sPath = _WinAPI_BrowseForFolderDlg($sRoot, 'Select a folder from the list below.', BitOR($BIF_RETURNONLYFSDIRS, $BIF_UAHINT, $BIF_BROWSEINCLUDEFILES, $BIF_VALIDATE, $BIF_NEWDIALOGSTYLE, $BIF_NONEWFOLDERBUTTON), $pBrowseProc, $pText) _WinAPI_FreeMemory($pText) If $sPath Then ConsoleWrite($sChecked & @CRLF) ;ConsoleWrite('--------------------------------------------------' & @CRLF) ;ConsoleWrite($sPath & @CRLF) EndIf DllCallbackFree($hBrowseProc) Func _BrowseProc($hWnd, $iMsg, $wParam, $lParam) Local $sPath Local Static $hLastItem, $hTV = ControlGetHandle($hWnd, '', 'SysTreeView321') Switch $iMsg Case $BFFM_INITIALIZED ;Set checkboxes _WinAPI_SetWindowLong($hTV, $GWL_STYLE, BitOR(_WinAPI_GetWindowLong($hTV, $GWL_STYLE), $TVS_CHECKBOXES)) ;Set title _WinAPI_SetWindowText($hWnd, 'MyTitle') ;Set default selection _SendMessage($hWnd, $BFFM_SETSELECTIONW, 1, $lParam) Case $BFFM_SELCHANGED If $hLastItem Then _StringUpdate($sChecked, $sPrev_Path, _GUICtrlTreeView_GetChecked($hTV, $hLastItem)) EndIf $hLastItem = _GUICtrlTreeView_GetSelection($hTV) $sPath = _WinAPI_ShellGetPathFromIDList($wParam) If Not @error Then $sPrev_Path = $sPath EndIf EndSwitch Return 0 EndFunc Func _StringUpdate(ByRef $sString, $sValue, $bAdd, $bUnique = True, $sDelim = Default) If $sDelim == Default Then $sDelim = Opt('GUIDataSeparatorChar') EndIf If $bAdd Then If Not $bUnique Or ($bUnique And Not StringInStr($sDelim & $sString & $sDelim, $sDelim & $sValue & $sDelim, 2)) Then $sString &= ($sString ? $sDelim : '') & $sValue EndIf Return EndIf ;Remove If StringInStr($sDelim & $sString & $sDelim, $sDelim & $sValue & $sDelim, 2) Then Local $aString = StringSplit($sString, $sDelim) $sString = '' For $i = 1 To $aString[0] If $aString[$i] <> $sValue Then $sString &= ($sString ? $sDelim : '') & $aString[$i] EndIf Next EndIf EndFunc Now there is another task: How to pre-set the checkboxes from a similar paths list? Edited April 16, 2020 by MrCreatoR argumentum 1 Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
MrCreatoR Posted April 17, 2020 Author Share Posted April 17, 2020 1 hour ago, MrCreatoR said: How to pre-set the checkboxes from a similar paths list? It seems that we can take a path, convert it to PIDL, and then send selection message to the callback function (to itself actually), but it's not working for items that are hidden. I suspect that this is because those items still not exists on that stage, they are created on each expansion. This what i have tried: expandcollapse popupFunc _BrowseProc($hWnd, $iMsg, $wParam, $lParam) Local $sPath, $aSplit, $pIDL Local Static $hLastItem, $hTV = ControlGetHandle($hWnd, '', 'SysTreeView321') Switch $iMsg Case $BFFM_INITIALIZED ;Set checkboxes _WinAPI_SetWindowLong($hTV, $GWL_STYLE, BitOR(_WinAPI_GetWindowLong($hTV, $GWL_STYLE), $TVS_CHECKBOXES)) ;Set title _WinAPI_SetWindowText($hWnd, 'MyTitle') ;Split the pre-checked list and set checkboxes by PIDL $aSplit = StringSplit($sChecked, '|') For $i = 1 To $aSplit[0] $pIDL = _WinAPI_ShellILCreateFromPath($aSplit[$i]) _SendMessage($hWnd, $BFFM_SETSELECTIONW, 0, $pIDL) _WinAPI_CoTaskMemFree($pIDL) _GUICtrlTreeView_SetChecked($hTV, _GUICtrlTreeView_GetSelection($hTV)) Next ;Set default selection _SendMessage($hWnd, $BFFM_SETSELECTIONW, 1, $lParam) Case $BFFM_SELCHANGED If $hLastItem Then _StringUpdate($sChecked, $sPrev_Path, _GUICtrlTreeView_GetChecked($hTV, $hLastItem)) EndIf $hLastItem = _GUICtrlTreeView_GetSelection($hTV) $sPath = _WinAPI_ShellGetPathFromIDList($wParam) If Not @error Then $sPrev_Path = $sPath If _GUICtrlTreeView_GetExpanded($hTV, $hLastItem) Then ConsoleWrite($sPath & @CRLF) EndIf EndIf EndSwitch Return 0 EndFunc Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
MrCreatoR Posted April 17, 2020 Author Share Posted April 17, 2020 (edited) Ok, i think i got it to work (again, obviously it was easier then i thought). When the window initialized, we send expand message (as PIDL), and then we just send another message to select the item, and then once we have target item selected, we can set checked state for that item. expandcollapse popup#include <WindowsConstants.au3> #include <WinAPIDlg.au3> #include <GUITreeView.au3> Global $sChecked $sInitDir = @ProgramFilesDir $sRoot = _WinAPI_PathStripToRoot($sInitDir) $hBrowseProc = DllCallbackRegister('_BrowseProc', 'int', 'hwnd;uint;lparam;ptr') $pBrowseProc = DllCallbackGetPtr($hBrowseProc) $sChecked = $sInitDir & '|' & @UserProfileDir & '|' & @DesktopDir $pText = _WinAPI_CreateString($sInitDir) $sPath = _WinAPI_BrowseForFolderDlg($sRoot, 'Select a folder from the list below.', BitOR($BIF_RETURNONLYFSDIRS, $BIF_UAHINT, $BIF_BROWSEINCLUDEFILES, $BIF_VALIDATE, $BIF_NEWDIALOGSTYLE, $BIF_NONEWFOLDERBUTTON), $pBrowseProc, $pText) _WinAPI_FreeMemory($pText) If $sPath Then ConsoleWrite($sChecked & @CRLF) ;ConsoleWrite('--------------------------------------------------' & @CRLF) ;ConsoleWrite($sPath & @CRLF) EndIf DllCallbackFree($hBrowseProc) Func _BrowseProc($hWnd, $iMsg, $wParam, $lParam) Local $sPath, $aSplit, $pIDL Local Static $sPrev_Path, $hPrev_Item Local Static $hTV = ControlGetHandle($hWnd, '', 'SysTreeView321') Switch $iMsg Case $BFFM_INITIALIZED ;Set checkboxes _WinAPI_SetWindowLong($hTV, $GWL_STYLE, BitOR(_WinAPI_GetWindowLong($hTV, $GWL_STYLE), $TVS_CHECKBOXES)) ;Set title _WinAPI_SetWindowText($hWnd, 'MyTitle') ;Split the pre-checked list and set checkboxes by PIDL $aSplit = StringSplit($sChecked, '|') ;$sChecked = '' For $i = 1 To $aSplit[0] $pIDL = _WinAPI_ShellILCreateFromPath($aSplit[$i]) _SendMessage($hWnd, $BFFM_SETEXPANDED, 0, $pIDL) _SendMessage($hWnd, $BFFM_SETSELECTIONW, 0, $pIDL) _WinAPI_CoTaskMemFree($pIDL) _GUICtrlTreeView_SetChecked($hTV, _GUICtrlTreeView_GetSelection($hTV)) ;_GUICtrlTreeView_Expand($hTV, _GUICtrlTreeView_GetSelection($hTV), False) Next ;Set default selection _SendMessage($hWnd, $BFFM_SETSELECTIONW, 1, $lParam) Case $BFFM_SELCHANGED If $hPrev_Item Then _StringUpdate($sChecked, $sPrev_Path, _GUICtrlTreeView_GetChecked($hTV, $hPrev_Item)) EndIf $hPrev_Item = _GUICtrlTreeView_GetSelection($hTV) $sPath = _WinAPI_ShellGetPathFromIDList($wParam) If Not @error Then $sPrev_Path = $sPath EndIf EndSwitch Return 0 EndFunc Func _StringUpdate(ByRef $sString, $sValue, $bAdd, $bUnique = True, $sDelim = Default) If $sDelim == Default Then $sDelim = Opt('GUIDataSeparatorChar') EndIf If $bAdd Then If Not $bUnique Or ($bUnique And Not StringInStr($sDelim & $sString & $sDelim, $sDelim & $sValue & $sDelim, 2)) Then $sString &= ($sString ? $sDelim : '') & $sValue EndIf Return EndIf ;Remove If StringInStr($sDelim & $sString & $sDelim, $sDelim & $sValue & $sDelim, 2) Then Local $aString = StringSplit($sString, $sDelim) $sString = '' For $i = 1 To $aString[0] If $aString[$i] <> $sValue Then $sString &= ($sString ? $sDelim : '') & $aString[$i] EndIf Next EndIf EndFunc The "Magic" constant (BFFM_SETEXPANDED) i found here. Edited April 17, 2020 by MrCreatoR argumentum and Danyfirex 1 1 Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
MrCreatoR Posted April 17, 2020 Author Share Posted April 17, 2020 Strange how i ask here and answer to myself . Well... "I like to talk with a smart person!" © Danyfirex, argumentum, FrancescoDiMuro and 1 other 3 1 Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
MrCreatoR Posted April 27, 2020 Author Share Posted April 27, 2020 The results: BrowseForFolder Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
KaFu Posted April 27, 2020 Share Posted April 27, 2020 (edited) Or as they say here, a good monologue requires a smart discussion partner ;). Edit: Ripped from SMF, not exactly what you requested, but same direction. expandcollapse popup#include <WinAPIDlg.au3> #include <GuiTreeView.au3> Global $hInstance_User32_dll = _WinAPI_GetModuleHandle("user32.dll") Global $hAddress_User32_dll_SendMessageW = _WinAPI_GetProcAddress($hInstance_User32_dll, "SendMessageW") Global $__FileSelectFolder_Ex_Titel, $__FileSelectFolder_Ex_Ini_Done, $__FileSelectFolder_Ex_hWnd_Parent Local $s_Folder_Destination = _FileSelectFolder_Ex("", "", 7, "") MsgBox(0,"",$s_Folder_Destination) Func _FileSelectFolder_Ex($sDialogText = "Select a folder from the list below.", $sRootDir = "", $iFlag = 0, $sInitialDir = "", $hParent = 0, $sDialogTitle = "Select Folder") $__FileSelectFolder_Ex_Titel = $sDialogTitle ; Global Var $__FileSelectFolder_Ex_hWnd_Parent = $hParent ; Global Var If Not IsHWnd($__FileSelectFolder_Ex_hWnd_Parent) Then $__FileSelectFolder_Ex_hWnd_Parent = 0 If Not FileExists("\\?\" & $sInitialDir) Then $sInitialDir = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" ; CLSID for "My Computer" Local $hBrowseProc = DllCallbackRegister('_FileSelectFolder_Ex_BrowseProc', 'int', 'hwnd;uint;lparam;ptr') Local $pText = _WinAPI_CreateString($sInitialDir) Local $sPath = _WinAPI_BrowseForFolderDlg($sRootDir, $sDialogText, BitOR($BIF_RETURNONLYFSDIRS, $BIF_VALIDATE, $BIF_USENEWUI), DllCallbackGetPtr($hBrowseProc), $pText, $__FileSelectFolder_Ex_hWnd_Parent) _WinAPI_FreeMemory($pText) DllCallbackFree($hBrowseProc) If Not $sPath Then Return SetError(1, "", "") Return $sPath EndFunc ;==>_FileSelectFolder_Ex Volatile Func _FileSelectFolder_Ex_BrowseProc($hWnd, $iMsg, $wParam, $lParam) Switch $iMsg Case $BFFM_INITIALIZED #cs _WinAPI_SetWindowLong($hWnd, $GWL_EXSTYLE, BitXOR(_WinAPI_GetWindowLong($hWnd, $GWL_EXSTYLE), $WS_EX_CONTEXTHELP)) _WinAPI_SetWindowLong($hWnd, $GWL_STYLE, BitXOR(_WinAPI_GetWindowLong($hWnd, $GWL_STYLE), $DS_CONTEXTHELP)) _WinAPI_SetWindowPos($hWnd, 0, 0, 0, 0, 0, BitOR($SWP_FRAMECHANGED, $SWP_NOCOPYBITS, $SWP_NOACTIVATE, $SWP_NOMOVE, $SWP_NOSIZE)) #ce _WinAPI_SetWindowText($hWnd, $__FileSelectFolder_Ex_Titel) $__FileSelectFolder_Ex_Ini_Done = False If $lParam Then _SendMessage_CallByAddress($hWnd, $BFFM_SETSELECTIONW, 1, $lParam) ; Initial Dir Local $hCtrl = ControlGetHandle($hWnd, "", "[CLASS:SysTreeView32; INSTANCE:1]") ; Expand Initial Dir _GUICtrlTreeView_Expand($hCtrl, _GUICtrlTreeView_GetSelection($hCtrl), True) If FileExists("\\?\" & _WinAPI_GetString($lParam)) Then _SendMessage_CallByAddress($hWnd, $BFFM_ENABLEOK, 0, 1) Else _SendMessage_CallByAddress($hWnd, $BFFM_ENABLEOK, 0, 0) EndIf ; ConsoleWrite($hWnd & @tab & $__FileSelectFolder_Ex_hWnd_Parent & @tab & WinGetTitle($__FileSelectFolder_Ex_hWnd_Parent) & @crlf) If IsHWnd($__FileSelectFolder_Ex_hWnd_Parent) Then Local $aWinPos_Parent = WinGetPos($__FileSelectFolder_Ex_hWnd_Parent) ; XP Default Size: 667, 553 WinMove($hWnd, "", $aWinPos_Parent[0] + (0.5 * $aWinPos_Parent[2]) - (500 / 2), $aWinPos_Parent[1] + (0.5 * $aWinPos_Parent[3]) - (540 / 2), 500, 540) Else WinMove($hWnd, "", 100, 100, 500, 540) EndIf ControlMove($hWnd, "", "[CLASSNN:Static1]", 10, 10, 480, 20) ControlMove($hWnd, "", "[CLASSNN:SHBrowseForFolder ShellNameSpace Control1]", 10, 30, 465, 400) ControlMove($hWnd, "", "[CLASSNN:Static4]", 10, 443, 50, 20) ControlMove($hWnd, "", "[CLASSNN:Edit1]", 60, 440, 415, 20) ControlMove($hWnd, "", "[CLASSNN:Button1]", 10, 470, 140, 25) ControlMove($hWnd, "", "[CLASSNN:Button2]", 305, 470, 80, 25) ControlMove($hWnd, "", "[CLASSNN:Button3]", 395, 470, 80, 25) $__FileSelectFolder_Ex_Ini_Done = True Case $BFFM_SELCHANGED If $__FileSelectFolder_Ex_Ini_Done Then Local $Path = _WinAPI_ShellGetPathFromIDList($wParam) If FileExists("\\?\" & $Path) Then _SendMessage_CallByAddress($hWnd, $BFFM_ENABLEOK, 0, 1) Else _SendMessage_CallByAddress($hWnd, $BFFM_ENABLEOK, 0, 0) EndIf EndIf #cs { In a BIF_NEWDIALOGSTYLE dialog, BIF_RETURNONLYFSDIRS does not cause the OK button to be disabled automatically when the user clicks a non-FS item (e.g. My Computer), so do that ourself. } ShouldEnable := SHGetPathFromIDList(PItemIDList(lParam), Path); SendMessage(Wnd, BFFM_ENABLEOK, 0, Ord(ShouldEnable)); #ce Case $BFFM_VALIDATEFAILED MsgBox(16, 'Error', _WinAPI_GetString($wParam) & ' is an invalid directory.', 0, $hWnd) Return 1 EndSwitch Return 0 EndFunc ;==>_FileSelectFolder_Ex_BrowseProc Func _SendMessage_CallByAddress($hWnd, $iMsg, $wParam = 0, $lParam = 0, $iReturn = 0, $wParamType = "wparam", $lParamType = "lparam", $sReturnType = "lresult") Local $aResult = DllCallAddress($sReturnType, $hAddress_User32_dll_SendMessageW, "hwnd", $hWnd, "uint", $iMsg, $wParamType, $wParam, $lParamType, $lParam) If @error Then Return SetError(@error, @extended, "") If $iReturn >= 0 And $iReturn <= 4 Then Return $aResult[$iReturn] Return $aResult EndFunc ;==>_SendMessage_CallByAddress Edited April 27, 2020 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
MrCreatoR Posted April 27, 2020 Author Share Posted April 27, 2020 4 hours ago, KaFu said: same direction Few questions please... 1) What is the difference of using normal SendMessage call and calling that function by it's address? 2) Why Volatile needed in this case for the callback function? Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
KaFu Posted April 27, 2020 Share Posted April 27, 2020 (edited) 1) I think execution speed, I use it throughout SMF Edit: expandcollapse popup#include <GUIConstants.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> #include <SendMessage.au3> Opt("GUIOnEventMode", 1) #include <WinAPIDlg.au3> Global $hInstance_User32_dll = _WinAPI_GetModuleHandle("user32.dll") Global $hAddress_User32_dll_SendMessageW = _WinAPI_GetProcAddress($hInstance_User32_dll, "SendMessageW") Global $GUI_Main Global Const $SC_DRAGMOVE = 0xF012 Create_GUI() $iTimer = TimerInit() $iEnum = 0 While TimerDiff($iTimer) < 1000 _SendMessage($GUI_Main, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0) $iEnum += 1 WEnd ConsoleWrite("_SendMessage" & @TAB & $iEnum & @CRLF) $iTimer = TimerInit() $iEnum = 0 While TimerDiff($iTimer) < 1000 _SendMessage_CallByAddress($GUI_Main, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0) $iEnum += 1 WEnd ConsoleWrite("_SendMessage_CallByAddress" & @TAB & $iEnum & @CRLF) While 1 Sleep(10) WEnd Func Create_GUI() Global $GUI_Main = GUICreate("Main GUI", 200, 100) Global $GUI_Main_Button = GUICtrlCreateLabel("Button", 0, 0, 200, 100, BitOR($SS_CENTERIMAGE, $SS_CENTER, $SS_RIGHTJUST)) GUICtrlSetOnEvent($GUI_Main_Button, "Drag") GUISetOnEvent($GUI_EVENT_CLOSE, "Exiting_Function") GUISetState(@SW_SHOW, $GUI_Main) EndFunc ;==>Create_GUI Func Drag() $pos = WinGetPos($GUI_Main) ; _SendMessage($GUI_Main, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0) Sleep(10) $pos2 = WinGetPos($GUI_Main) If $pos[0] = $pos2[0] And $pos[1] = $pos2[1] Then Button_Function() EndFunc ;==>Drag Func Button_Function() MsgBox($MB_OK, "You did the thing", "I only want the thing done if I didn't use the label/button to drag the GUI") EndFunc ;==>Button_Function Func Exiting_Function() Exit EndFunc ;==>Exiting_Function Func _SendMessage_CallByAddress($hWnd, $iMsg, $wParam = 0, $lParam = 0, $iReturn = 0, $wParamType = "wparam", $lParamType = "lparam", $sReturnType = "lresult") Local $aResult = DllCallAddress($sReturnType, $hAddress_User32_dll_SendMessageW, "hwnd", $hWnd, "uint", $iMsg, $wParamType, $wParam, $lParamType, $lParam) If @error Then Return SetError(@error, @extended, "") If $iReturn >= 0 And $iReturn <= 4 Then Return $aResult[$iReturn] Return $aResult EndFunc ;==>_SendMessage_CallByAddress 2) Volatile > Callback function = "During function execution the main AutoIt's message pump is not blocked as it normally is for non-Volatile callbacks.", I use volatile in all callback functions to make them non-blocking. Edited April 27, 2020 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
MrCreatoR Posted April 27, 2020 Author Share Posted April 27, 2020 44 minutes ago, KaFu said: execution speed Oh i see, thanks. But in my case it's not needed i think. 55 minutes ago, KaFu said: Volatile > Callback function = "During function execution the main AutoIt's message pump is not blocked as it normally is for non-Volatile callbacks." Good to know. Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
MrCreatoR Posted April 27, 2020 Author Share Posted April 27, 2020 Well, about Volatile, it's useless if you use _ArrayDisplay for example in your callback function. Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team 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