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 oldFileName, Title, InitialDir, DefaultExt As WString * %Max_Path
Local Filter as WString, ofn As OPENFILENAME
'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"
DefaultExt = "bas"
'set OFN structure
ofn.hwndOwner = hDlg
ofn.lStructSize = SizeOf(ofn)
ofn.nMaxFile = SizeOf(FileName)
ofn.lpstrTitle = VarPtr(Title)
ofn.lpstrFile = VarPtr(FileName)
ofn.lpstrInitialDir = VarPtr(InitialDir)
ofn.lpstrFilter = StrPtr(Filter)
ofn.lpstrDefExt = VarPtr(DefaultExt)
ofn.Flags = %OFN_Explorer Or %OFN_PathMustExist Or %OFN_OverWritePrompt Or %OFN_HideReadOnly
GetSaveFilename(ofn)
If FileName <> oldFileName Then Function = FileName 'return valid filename or empty string
End Function
'gbs_01442
'Date: 10-17-2014
http://www.garybeene.com/sw/gbsnippets.htm