Using Common Dialogs
XEditor uses all the common dialogs except Find and Replace (for reasons I’ll get to later). Let’s look at the ones implemented in the COMDLG module and called by XEditor in EDITOR.CLS:
-
The FileOpen method calls VBGetOpenFileName, which calls
Windows GetOpenFileName.
-
The FileSaveAs method calls VBGetSaveFileName, which calls
Windows GetSaveFileName.
-
The FilePrint method calls VBPrintDlg, which calls Windows PrintDlg.
-
The FilePageSetup method calls VBPageSetupDlg, which calls
Windows PageSetupDlg.
-
The OptionFont method calls VBChooseFont, which calls Windows ChooseFont.
-
The OptionColor method calls VBChooseColor, which calls Windows ChooseColor.
If you’ve seen one common dialog function, you’ve seen them all, so let’s go through the process for the most common and most complicated function—the Open dialog box. The Save As dialog box is almost identical, and the Font and Color dialog boxes are simple by comparison. The Print and Page Setup dialog boxes are a little different, but I won’t get into the details.
It all starts with the mnuFileOpen_Click event:
Private Sub mnuFileOpen_Click()
If edit.DirtyDialog Then edit.FileOpen
dropFile.Text = edit.filename
SetTextMode edit.TextMode
End Sub
After checking that the current file is saved, call the FileOpen method of the XEditor object. FileOpen in turn calls VBGetOpenFileName:
Function FileOpen() As Boolean
Dim f As Boolean, sFile As String, fReadOnly As Boolean
f = VBGetOpenFileName( _
FileName:=sFile, _
ReadOnly:=fReadOnly, _
Filter:=FilterString, _
Owner:=hWnd)
If f And sFile <> sEmpty Then
TextMode = Not IsRTF(sFile)
LoadFile sFile
If fReadOnly Then Locked = True
FileOpen = True
End If
End Function
In any case, pass whatever you get to the LoadFile method.