Sign in to follow this  
Followers 0
Undutchable

FileSaveDialog default name read-only?

14 posts in this topic

Hello,

In FileSaveDialog, is there a way to prevent editing of the default file name that I sugest?

Probably been answered before but my search reveals nothing.

thanks!

Share this post


Link to post
Share on other sites



You could try to get the controlid of the inputbox and use stringtrimleft to check it.


The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Share this post


Link to post
Share on other sites

Hello,

In FileSaveDialog, is there a way to prevent editing of the default file name that I sugest?

Probably been answered before but my search reveals nothing.

thanks!

If you don't want the user to enter a file name, but just select the location to save the file then why not use FileSelectFolder instead.

Alternatively replace the returned file name with the one you suggested if it has been changed.


"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

Hello,

In FileSaveDialog, is there a way to prevent editing of the default file name that I sugest?

Probably been answered before but my search reveals nothing.

thanks!

If you want to enforce the name of the target file the traditional way is to use FileSelectFolder(). I don't like it either but for some reason they coded the File Save Dialog to discourage subclassing it. That folder select thing has to be the lamest but I've seen no good free replacements around.

Share this post


Link to post
Share on other sites

Yeah, I didn't want to use the FileSelectFolder because I believe it doesn't show me the files present in the folder and also, reading the helpfile, it says UNC paths are not supported.

I guess the only way is like Bowmore mentioned: Replace the name no matter what the user inputed.

Thanks guys!

Share this post


Link to post
Share on other sites

If you just changed the path returned by filesavedialog it could get very confusing for the user. They might decide to save something as C:\something.txt and instead see C:\somethingelse.txt and wonder what the heck happened.


The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Share this post


Link to post
Share on other sites

Correct Hawkwing..thought about that..

but in this case it's more important for me to keep the name i sugested (has a date algorithm)

Until something better comes up, it will have to do >_<

Cheers

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Kludgy workaround, but it does the trick:

$fileSave = _FileSaveDialogRO("Save File As", @TempDir, "All files (*.*)", 2, "ReadOnlyFileName.txt")
ConsoleWrite($fileSave & @CRLF)



Func _FileSaveDialogRO($sFileSaveDialogName, $sInitDir, $sFilter, $iOptions = 0, $sDefaultName = "", $hwndParent = 0)
    Local $sfnFSHelper = @TempDir & "\roFShelper.au3"
    Local $fhRoFShelper = FileOpen($sfnFSHelper, 2)
    FileWriteLine($fhRoFShelper, 'WinWait("' & $sFileSaveDialogName & '")')
    FileWriteLine($fhRoFShelper, '$hEdit = ControlGetHandle("' & $sFileSaveDialogName & '","","[CLASS:Edit; INSTANCE:1]")')
    FileWriteLine($fhRoFShelper, 'While WinExists("' & $sFileSaveDialogName & '")')
    FileWriteLine($fhRoFShelper, '$sFileName = ControlGetText("' & $sFileSaveDialogName & '","",$hEdit)')
    FileWriteLine($fhRoFShelper, 'If $sFileName <> "' & $sDefaultName & '" then')
    FileWriteLine($fhRoFShelper, 'ControlSetText("' & $sFileSaveDialogName & '","",$hEdit,"' & $sDefaultName & '")')
    FileWriteLine($fhRoFShelper, 'ControlSend("' & $sFileSaveDialogName & '","",$hEdit,"{END}")')
    FileWriteLine($fhRoFShelper, 'EndIf')
    FileWriteLine($fhRoFShelper, 'WEnd')
    FileWriteLine($fhRoFShelper, 'Exit')
    FileClose($fhRoFShelper)
    Run(@AutoItExe & ' /AutoIt3ExecuteScript ' & $sfnFSHelper)
    $fileSave = FileSaveDialog($sFileSaveDialogName, $sInitDir, "(" & $sDefaultName & ")", $iOptions, $sDefaultName, $hwndParent)
    Return $fileSave
EndFunc   ;==>_FileSaveDialogRO

Edit: Fixed extraneous edit control references

Edit2: Fixed call in function to actually use the parameter variables by name instead of the hard coded parameters I'd left in

Edit3: Forced the filter parameter in the function's call to FileSaveDialog() to be the same as your read only filename. This prevents the user from seeing and double-clicking on another file in the dialog box and having that returned as the filename.

Edited by ResNullius

Share this post


Link to post
Share on other sites

Kludgy workaround, but it does the trick:

Wow! That's pretty dang clever.. I have a couple of ideas brewing about how to use that idea, if you don't mind me using your code? (with credit, of course).

If you don't mind me asking, is there any way to adapt this method so that I can type in something like c:\drivers, and it returns c:\drivers\myfile.txt?

(Not asking for much, am I?! Just basically completely moving the goalposts!! [cough])

Regards,

Gerard

Share this post


Link to post
Share on other sites

Wow! That's pretty dang clever.. I have a couple of ideas brewing about how to use that idea, if you don't mind me using your code? (with credit, of course).

Go ahead and use the code, that's what it's here for.

Note that I just now edited the function to make use of the proper variables for the parameters in the function and not the hard coded parameters I had.

Not sure what your asking about with

If you don't mind me asking, is there any way to adapt this method so that I can type in something like c:\drivers, and it returns c:\drivers\myfile.txt?

Are you looking for some kind of auto completion? The whole idea behind the code above and the original idea is that you know what file/folder you're specifying ahead of time :D

Share this post


Link to post
Share on other sites

Go ahead and use the code, that's what it's here for.

...

Are you looking for some kind of auto completion? The whole idea behind the code above and the original idea is that you know what file/folder you're specifying ahead of time :D

Thanks for allowing the use of your code - much appreciated.

I'll try to explain what I'm looking for.

I'm looking for a way where I can select a FOLDER without using the inbuilt folder dialog box, as it's dreadfully limited under WinPE.

So I was hoping I could just type in C:\Drivers in the fileopen dialog and it would know that I mean the folder c:\drivers.

Using your code, I can browse to C:\drivers and it'll return c:\drivers\[fixed filename from script], so extracting the c:\drivers bit is easy.

However because the filename part is locked, I can only use the browse while I'd like to be able to type in the filename part of the dialog.

Hope that makes sense.

I'm fully aware I'm asking for a Porsche here! :D

Regards,

Gerard

Share this post


Link to post
Share on other sites

Thanks for allowing the use of your code - much appreciated.

I'll try to explain what I'm looking for.

I'm looking for a way where I can select a FOLDER without using the inbuilt folder dialog box, as it's dreadfully limited under WinPE.

So I was hoping I could just type in C:\Drivers in the fileopen dialog and it would know that I mean the folder c:\drivers.

Using your code, I can browse to C:\drivers and it'll return c:\drivers\[fixed filename from script], so extracting the c:\drivers bit is easy.

However because the filename part is locked, I can only use the browse while I'd like to be able to type in the filename part of the dialog.

Hope that makes sense.

I'm fully aware I'm asking for a Porsche here! :)

Regards,

Gerard

Sorry for the late reply to this, but if you're still interested, I think I have the keys to your Porsche :)

$fileSave = _FileSaveDialogROFileName("Save File As", @TempDir, "All files (*.*)", 2, "ReadOnlyFileName.txt")

Func _FileSaveDialogROFileName($sFileSaveDialogName, $sInitDir, $sFilter, $iOptions = 0, $sDefaultName = "", $hwndParent = 0)
  Local $sfnFSHelper = @TempDir & "\roFShelper.au3"
  Local $fhRoFShelper = FileOpen($sfnFSHelper, 2)
  FileWriteLine($fhRoFShelper, 'Global Const $EM_GETSEL = 0xB0')
  FileWriteLine($fhRoFShelper, 'Global Const $EM_SETSEL = 0xB1')
  FileWriteLine($fhRoFShelper, '$sFileName = "ReadOnlyFileName.txt"')
  FileWriteLine($fhRoFShelper, '$iFileNameLen = StringLen($sFileName)')
  FileWriteLine($fhRoFShelper, '')
  FileWriteLine($fhRoFShelper, 'WinWait("' & $sFileSaveDialogName & '")')
  FileWriteLine($fhRoFShelper, '$hEdit = ControlGetHandle("' & $sFileSaveDialogName & '", "", "[CLASS:Edit; INSTANCE:1]")')
  FileWriteLine($fhRoFShelper, '$sOldText = ControlGetText("' & $sFileSaveDialogName & '", "", $hEdit)')
  FileWriteLine($fhRoFShelper, '')
  FileWriteLine($fhRoFShelper, 'While WinExists("' & $sFileSaveDialogName & '")')
  FileWriteLine($fhRoFShelper, '    $sNewText = ControlGetText("' & $sFileSaveDialogName & '", "", $hEdit)')
  FileWriteLine($fhRoFShelper, '  If $sNewText <> $sOldText Then')
  FileWriteLine($fhRoFShelper, '        $aPos = _GUICtrlEdit_GetSel($hEdit)')
  FileWriteLine($fhRoFShelper, '        If StringLen($sNewText) < $iFileNameLen Then $sNewText = "' & $sDefaultName & '"')
  FileWriteLine($fhRoFShelper, '        IF $aPos[1] = StringLen($sNewText) OR NOT StringInStr($sNewText, "' & $sDefaultName & '") Then')
  FileWriteLine($fhRoFShelper, '            $sNewText = $sOldText')
  FileWriteLine($fhRoFShelper, '        Else')
  FileWriteLine($fhRoFShelper, '            $sNewText = StringMid($sNewText, 1, StringInStr($sNewText, "' & $sDefaultName & '") - 1) & "' & $sDefaultName & '"')
  FileWriteLine($fhRoFShelper, '        EndIf')
  FileWriteLine($fhRoFShelper, '    ControlSetText("' & $sFileSaveDialogName & '", "", $hEdit, $sNewText)')
  FileWriteLine($fhRoFShelper, '    $sOldText = ControlGetText("' & $sFileSaveDialogName & '", "", $hEdit)')
  FileWriteLine($fhRoFShelper, '    _GUICtrlEdit_SetSel($hEdit, $aPos[0], $aPos[1])')
  FileWriteLine($fhRoFShelper, '    EndIf')
  FileWriteLine($fhRoFShelper, 'Sleep(10)')
  FileWriteLine($fhRoFShelper, 'WEnd')
  FileWriteLine($fhRoFShelper, '')
  FileWriteLine($fhRoFShelper, '; #FUNCTION# ====================================================================================================================')
  FileWriteLine($fhRoFShelper, '; Name...........: _GUICtrlEdit_GetSel')
  FileWriteLine($fhRoFShelper, '; Author ........: Gary Frost (gafrost)')
  FileWriteLine($fhRoFShelper, '; ===============================================================================================================================')
  FileWriteLine($fhRoFShelper, 'Func _GUICtrlEdit_GetSel($hWnd)')
  FileWriteLine($fhRoFShelper, 'If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)')
  FileWriteLine($fhRoFShelper, 'Local $aSel[2], $wparam, $lparam')
  FileWriteLine($fhRoFShelper, '    $wparam = DllStructCreate("int Start")')
  FileWriteLine($fhRoFShelper, '    $lparam = DllStructCreate("int End")')
  FileWriteLine($fhRoFShelper, '_SendMessage($hWnd, $EM_GETSEL, DllStructGetPtr($wparam), DllStructGetPtr($lparam), 0, "ptr", "ptr")')
  FileWriteLine($fhRoFShelper, '$aSel[0] = DllStructGetData($wparam, "Start")')
  FileWriteLine($fhRoFShelper, '    $aSel[1] = DllStructGetData($lparam, "End")')
  FileWriteLine($fhRoFShelper, '    Return $aSel')
  FileWriteLine($fhRoFShelper, 'EndFunc   ;==>_GUICtrlEdit_GetSel')
  FileWriteLine($fhRoFShelper, '')
  FileWriteLine($fhRoFShelper, '; #FUNCTION# ====================================================================================================================')
  FileWriteLine($fhRoFShelper, '; Name...........: _GUICtrlEdit_SetSel')
  FileWriteLine($fhRoFShelper, '; Author ........: Gary Frost (gafrost)')
  FileWriteLine($fhRoFShelper, '; ===============================================================================================================================')
  FileWriteLine($fhRoFShelper, 'Func _GUICtrlEdit_SetSel($hWnd, $iStart, $iEnd)')
  FileWriteLine($fhRoFShelper, 'If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)')
  FileWriteLine($fhRoFShelper, '    _SendMessage($hWnd, $EM_SETSEL, $iStart, $iEnd)')
  FileWriteLine($fhRoFShelper, 'EndFunc   ;==>_GUICtrlEdit_SetSel')
  FileWriteLine($fhRoFShelper, '')
  FileWriteLine($fhRoFShelper, '; #FUNCTION# ====================================================================================================================')
  FileWriteLine($fhRoFShelper, '; Name...........: _SendMessage')
  FileWriteLine($fhRoFShelper, '; Author ........: Valik')
  FileWriteLine($fhRoFShelper, '; Modified.......: Gary Frost (GaryFrost) aka gafrost')
  FileWriteLine($fhRoFShelper, '; ===============================================================================================================================')
  FileWriteLine($fhRoFShelper, 'Func _SendMessage($hWnd, $iMsg, $wParam = 0, $lParam = 0, $iReturn = 0, $wParamType = "wparam", $lParamType = "lparam", $sReturnType = "lparam")')
  FileWriteLine($fhRoFShelper, 'Local $aResult = DllCall("user32.dll", $sReturnType, "SendMessage", "hwnd", $hWnd, "int", $iMsg, $wParamType, $wParam, $lParamType, $lParam)')
  FileWriteLine($fhRoFShelper, 'If @error Then Return SetError(@error, @extended, "")')
  FileWriteLine($fhRoFShelper, '    If $iReturn >= 0 And $iReturn <= 4 Then Return $aResult[$iReturn]')
  FileWriteLine($fhRoFShelper, '    Return $aResult')
  FileWriteLine($fhRoFShelper, 'EndFunc   ;==>_SendMessage')
  FileClose($fhRoFShelper)

  Run(@AutoItExe & ' /AutoIt3ExecuteScript ' & $sfnFSHelper)
  $fileSave = FileSaveDialog($sFileSaveDialogName, $sInitDir, "(" & $sDefaultName & ")", $iOptions, $sDefaultName, $hwndParent)
  Return $fileSave
EndFunc   ;==>_FileSaveDialogROFileName

The only thing I haven't been able to test is if the _GUICtrlEdit_GetSel & _GUICtrlEdit_SetSel work under PE.

Note: I've ripped those functions and the _SendMessage straight out of the standard AutoIt UDFs.

Share this post


Link to post
Share on other sites

Sorry for the late reply to this, but if you're still interested, I think I have the keys to your Porsche :)

At the risk of sounding dim/rude/both, this appears to do the same as the first version where the filename is locked.

I can type in it, and the cursor moves however it still just returns the %TEMP%\Readonlyfilename.txt (I mean %temp% is the fully expanded path, like c:\documents and settings\blah blah\temp).

Like I said - I don't mean to sound ungrateful here - simply providing the results of my test :)

Thanks lots for trying this - it's very much appreciated.

Kind regards,

Gerard

Share this post


Link to post
Share on other sites

At the risk of sounding dim/rude/both, this appears to do the same as the first version where the filename is locked.

I can type in it, and the cursor moves however it still just returns the %TEMP%\Readonlyfilename.txt (I mean %temp% is the fully expanded path, like c:\documents and settings\blah blah\temp).

Like I said - I don't mean to sound ungrateful here - simply providing the results of my test :)

Thanks lots for trying this - it's very much appreciated.

Kind regards,

Gerard

So, what you want is for the file dialog to only return the folder name????

That is, you want to emulate the behaviour of FileSelectFolder( ) but using FileSaveDialog( )?

Or am i being dim?

Describe for me:

  • what, if anything, you want pre-typed in the dialog
  • whether or not it should be editable (or read only)
  • what you want returned from the dialog

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  
Followers 0