Modify

Opened 15 years ago

Closed 11 years ago

#1533 closed Feature Request (Rejected)

FileSaveDialog/FileOpenDialog return selected filter type

Reported by: anonymous Owned by: Jpm
Milestone: Component: AutoIt
Version: Severity: None
Keywords: Cc:

Description

As of now there is no way of telling what filter type was selected. I propose setting that information in the @extended macro.

example.

_Filesave()

Func _Filesave()
	Local $sFile, $sType

	$sFile = FileSaveDialog('Save file as...', @WorkingDir, "Text file (*.txt)|CSV file (*.csv)|HTML file (*.html)|Any files (*.*)")

	If Not @error Then

		; FileSaveDialog/FileOpenDialog could set @extended with the selected filter type index
		Switch @extended
			Case 0
				$sType = "Text file"
			Case 1
				$sType = "CSV file"
			Case 2
				$sType = "HTML file"
			Case 3
				$sType = "Any file"
		EndSwitch

		MsgBox(0, "You saved this file", "Filename: " & $sFile & @LF & "Type: " & $sType )


	EndIf
EndFunc

Attachments (0)

Change History (7)

comment:1 Changed 15 years ago by TicketCleanup

  • Version 3.3.6.0 deleted

Automatic ticket cleanup.

comment:2 Changed 15 years ago by MrCreatoR <mscreator@…>

Not sure if it helps, but here is a custom API function that can retrieve selected filter (among other extra options):

$sFileOpen = _FileOpenDialog("Open File", @ScriptDir, "All Files|*.*|Scripts|*.au3", 3, "ScriptName", "au3", 2)
If Not @error Then MsgBox(64, "Info", "Selected file: " & $sFileOpen & @CRLF & "Selected Filter: " & @extended)

Func _FileOpenDialog($sTitle, $sInitDir, $sFilter = 'All (*.*)|*.*', $iOpt = 0, $sDefFile = '', $sDefExt = '', $iDefFilter = 1, $hWnd = 0)
	Local $iFileLen = 65536 ; Max chars in returned string
	
	; API flags prepare
	Local $iFlag = BitOR( _
			BitShift(BitAND($iOpt, 1), -12), BitShift(BitAND($iOpt, 2), -10), BitShift(BitAND($iOpt, 4), -7), _
			BitShift(BitAND($iOpt, 8), -10), BitShift(BitAND($iOpt, 4), -17))
	
	; Filter string to array convertion
	If Not StringInStr($sFilter, '|') Then $sFilter &= '|*.*'
	$sFilter = StringRegExpReplace($sFilter, '|+', '|')
	
	Local $asFLines = StringSplit($sFilter, '|')
	Local $i, $suFilter = ''

	For $i = 1 To $asFLines[0] Step 2
		If $i < $asFLines[0] Then _
				$suFilter &= 'wchar[' & StringLen($asFLines[$i]) + 1 & '];wchar[' & StringLen($asFLines[$i + 1]) + 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;ptr;dword;dword')
	Local $usTitle = DllStructCreate('wchar[' & StringLen($sTitle) + 1 & ']')
	Local $usInitDir = DllStructCreate('wchar[' & StringLen($sInitDir) + 1 & ']')
	Local $usFilter = DllStructCreate($suFilter & 'wchar')
	Local $usFile = DllStructCreate('wchar[' & $iFileLen & ']')
	Local $usExtn = DllStructCreate('wchar[' & StringLen($sDefExt) + 1 & ']')
	
	For $i = 1 To $asFLines[0]
		DllStructSetData($usFilter, $i, $asFLines[$i])
	Next
	
	; Set Data of API structures
	DllStructSetData($usTitle, 1, $sTitle)
	DllStructSetData($usInitDir, 1, $sInitDir)
	DllStructSetData($usFile, 1, $sDefFile)
	DllStructSetData($usExtn, 1, $sDefExt)
	DllStructSetData($uOFN, 1, DllStructGetSize($uOFN))
	DllStructSetData($uOFN, 2, $hWnd)
	DllStructSetData($uOFN, 4, DllStructGetPtr($usFilter))
	DllStructSetData($uOFN, 7, $iDefFilter)
	DllStructSetData($uOFN, 8, DllStructGetPtr($usFile))
	DllStructSetData($uOFN, 9, $iFileLen)
	DllStructSetData($uOFN, 12, DllStructGetPtr($usInitDir))
	DllStructSetData($uOFN, 13, DllStructGetPtr($usTitle))
	DllStructSetData($uOFN, 14, $iFlag)
	DllStructSetData($uOFN, 17, DllStructGetPtr($usExtn))
	DllStructSetData($uOFN, 23, BitShift(BitAND($iOpt, 32), 5))
	
	; Call API function
	Local $aRet = DllCall('comdlg32.dll', 'int', 'GetOpenFileNameW', 'ptr', DllStructGetPtr($uOFN))
	If Not IsArray($aRet) Or Not $aRet[0] Then Return SetError(1, 0, "")
	
	If BitAND($iOpt, 4) Then
		$i = 1
		
		While 1
			If Binary(DllStructGetData($usFile, 1, $i)) = 0 Then
				If Binary(DllStructGetData($usFile, 1, $i + 1)) = 0 Then ExitLoop
				DllStructSetData($usFile, 1, '|', $i)
			EndIf
			
			$i += 1
		WEnd
	EndIf
	
	Local $sRet = StringStripWS(DllStructGetData($usFile, 1), 3)
	Return SetExtended(DllStructGetData($uOFN, 7), $sRet)
EndFunc

comment:3 Changed 15 years ago by Jpm

  • Milestone set to 3.3.7.0
  • Owner set to Jpm
  • Resolution set to Completed
  • Status changed from new to closed

Added by revision [5803] in version: 3.3.7.0

comment:4 Changed 13 years ago by MrCreatoR <mscreator@…>

Is this really completed?
In what version?

comment:5 Changed 13 years ago by Jpm

  • Resolution Completed deleted
  • Status changed from closed to reopened

Jon revert what I did without reopening the ticket

comment:6 Changed 13 years ago by TicketCleanup

  • Milestone 3.3.7.0 deleted

Automatic ticket cleanup.

comment:7 Changed 11 years ago by Jon

  • Resolution set to Rejected
  • Status changed from reopened to closed

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The owner will remain Jpm.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.