Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile Exe
#Dim All
%Unicode = 1
#Include "Win32API.inc"
Enum Equates Singular
IDC_Button
End Enum
Global hDlg As Dword, NewName, FileName As WStringZ * %Max_Path
Function PBMain() As Long
Dialog New Pixels, 0, "SDK SaveAs",300,300,200,200, %WS_OverlappedWindow To hDlg
Control Add Button, hDlg, %IDC_Button,"Save As", 50,10,100,20
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Select Case Cb.Msg
Case %WM_InitDialog
FileName = Exe.Path$ + "test.bas"
Case %WM_Command
Select Case Cb.Ctl
Case %IDC_Button
NewName = SaveAsDialog(FileName) 'returns new file name or empty string
If Len(NewName) Then FileName = NewName 'use the new file name
? FileName 'will be the same file name, or a new file name
End Select
End Select
End Function
Function SaveAsDialog (ByVal FileName As WStringZ * %Max_Path) As WString
Local Title, oldFileName, InitialDir, Filter, DefaultExt As WStringZ * %Max_Path, ofn As OPENFILENAMEW
Local wFilter As WString * %Max_Path
'values to use in dialog
Title = "Save As"
oldFileName = FileName
InitialDir = IIf$(IsFile(FileName), PathName$(Path,FileName), CurDir$) 'folder containing file or current directory
Filter = "Source Code (*.bas)" + $Nul + "*.bas" + $Nul + $Nul
wFilter = "Source Code (*.bas)" + $Nul + "*.bas" + $Nul + $Nul
DefaultExt = "bas"
'set OFN structure
ofn.hwndOwner = hDlg
ofn.lStructSize = SizeOf(ofn)
ofn.nMaxFile = SizeOf(FileName)
ofn.nFilterIndex = 1
ofn.lpstrTitle = VarPtr(Title)
ofn.lpstrFile = VarPtr(FileName)
ofn.lpstrInitialDir = VarPtr(InitialDir)
' ofn.lpstrFilter = VarPtr(Filter)
ofn.lpstrFilter = VarPtr(wFilter)
ofn.lpstrDefExt = VarPtr(DefaultExt)
ofn.Flags = %OFN_Explorer Or %OFN_PathMustExist Or %OFN_OverWritePrompt Or %OFN_HideReadOnly
GetSaveFilenameW(ofn)
If FileName <> oldFileName Then Function = FileName 'return valid filename or empty string
End Function
' lpstrTitle As WStringZ Ptr ' LPCWSTR lpstrTitle
' lpstrFile As WStringZ Ptr ' LPWSTR lpstrFile
' lpstrInitialDir As WStringZ Ptr ' LPCWSTR lpstrInitialDir
' lpstrFilter As WStringZ Ptr ' LPCWSTR lpstrFilter
' lpstrDefExt As WStringZ Ptr ' LPCWSTR lpstrDefExt
' bstrFilter += "CSED Project Files (*.sed)" + $Nul + "*.sed" + $Nul + $Nul
' bstrDefExt = "sed"
'gbs_01443
'Date: 10-17-2014
http://www.garybeene.com/sw/gbsnippets.htm