Jump to content

save file from FileSaveDialog problems


glarson
 Share

Recommended Posts

I can't figure out how to save a *.ini file using _FileSaveDialog. It will not save the file with the name I type in the dialog box. What am I missing?

CODE
Func SaveProfile()

$MouseSpeed=10

$title = "Save"

$initialdir = $ProfileFolder

$filter = "Ini (*.ini)"

$iOption = 1 + 2 +16; verifies file existance, popup messagebox if filename entered doesn't exist

$userdat ="Default"; default initial filename (or none) for dialog input

$parentgui = 0 ; or Hwnd returned from GuiCreate

$file=_FileSaveDialog($title, $initialdir, $filter, $iOption, $userdat, "", $parentgui)

IniWrite($ProfileFolder&"\"&$file,"Profile","Name",$MouseSpeed)

EndFunc

Func _FileSaveDialog($sTitle, $sInitDir, $sFilter = "All (*.*)", $iOpt = 0, $sDefaultFile = "", $sDefaultExt = "", $hWnd = 0)

; API flags prepare

Local $iFlag = BitOR( _

BitShift(BitAND($iOpt, 2), -10), _

BitShift(BitAND($iOpt,16), 3 ) _

)

; Call API function

Local $usPath = __FileOSDialogHelper("GetSaveFileName", $iFlag, $sTitle, $sInitDir, $sFilter, $iOpt, $sDefaultFile, $sDefaultExt, $hWnd)

If Not @error Then Return DllStructGetData($usPath, 1)

Return SetError(1, 0, "")

EndFunc

Func __FileOSDialogHelper($sFunction, $iFlag, $sTitle, $sInitDir, $sFilter, $iOpt, $sDefaultFile, $sDefaultExt, $hWnd)

Local $iPathLen = 256 ; Max chars in returned string

; Filter string to array conversion

Local $asFLines = StringSplit($sFilter, "|"), $asFilter[$asFLines[0]*2+1]

Local $i, $iStart, $iFinal, $suFilter

$asFilter[0] = $asFLines[0]*2

For $i = 1 To $asFLines[0]

$iStart = StringInStr($asFLines[$i], "(", 0, 1)

$iFinal = StringInStr($asFLines[$i], ")", 0,-1)

$asFilter[$i*2-1] = StringStripWS(StringLeft($asFLines[$i], $iStart-1), 3)

$asFilter[$i*2] = StringStripWS(StringTrimRight(StringTrimLeft($asFLines[$i], $iStart), StringLen($asFLines[$i]) -$iFinal+1), 3)

$suFilter &= "char[" & StringLen($asFilter[$i*2-1])+1 & "];char[" & StringLen($asFilter[$i*2])+1 & "];"

Next

; Create API structures

Local $uOFN = DllStructCreate("dword;int;int;ptr;ptr;dword;dword;ptr;dword;ptr;int;ptr;ptr;dword;short;short;ptr;ptr;ptr;ptr;p

tr;dword;dword")

Local $usTitle = DllStructCreate("char[" & StringLen($sTitle)+1 & "]")

Local $usInitDir = DllStructCreate("char[" & StringLen($sInitDir)+1 & "]")

Local $usFilter = DllStructCreate($suFilter & "char")

Local $usPath = DllStructCreate("char[" & $iPathLen & "]")

Local $usExtn = DllStructCreate("char[" & StringLen($sDefaultExt)+1 & "]")

For $i=1 To $asFilter[0]

DllStructSetData($usFilter, $i, $asFilter[$i])

Next

; Set Data of API structures

DllStructSetData($usTitle, 1, $sTitle)

DllStructSetData($usInitDir, 1, $sInitDir)

DllStructSetData($usPath, 1, $sDefaultFile)

DllStructSetData($usExtn, 1, $sDefaultExt)

DllStructSetData($uOFN, 1, DllStructGetSize($uOFN))

DllStructSetData($uOFN, 2, $hWnd)

DllStructSetData($uOFN, 4, DllStructGetPtr($usFilter))

DllStructSetData($uOFN, 7, 1)

DllStructSetData($uOFN, 8, DllStructGetPtr($usPath))

DllStructSetData($uOFN, 9, $iPathLen)

DllStructSetData($uOFN, 12, DllStructGetPtr($usInitDir))

DllStructSetData($uOFN, 13, DllStructGetPtr($usTitle))

DllStructSetData($uOFN, 14, BitOR($iFlag, 4))

DllStructSetData($uOFN, 17, DllStructGetPtr($usExtn))

DllStructSetData($uOFN, 23, BitShift(BitAND($iOpt, 32), 5))

; Call API function

Local $aiCall = DllCall("comdlg32.dll", "int", $sFunction, "ptr", DllStructGetPtr($uOFN))

If $aiCall[0] Then Return $usPath

Return SetError(1, 0, "")

EndFunc

Link to comment
Share on other sites

What am I missing?

Maby the part where the function is actualy called?

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: 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 Program

AutoIt_Icon_small.pngUDFs: 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
 
AutoIt_Icon_small.pngExamples: 
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 AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

So... what's the problem with the regular built-in FileSaveDialog? This works fine:

SaveProfile()

Func SaveProfile()
    $MouseSpeed = 10
    $title = "Save" 
    $initialdir = @UserProfileDir
    $filter = "Ini (*.ini)" 
    $iOption = 1 + 2 + 16; verifies file existance, popup messagebox if filename entered doesn't exist
    $userdat = "Default.ini"  ; default initial filename (or none) for dialog input
    $parentgui = 0 ; or Hwnd returned from GuiCreate
    $file = FileSaveDialog($title, $initialdir, $filter, $iOption, $userdat)
    IniWrite($file, "Profile", "Name", $MouseSpeed)
EndFunc   ;==>SaveProfile

<_<

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Try this:

Func SaveProfile()
    $MouseSpeed=10
    $title = "Save"
    $initialdir = $ProfileFolder
    $filter = "Ini (*.ini)"
    $iOption = 1 + 2 +16; verifies file existance, popup messagebox if filename entered doesn't exist
    $userdat ="Default"; default initial filename (or none) for dialog input
    $parentgui = 0 ; or Hwnd returned from GuiCreate
    $file = _FileSaveDialog($title, $initialdir, $filter, $iOption, $userdat, "", $parentgui)
    IniWrite($file,"Profile","Name",$MouseSpeed)
EndFunc

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: 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 Program

AutoIt_Icon_small.pngUDFs: 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
 
AutoIt_Icon_small.pngExamples: 
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 AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

what's the problem with the regular built-in FileSaveDialog?

As i understand, he need the $parentgui param <_<

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: 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 Program

AutoIt_Icon_small.pngUDFs: 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
 
AutoIt_Icon_small.pngExamples: 
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 AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Try this:

Func SaveProfile()
    $MouseSpeed=10
    $title = "Save"
    $initialdir = $ProfileFolder
    $filter = "Ini (*.ini)"
    $iOption = 1 + 2 +16; verifies file existance, popup messagebox if filename entered doesn't exist
    $userdat ="Default"; default initial filename (or none) for dialog input
    $parentgui = 0 ; or Hwnd returned from GuiCreate
    $file = _FileSaveDialog($title, $initialdir, $filter, $iOption, $userdat, "", $parentgui)
    IniWrite($file,"Profile","Name",$MouseSpeed)
EndFunc
Thanks, that worked.
Link to comment
Share on other sites

OK, new problem?!?!? When I save the ini file as 'default' it saves as an .ini file but when I change the name it saves as something else. When I open this 'other' file with notepad it is formatted as an .ini file but it is not reconized as one. What am I missing???

here is the code.

CODE
Func SelectFileFolderEVE()

$EVEFolder=FileSelectFolder("EVE Folder Path","",1+2+4)

GUICtrlSetData($EveGUI_EVEPath,$EVEFolder)

EndFunc

Func SelectFileFolderSave()

$ProfileFolder=FileSelectFolder("Save Profile Path","",1+2+4)

GUICtrlSetData($EveGUI_ProfileSavePath,$ProfileFolder)

EndFunc

Func OpenProfile()

$title1 = "Open"

$initialdir1 = $ProfileFolder

$filter1 = "ini (*.ini)"

$iOption1 = 1 + 2 + 16; verifies file existance, popup messagebox if filename entered doesn't exist

$userdat1 = "Default.ini" ; default initial filename (or none) for dialog input

$parentgui1 = 0 ; or Hwnd returned from GuiCreate

$file=FileOpenDialog($title1, $initialdir1, $filter1, $iOption1, $userdat1);, "", $parentgui1)

GUICtrlSetData($EveGUI_MouseSpeed,IniRead($file,"Main","Mouse",""))

GUICtrlSetData($EveGUI_ProfileSavePath,IniRead($file,"Main","Save",""))

GUICtrlSetData($EveGUI_EVEPath,IniRead($file,"Main","EVE",""))

EndFunc

Func SaveProfile()

$title = "Save"

$initialdir = $ProfileFolder

$filter = "ini (*.ini)"

$iOption = 1 + 2 +16; verifies file existance, popup messagebox if filename entered doesn't exist

$userdat ="Default.ini"; default initial filename (or none) for dialog input

$parentgui = 0 ; or Hwnd returned from GuiCreate

$file=FileSaveDialog($title, $initialdir, $filter, $iOption, $userdat);, "", $parentgui)

IniWrite($file,"Main","Mouse",$MouseSpeed);need to add all of the gUI variables to .ini file except login info

IniWrite($file,"Main","Save",$ProfileFolder)

IniWrite($file,"Main","EVE",$EVEFolder)

EndFunc

These functions are called for through a GUI.

MSCreatoR your right, the filesavedialog and fileopendialog work just fine!!! I got those other functions from this forum:D

Edited by glarson
Link to comment
Share on other sites

but when I change the name it saves as something else

It's a known issue (it's returned without file extension), you will have to use the custom function (from the link i gave), or you need to check the returned value, like this:

Func SaveProfile()
    $title = "Save"
    $initialdir = $ProfileFolder
    $filter = "ini (*.ini)"
    $iOption = 1 + 2 +16; verifies file existance, popup messagebox if filename entered doesn't exist
    $userdat ="Default.ini"; default initial filename (or none) for dialog input
    $parentgui = 0 ; or Hwnd returned from GuiCreate
    $file=FileSaveDialog($title, $initialdir, $filter, $iOption, $userdat);, "", $parentgui)
    If StringRight($file, 4) <> ".ini" Then $file &= ".ini"
    IniWrite($file,"Main","Mouse",$MouseSpeed);need to add all of the gUI variables to .ini file except login info
    IniWrite($file,"Main","Save",$ProfileFolder)
    IniWrite($file,"Main","EVE",$EVEFolder)
EndFunc

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: 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 Program

AutoIt_Icon_small.pngUDFs: 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
 
AutoIt_Icon_small.pngExamples: 
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 AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

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...