Jump to content
Sign in to follow this  
levanduyet

How can I change the caption when I use FileSelectFolder

Recommended Posts

levanduyet

Dear All,

When I use the following code:

$FolderPath = FileSelectFolder("Chose folder","")

How can I change the caption of SelectFolder window and button.

Tks,

LVD

post-46159-0-78560500-1317693157_thumb.p

Edited by levanduyet

Share this post


Link to post
Share on other sites
BrewManNH

I don't think that you can mainly because it's using a built-in Windows function, and secondarily because it pauses the script until you close out of it so even a WinSetTitle won't work because it won't be called until after the window is closed. You'd have to create your own dialog if you wanted something else for the title, although I've been proven wrong about that many times in the past. :graduated:


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
Syed23

There is a function to change the title "WinSetTitle()". I tried for an example from my side but i couldn't :graduated:. Please have a try with this function.


Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Share this post


Link to post
Share on other sites
BrewManNH

There is a function to change the title "WinSetTitle()". I tried for an example from my side but i couldn't :graduated:. Please have a try with this function.

I'm pretty sure my description of the problem explains why WinSetTitle won't work for a modal dialog box like this.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
Syed23

I'm pretty sure my description of the problem explains why WinSetTitle won't work for a modal dialog box like this.

i apologize for posting answer without verification :graduated: i had a multiple tries and BrewManNH completely right.

Edited by Syed23

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Share this post


Link to post
Share on other sites
rover

How can I change the caption of SelectFolder window and button.

Tested with XP/Vista x86

AdlibRegister does not work here, so timer API calls used.

This can also be done with the UDF version of openfolder /w callback that Siao? posted,

or using the method Ward posted recently, and a thousand others on the forum.

Issue with FileSelectFolder and title with flag option.

WinTitleMatchMode lower case match required, because...

flag option: 0, 4 = 'Browse for Folder'

flag option: 1, 2, 6, 7 = 'Browse For Folder'

Opt("MustDeclareVars", 1)
;vars for _OpenFolder
Global $CallBack, $sFSFTitle = "Set Title", $sBtnOK = "OK Then", $sBtnCANCEL = "Well, Maybe", $sStc3Folder = "YourText"
Global $sFolder = _OpenFolder("Choose your folder", "", 6, "", 0)
If Not @error Then MsgBox(0, "Folder Name", $sFolder)
Func _OpenFolder($sText, $sRootDir = "", $iFlag = 0, $sInitDir = "", $hParent = 0)
Local $iOpt = Opt("WinTitleMatchMode", -1) ; force lower case match - Browse for Folder or Browse For Folder
$CallBack = DllCallbackRegister("_FolderCallback", "int", "hwnd;uint;uint_ptr;dword")
Local $aRet = DllCall("User32.dll", "uint_ptr", "SetTimer", "hwnd", $hParent, "uint_ptr", 24681012, _
"uint", 50, "ptr", DllCallbackGetPtr($CallBack))
If @error Or $aRet[0] = 0 Then DllCallbackFree($CallBack)
Local $sTemp = FileSelectFolder($sText, $sRootDir, $iFlag, $sInitDir, $hParent)
Local $iError = @error
Opt("WinTitleMatchMode", $iOpt)
If $CallBack <> 0 Then DllCallbackFree($CallBack)
If $CallBack <> 0 Then DllCall("user32.dll", "int", "KillTimer", "hwnd", $hParent, "uint_ptr", $aRet[0])
Return SetError($iError, 0, $sTemp)
EndFunc
Func _FolderCallback($hWnd, $Msg, $iIDTimer, $dwTime)
#forceref $Msg, $dwTime
Local $aWin = WinList("[TITLE:Browse for Folder; CLASS:#32770]")
If @error Or $aWin[0][0] = 0 Then Return
For $i = 1 To $aWin[0][0]
  If Not IsHWnd($aWin[$i][1]) Or WinGetProcess($aWin[$i][1]) <> @AutoItPID Then ContinueLoop
  WinSetOnTop($aWin[$i][1], "", 1)
  WinSetTitle($aWin[$i][1], "", $sFSFTitle)
  ;ControlSetText($aWin[$i][1], "", 14150, $sBtnFolder, 1) ;[CLASS:Button; INSTANCE:1] ;Make New Folder
  ControlSetText($aWin[$i][1], "", 1, $sBtnOK, 1);[CLASS:Button; INSTANCE:2] ;1 ;OK
  ControlSetText($aWin[$i][1], "", 2, $sBtnCANCEL, 1) ;[CLASS:Button; INSTANCE:3] ;2 ;CANCEL
  ControlSetText($aWin[$i][1], "", 14152, $sStc3Folder, 1) ;"[CLASS:Static; INSTANCE:3]" ;Folder
  DllCallbackFree($CallBack)
  $CallBack = 0
  DllCall("user32.dll", "int", "KillTimer", "hwnd", $hWnd, "uint_ptr", $iIDTimer)
  ExitLoop
Next
EndFunc
Edited by rover

I see fascists...

Share this post


Link to post
Share on other sites
Yashied

#Include <APIConstants.au3>
#Include <WinAPIEx.au3>

Opt('MustDeclareVars', 1)

Global Const $InitDir = @ProgramFilesDir

Global $hBrowseProc, $pBrowseProc, $tData, $Path

$hBrowseProc = DllCallbackRegister('_BrowseProc','int', 'hwnd;uint;long;ptr')
$pBrowseProc = DllCallbackGetPtr($hBrowseProc)

$Path = _WinAPI_BrowseForFolderDlg(_WinAPI_PathStripToRoot($InitDir), 'Select a folder from the list below.', BitOR($BIF_RETURNONLYFSDIRS, $BIF_EDITBOX, $BIF_VALIDATE), $pBrowseProc, _WinAPI_CreateString($InitDir, $tData))
If $Path Then
    ConsoleWrite('--------------------------------------------------' & @CR)
    ConsoleWrite($Path & @CR)
EndIf

DllCallbackFree($hBrowseProc)

Func _BrowseProc($hWnd, $iMsg, $wParam, $lParam)

    Local $Path

    Switch $iMsg
        Case $BFFM_INITIALIZED
            _SendMessage($hWnd, $BFFM_SETSELECTIONW, 1, $lParam)
            _WinAPI_SetWindowText($hWnd, 'My Title')
        Case $BFFM_SELCHANGED
            $Path = _WinAPI_ShellGetPathFromIDList($wParam)
            If Not @error Then
                ConsoleWrite($Path & @CR)
            EndIf
        Case $BFFM_VALIDATEFAILED
            MsgBox(16, 'Error', _WinAPI_GetString($wParam) & ' is invalid.', 0, $hWnd)
            Return 1
    EndSwitch
    Return 0
EndFunc ;==> _BrowseProc

Share this post


Link to post
Share on other sites
Syed23

Hi Yashield,

i am getting below error messages when i execute the above example. can you tell me where i can get the correct Include folders :graduated:

C:\Users\Q03200\Desktop\2.au3(28,52) : WARNING: $BFFM_SETSELECTIONW: possibly used before declaration.

_SendMessage($hWnd, $BFFM_SETSELECTIONW,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Users\Q03200\Desktop\2.au3(28,52) : ERROR: $BFFM_SETSELECTIONW: undeclared global variable.

_SendMessage($hWnd, $BFFM_SETSELECTIONW,

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Users\Q03200\Desktop\2.au3(14,221) : ERROR: _WinAPI_CreateString(): undefined function.

$Path = _WinAPI_BrowseForFolderDlg(_WinAPI_PathStripToRoot($InitDir), 'Select a folder from the list below.', BitOR($BIF_RETURNONLYFSDIRS, $BIF_EDITBOX, $BIF_VALIDATE), $pBrowseProc, _WinAPI_CreateString($InitDir, $tData)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\Users\Q03200\Desktop\2.au3(36,58) : ERROR: _WinAPI_GetString(): undefined function.

MsgBox(16, 'Error', _WinAPI_GetString($wParam)


Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Share this post


Link to post
Share on other sites
Yashied
levanduyet

Hi Happy in Moscow,

How about changing the caption of button "OK" or "Cancel"?

Tks,

LVD

Share this post


Link to post
Share on other sites
Yashied

Hi Member,

_WinAPI_SetWindowText(ControlGetHandle($hWnd, '', '[CLASS:Button;INSTANCE:1]'), ':-)')
_WinAPI_SetWindowText(ControlGetHandle($hWnd, '', '[CLASS:Button;INSTANCE:2]'), ':-(')
Edited by Yashied

Share this post


Link to post
Share on other sites
levanduyet

Hi Yashied,

How can I start with the folder: "My Computer"?

Tks,

LVD

Share this post


Link to post
Share on other sites
BrewManNH

How can I start with the folder: "My Computer"?

Tks,

Look in the Help file for AutoIt for "CLSIDs of Special Folders", the most common ones are in there.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
levanduyet

Look in the Help file for AutoIt for "CLSIDs of Special Folders", the most common ones are in there.

Hi,

I know this: FileSelectFolder("Xin chọn thư mục để cài đặt","::{20D04FE0-3AEA-1069-A2D8-08002B30309D}")

But I want to use the function of Yashied.

LVD

Share this post


Link to post
Share on other sites
Yashied

Use the following (I replace it in the next release).

Func _WinAPI_BrowseForFolderDlg($sRoot = '', $sText = '', $iFlags = 0, $pBrowseProc = 0, $lParam = 0, $hParent = 0)
 
    Local $tBROWSEINFO = DllStructCreate('hwnd;ptr;ptr;ptr;int;ptr;uint_ptr;int;wchar[' & (StringLen($sText) + 1) & '];wchar[260]')
    Local $PIDL = 0, $Path, $Result = ''
 
    $Path = _WinAPI_PathSearchAndQualify($sRoot, 1)
    If @error Then
        $Path = $sRoot
    EndIf
    $PIDL = _WinAPI_ShellILCreateFromPath($Path)
    If @error Then
        ; Nothing
    EndIf
 
    DllStructSetData($tBROWSEINFO, 1, $hParent)
    DllStructSetData($tBROWSEINFO, 2, $PIDL)
    DllStructSetData($tBROWSEINFO, 3, DllStructGetPtr($tBROWSEINFO, 10))
    DllStructSetData($tBROWSEINFO, 4, DllStructGetPtr($tBROWSEINFO, 9))
    DllStructSetData($tBROWSEINFO, 5, $iFlags)
    DllStructSetData($tBROWSEINFO, 6, $pBrowseProc)
    DllStructSetData($tBROWSEINFO, 7, $lParam)
    DllStructSetData($tBROWSEINFO, 8, 0)
    DllStructSetData($tBROWSEINFO, 9, $sText)
 
    Local $Ret = DllCall('shell32.dll', 'ptr', 'SHBrowseForFolderW', 'ptr', DllStructGetPtr($tBROWSEINFO))
 
    If @error Then
        Return SetError(1, 0, '')
    Else
        If Not $Ret[0] Then
            Return ''
        EndIf
    EndIf
    $Result = _WinAPI_ShellGetPathFromIDList($Ret[0])
    _WinAPI_CoTaskMemFree($Ret[0])
    If $PIDL Then
        _WinAPI_CoTaskMemFree($PIDL)
    EndIf
    If Not $Result Then
        Return SetError(1, 0, '')
    EndIf
    Return $Result
EndFunc   ;==>_WinAPI_BrowseForFolderDlg

And

$Path = _WinAPI_BrowseForFolderDlg('::{20D04FE0-3AEA-1069-A2D8-08002B30309D}', 'Select a folder from the list below.', BitOR($BIF_RETURNONLYFSDIRS, $BIF_EDITBOX, $BIF_VALIDATE), $pBrowseProc, _WinAPI_CreateString($InitDir, $tData))

Share this post


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
Sign in to follow this  

×