|
-
Sep 25th, 2009, 05:00 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] Return Selected Filter with GetSaveFileName API
Ok, I have a File Save dialog for a while, through the GetSaveFileName API.
However, now I need to determine which Filter the user has selected.
i.e .jpeg, .bmp, .gif etc...
Code:
Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameW" (pOpenfilename As OPENFILENAME) As Long
Private Type OPENFILENAME
lStructSize As Long 'Length of structure, in bytes
hWndOwner As Long 'Window that owns the dialog, or NULL
hInstance As Long 'Handle of mem object containing template (not used)
lpstrFilter As Long 'File types/descriptions, delimited with vbnullchar, ends with 2xvbnullchar
lpstrCustomFilter As Long 'Filters typed in by user
nMaxCustFilter As Long 'Length of CustomFilter, min 40x chars
nFilterIndex As Long 'Filter Index to use (1,2,etc) or 0 for custom
lpstrFile As Long 'Initial file/returned file(s), delimited with vbnullchar for multi files
nMaxFile As Long 'Size of Initial File long , min 256
lpstrFileTitle As Long 'File.ext excluding path
nMaxFileTitle As Long 'Length of FileTitle
lpstrInitialDir As Long 'Initial file dir, null for current dir
lpstrTitle As Long 'Title bar of dialog
flags As Long 'See OFN_Flags
nFileOffset As Integer 'Offset to file name in full path, 0-based
nFileExtension As Integer 'Offset to file ext in full path, 0-based (excl '.')
lpstrDefExt As Long 'Default ext appended, excl '.', max 3 chars
lCustData As Long 'Appl defined data for lpfnHook
lpfnHook As Long 'Pointer to hook procedure
lpTemplateName As Long 'Template Name (not used)
pvReserved As Long 'new Win2000 / WinXP members
dwReserved As Long 'new Win2000 / WinXP members
FlagsEx As Long 'new Win2000 / WinXP members
End Type
Public Function cFileSave(ByVal InitialDir As String, _
ByVal DialogTitle As String, ByVal Filter As String, _
ByVal FrmhWnd As Long, Optional FileTitle As String = vbNullString, _
Optional ByRef rtnFilter As Long) As String
Dim OpenFile As OPENFILENAME
Dim lReturn As Long
Dim FileFilter As String
Dim strFile As String
strFile = String$(512, 0)
If Not FileTitle = vbNullString Then
strFile = FileTitle & strFile
End If
OpenFile.lStructSize = Len(OpenFile)
OpenFile.hWndOwner = FrmhWnd
OpenFile.hInstance = App.hInstance
FileFilter = Replace$(Filter, "|", vbNullChar)
If AscW(Right$(FileFilter, 1)) <> 0& Then FileFilter = FileFilter & vbNullChar
OpenFile.lpstrFilter = StrPtr(FileFilter)
OpenFile.nFilterIndex = 1
OpenFile.lpstrFile = StrPtr(strFile)
OpenFile.nMaxFile = Len(strFile) - 1
OpenFile.lpstrFileTitle = StrPtr(OpenFile.lpstrFile)
OpenFile.nMaxFileTitle = StrPtr(OpenFile.nMaxFile)
OpenFile.lpstrInitialDir = StrPtr(InitialDir)
OpenFile.lpstrTitle = StrPtr(DialogTitle)
OpenFile.flags = 0
lReturn = GetSaveFileName(OpenFile)
If lReturn = 0 Then
'Cancel Button Pressed
Else
cFileSave = Left$(strFile, InStr(strFile, vbNullChar) - 1)
rtnFilter = OpenFile.lpstrFile
End If
End Function
Currently it returns a LONG number,
How do i convert this to the relevant String format ?
_____________________________________________________________________
----If this post has helped you. Please take time to Rate it.
----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.

Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|