home *** CD-ROM | disk | FTP | other *** search
- VERSION 5.00
- Begin VB.Form FileOpenSaveForm
- BorderStyle = 3 'Fixed Dialog
- Caption = "File Open and File Save example"
- ClientHeight = 6600
- ClientLeft = 45
- ClientTop = 330
- ClientWidth = 9510
- LinkTopic = "Form1"
- MaxButton = 0 'False
- MinButton = 0 'False
- ScaleHeight = 6600
- ScaleWidth = 9510
- ShowInTaskbar = 0 'False
- Begin VB.CommandButton ShowOpenBut
- Caption = "Sho&w Open Dialog!"
- BeginProperty Font
- Name = "MS Sans Serif"
- Size = 12
- Charset = 0
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 375
- Left = 120
- TabIndex = 38
- Top = 6120
- Width = 2505
- End
- Begin VB.CommandButton ShowSaveBut
- Caption = "&Show Save Dialog!"
- BeginProperty Font
- Name = "MS Sans Serif"
- Size = 12
- Charset = 0
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 375
- Left = 120
- TabIndex = 37
- Top = 5520
- Width = 2505
- End
- Begin VB.Frame Frame6
- Caption = "Results"
- BeginProperty Font
- Name = "MS Sans Serif"
- Size = 13.5
- Charset = 0
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 1050
- Left = 2760
- TabIndex = 33
- Top = 5440
- Width = 6615
- Begin VB.TextBox PathText
- Height = 285
- Left = 1380
- TabIndex = 27
- Top = 660
- Width = 5055
- End
- Begin VB.TextBox FileSelectedText
- Height = 285
- Left = 1380
- TabIndex = 26
- Top = 300
- Width = 5055
- End
- Begin VB.Label Label9
- AutoSize = -1 'True
- Caption = "Path Selected"
- Height = 195
- Left = 120
- TabIndex = 35
- Top = 690
- Width = 1005
- End
- Begin VB.Label Label3
- AutoSize = -1 'True
- Caption = "File(s) Selected"
- Height = 195
- Left = 120
- TabIndex = 34
- Top = 330
- Width = 1080
- End
- End
- Begin VB.Frame Frame5
- Caption = "OK and Cancel Button Options"
- BeginProperty Font
- Name = "MS Sans Serif"
- Size = 8.25
- Charset = 0
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 1125
- Left = 120
- TabIndex = 32
- Top = 120
- Width = 6735
- Begin VB.CheckBox CancelErrorCheck
- Caption = "&Raise Error On Cancel"
- Height = 285
- Left = 120
- TabIndex = 2
- Top = 630
- Width = 1905
- End
- Begin VB.CheckBox HideCancelCheck
- Caption = "Hide Cancel B&utton"
- Height = 285
- Left = 120
- TabIndex = 1
- Top = 240
- Width = 1845
- End
- Begin VB.CheckBox CustomButtonCaptionCheck
- Caption = "Change &Open/Save Button Caption"
- Height = 285
- Left = 2640
- TabIndex = 3
- Top = 240
- Width = 2865
- End
- Begin VB.TextBox CustomButtonCaptionText
- Height = 345
- Left = 5580
- TabIndex = 4
- Text = "&Select"
- Top = 210
- Width = 945
- End
- Begin VB.TextBox CustomCancelCaptionText
- Height = 345
- Left = 5580
- TabIndex = 6
- Text = "E&xit"
- Top = 630
- Width = 945
- End
- Begin VB.CheckBox CustomCancelCaptionCheck
- Caption = "Change &Cancel Button Caption"
- Height = 285
- Left = 2640
- TabIndex = 5
- Top = 630
- Width = 2865
- End
- End
- Begin VB.Frame Frame4
- Caption = "Dialog Box Position"
- BeginProperty Font
- Name = "MS Sans Serif"
- Size = 8.25
- Charset = 0
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 1500
- Left = 120
- TabIndex = 31
- Top = 1320
- Width = 6735
- Begin VB.CheckBox SetDlgPosCheck
- Caption = "Set &Dialog Position"
- Height = 285
- Left = 120
- TabIndex = 7
- Top = 240
- Width = 1845
- End
- Begin VB.CheckBox SetDlgPosToScreenCheck
- Caption = "Set Dialog &Position Relative To Screen"
- Height = 285
- Left = 480
- TabIndex = 8
- Top = 600
- Width = 3075
- End
- Begin VB.TextBox XPosText
- Height = 345
- Left = 2040
- TabIndex = 10
- Text = "0"
- Top = 1020
- Width = 555
- End
- Begin VB.TextBox YPosText
- Height = 345
- Left = 4080
- TabIndex = 12
- Text = "0"
- Top = 1020
- Width = 555
- End
- Begin VB.Label Label1
- AutoSize = -1 'True
- Caption = "&X Position"
- Height = 195
- Left = 1200
- TabIndex = 9
- Top = 1065
- Width = 705
- End
- Begin VB.Label Label2
- Caption = "&Y Position"
- Height = 225
- Left = 3240
- TabIndex = 11
- Top = 1065
- Width = 735
- End
- End
- Begin VB.Frame Frame3
- Caption = "&Flags"
- BeginProperty Font
- Name = "MS Sans Serif"
- Size = 8.25
- Charset = 0
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 5310
- Left = 6960
- TabIndex = 24
- Top = 120
- Width = 2415
- Begin VB.ListBox List1
- Height = 4545
- ItemData = "opensave.frx":0000
- Left = 120
- List = "opensave.frx":0046
- MultiSelect = 1 'Simple
- TabIndex = 25
- Top = 240
- Width = 2175
- End
- End
- Begin VB.Frame Frame2
- Caption = "Other Options"
- BeginProperty Font
- Name = "MS Sans Serif"
- Size = 8.25
- Charset = 0
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 1095
- Left = 120
- TabIndex = 30
- Top = 4320
- Width = 6735
- Begin VB.CheckBox RaiseEventCheck
- Caption = "Raise Callback &Event"
- Height = 285
- Left = 4680
- TabIndex = 22
- Top = 240
- Width = 1875
- End
- Begin VB.TextBox OpenSaveFilterText
- Height = 315
- Left = 1830
- TabIndex = 23
- Text = "Text (*.txt)|*.txt|Pictures (*.bmp;*.ico)|*.bmp;*.ico|All Files (*.*)|*.*"
- Top = 630
- Width = 4755
- End
- Begin VB.TextBox OpenSaveCaptionText
- Height = 315
- Left = 1830
- TabIndex = 21
- Text = "Open"
- Top = 240
- Width = 1995
- End
- Begin VB.Label Label5
- Caption = "Open Save Filter"
- Height = 255
- Left = 240
- TabIndex = 36
- Top = 675
- Width = 1515
- End
- Begin VB.Label Label4
- Caption = "Di&alog Box Caption"
- Height = 255
- Left = 240
- TabIndex = 20
- Top = 270
- Width = 1515
- End
- End
- Begin VB.Frame Frame1
- Caption = "Help Options"
- BeginProperty Font
- Name = "MS Sans Serif"
- Size = 8.25
- Charset = 0
- Weight = 700
- Underline = 0 'False
- Italic = 0 'False
- Strikethrough = 0 'False
- EndProperty
- Height = 1455
- Left = 120
- TabIndex = 0
- Top = 2840
- Width = 6735
- Begin VB.CommandButton Command1
- Caption = "&Browse..."
- Height = 375
- Left = 5520
- TabIndex = 15
- Top = 200
- Width = 1095
- End
- Begin VB.TextBox HelpKeyText
- Height = 315
- Left = 2880
- TabIndex = 19
- Top = 1050
- Width = 1005
- End
- Begin VB.TextBox HelpContextNumberText
- Height = 315
- Left = 2880
- TabIndex = 18
- Top = 630
- Width = 1005
- End
- Begin VB.OptionButton HelpKeyOpt
- Caption = "Help &Key"
- Height = 255
- Left = 180
- TabIndex = 17
- Top = 1080
- Width = 1245
- End
- Begin VB.TextBox HelpFileText
- Height = 315
- Left = 1410
- TabIndex = 14
- Top = 210
- Width = 4005
- End
- Begin VB.OptionButton HelpContextOpt
- Caption = "Help Co&ntext"
- Height = 255
- Left = 180
- TabIndex = 16
- Top = 690
- Value = -1 'True
- Width = 1245
- End
- Begin VB.Label Label8
- Caption = "Help Key Word"
- Height = 255
- Left = 1620
- TabIndex = 29
- Top = 1110
- Width = 1155
- End
- Begin VB.Label Label7
- Caption = "Context Number"
- Height = 255
- Left = 1620
- TabIndex = 28
- Top = 690
- Width = 1155
- End
- Begin VB.Label Label6
- Caption = "&Help File Name"
- Height = 255
- Left = 150
- TabIndex = 13
- Top = 240
- Width = 1155
- End
- End
- Attribute VB_Name = "FileOpenSaveForm"
- Attribute VB_GlobalNameSpace = False
- Attribute VB_Creatable = False
- Attribute VB_PredeclaredId = True
- Attribute VB_Exposed = False
- Option Explicit
- Dim WithEvents dwCmdDialog As dwFileOpenSave
- Attribute dwCmdDialog.VB_VarHelpID = -1
- Private Declare Function EnableWindow& Lib "user32" (ByVal hWnd As Long, ByVal fEnable As Long)
- Private Sub command1_Click()
- Dim dwCmdDialog As dwFileOpenSave
- Dim lres As Long
- Dim lstr As String
- Set dwCmdDialog = New dwFileOpenSave
- dwCmdDialog.DialogTitle = "Select Help File"
- dwCmdDialog.Filter = "Help (*.hlp)|*.hlp|All Files (*.*)|*.*"
- dwCmdDialog.DlgWindowOwner = Me.hWnd
- dwCmdDialog.SetDialogPosition = True
- dwCmdDialog.PosX = 50
- dwCmdDialog.PosY = 50
- dwCmdDialog.CustomOkButtonCaption = True
- dwCmdDialog.OkButtonCaption = "Select"
- dwCmdDialog.Flags = glmcdOFNEnableHook Or glmcdOFNLongNames Or glmcdOFNFileMustexist Or glmcdOFNNoChangeDir Or glmcdOFNHideReadOnly
- If WindowsVersion <> 35 Then
- dwCmdDialog.Flags = dwCmdDialog.Flags Or glmcdOFNExplorer
- End If
- lres = dwCmdDialog.ShowOpen
- If lres = 1 Then
- HelpFileText.Text = dwCmdDialog.filename
- End If
- Set dwCmdDialog = Nothing
- End Sub
- Private Sub dwCmdDialog_dwCmnDlgCallback(ByVal hWnd As Long, ByVal msg As Long, ByVal wp As Long, ByVal lp As Long, retval As Long)
- Debug.Print "Message " & Hex$(msg) & " for " & Hex$(hWnd)
- End Sub
- Private Sub Form_Load()
- If SetDlgPosCheck.Value Then
- SetDlgPosToScreenCheck.Enabled = True
- XPosText.Enabled = True
- YPosText.Enabled = True
- Else
- SetDlgPosToScreenCheck.Enabled = False
- XPosText.Enabled = False
- YPosText.Enabled = False
- End If
- If HelpContextOpt.Value Then
- HelpContextNumberText.Enabled = True
- HelpKeyText.Enabled = False
- HelpKeyText.Text = ""
- Else
- HelpKeyText.Enabled = True
- HelpContextNumberText.Enabled = False
- HelpContextNumberText.Text = ""
- End If
- ' Initialize list box
- List1.Selected(0) = True ' Show Read Only button
- List1.Selected(4) = True ' Show Help button
- List1.Selected(5) = True ' enable hook
- If WindowsVersion <> 35 Then
- List1.Selected(19) = True ' explorer style
- End If
- End Sub
- Private Sub HelpContextOpt_Click()
- HelpContextNumberText.Enabled = True
- HelpKeyText.Enabled = False
- HelpKeyText.Text = ""
- End Sub
- Private Sub HelpKeyOpt_Click()
- HelpKeyText.Enabled = True
- HelpContextNumberText.Enabled = False
- HelpContextNumberText.Text = ""
- End Sub
- Private Sub SetDlgPosCheck_Click()
- If SetDlgPosCheck.Value Then
- SetDlgPosToScreenCheck.Enabled = True
- XPosText.Enabled = True
- YPosText.Enabled = True
- Else
- SetDlgPosToScreenCheck.Enabled = False
- XPosText.Enabled = False
- YPosText.Enabled = False
- End If
- End Sub
- Private Sub ShowOpenBut_Click()
- Dim lres As Long
- Dim specialhandling As Boolean
- Set dwCmdDialog = New dwFileOpenSave
- GetDialogInfo dwCmdDialog
- ' Need a special check to handle the case where the Explorer style common dialog
- ' is used and the vertical position of the common dialog is specified to a position
- ' lower (greater) than that of the dialog's owner window.
- If dwCmdDialog.Flags And glmcdOFNExplorer Then
- If dwCmdDialog.SetDialogPosition Then
- ' *** Same problem can occur if the vertical position is specified to a negative value.
- If dwCmdDialog.SetDialogRelativeToScreen Then
- specialhandling = True
- ' Set the dialog's owner window to the desktop and
- ' manually disable the owner window.
- dwCmdDialog.DlgWindowOwner = 0
- Me.Enabled = False ' or use the EnableWindow API function to disable window
- ' Call EnableWindow(Me.hwnd, False)
- End If
- End If
- End If
- lres = dwCmdDialog.ShowOpen
- If specialhandling Then
- Me.Enabled = True ' or use the EnableWindow API function to enable window
- ' Call EnableWindow(Me.hwnd, True)
- ' This is needed for Windows 95, for some reason the application loses the focus
- ' after the dialog closes. This may produce a flicker though. Not needed on NT.
- Me.SetFocus
- End If
- If lres <> 1 Then
- ' If cancel was selected, or other error.
- FileSelectedText.Text = ""
- PathText.Text = ""
- Else
- GetDialogResults dwCmdDialog
- End If
- Set dwCmdDialog = Nothing
- End Sub
- Private Function GetOpenSaveFlags() As Long
- Dim lcount As Long, lindex As Long
- Dim flagvalue As Long
- lindex = List1.ListCount
- For lcount = 0 To lindex - 1 Step 1
- If List1.Selected(lcount) Then
- flagvalue = flagvalue + 2 ^ lcount
- End If
- Next
- GetOpenSaveFlags = flagvalue
- End Function
- Private Sub ShowSaveBut_Click()
- Dim lres As Long
- Dim specialhandling As Boolean
- Set dwCmdDialog = New dwFileOpenSave
- GetDialogInfo dwCmdDialog
- ' Need a special check to handle the case where the Explorer style common dialog
- ' is used and the vertical position of the common dialog is specified to a position
- ' lower (greater) than that of the dialog's owner window.
- If dwCmdDialog.Flags And glmcdOFNExplorer Then
- If dwCmdDialog.SetDialogPosition Then
- ' *** Same problem can occur if the vertical position is specified to a negative value.
- If dwCmdDialog.SetDialogRelativeToScreen Then
- specialhandling = True
- ' Set the dialog's owner window to the desktop and
- ' manually disable the owner window.
- dwCmdDialog.DlgWindowOwner = 0
- Me.Enabled = False ' or use the EnableWindow API function to disable window
- ' Call EnableWindow(Me.hwnd, False)
- End If
- End If
- End If
- lres = dwCmdDialog.ShowSave
- If specialhandling Then
- Me.Enabled = True ' or use the EnableWindow API function to enable window
- ' Call EnableWindow(Me.hwnd, True)
- ' This is needed for Windows 95, for some reason the application loses the focus
- ' after the dialog closes. This may produce a flicker though. Not needed on NT.
- Me.SetFocus
- End If
- If lres <> 1 Then
- ' If cancel was selected, or other error.
- FileSelectedText.Text = ""
- PathText.Text = ""
- Else
- GetDialogResults dwCmdDialog
- End If
- Set dwCmdDialog = Nothing
- End Sub
- Private Sub GetDialogInfo(dwCmdDialog As dwFileOpenSave)
- dwCmdDialog.DialogTitle = OpenSaveCaptionText.Text
- dwCmdDialog.Filter = OpenSaveFilterText.Text
- dwCmdDialog.DlgWindowOwner = Me.hWnd
- dwCmdDialog.HideCancel = HideCancelCheck.Value
- dwCmdDialog.SetDialogPosition = SetDlgPosCheck.Value
- dwCmdDialog.SetDialogRelativeToScreen = SetDlgPosToScreenCheck.Value
- dwCmdDialog.PosX = Val(XPosText.Text)
- dwCmdDialog.PosY = Val(YPosText.Text)
- dwCmdDialog.CustomOkButtonCaption = CustomButtonCaptionCheck.Value
- dwCmdDialog.OkButtonCaption = CustomButtonCaptionText.Text
- dwCmdDialog.CustomCancelButtonCaption = CustomCancelCaptionCheck.Value
- dwCmdDialog.CancelButtonCaption = CustomCancelCaptionText.Text
- dwCmdDialog.RaiseCallbackEvent = RaiseEventCheck.Value
- dwCmdDialog.CancelError = CancelErrorCheck.Value
- dwCmdDialog.Flags = GetOpenSaveFlags()
- dwCmdDialog.HelpFile = Trim$(HelpFileText.Text)
- If dwCmdDialog.HelpFile <> "" Then
- If HelpContextOpt.Value Then
- dwCmdDialog.HelpCommand = glmcdHCContext
- dwCmdDialog.HelpContext = Val(HelpContextNumberText.Text)
- Else
- dwCmdDialog.HelpCommand = glmcdHCKey
- dwCmdDialog.HelpKey = HelpKeyText.Text
- End If
- End If
- End Sub
- Private Sub GetDialogResults(dwCmdDialog As dwFileOpenSave)
- Dim findex As Long, fcount As Long
- Dim fname As String
- ' A file was selected
- If dwCmdDialog.FileCount > 1 Then
- fcount = dwCmdDialog.FileCount
- For findex = 1 To fcount Step 1
- fname = fname & dwCmdDialog.FileNameByIndex(findex) & " "
- Next
- FileSelectedText.Text = fname
- Else
- FileSelectedText.Text = dwCmdDialog.FileTitle
- End If
- PathText.Text = dwCmdDialog.FilePath
- End Sub
-