WinXP+SP2系统,用getopenfilename,打开文件对话框显示不出来,出了什么问题了?
代码如下:Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type Dim ofn As OPENFILENAME
Dim selectedfilepath As String
Dim fileopenreturns As Long
ofn.lStructSize = Len(ofn)
ofn.hwndOwner = Me.hWnd
ofn.hInstance = App.hInstance
ofn.lpstrFilter = "ËùÓÐÎļþ"
ofn.lpstrFile = Space(254)
ofn.nMaxFileTitle = 255
ofn.lpstrInitialDir = App.Path
ofn.lpstrTitle = "´ò¿ªÎļþ"
ofn.flags = 6148
fileopenreturns = GetOpenFileName(ofn)
'If fileopenreturns >= 1 Then
MsgBox fileopenreturns
Text1.Text = ofn.lpstrFile
selectedfilepath = ofn.lpstrFile
MsgBox selectedfilepath
'End If
代码如下:Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type Dim ofn As OPENFILENAME
Dim selectedfilepath As String
Dim fileopenreturns As Long
ofn.lStructSize = Len(ofn)
ofn.hwndOwner = Me.hWnd
ofn.hInstance = App.hInstance
ofn.lpstrFilter = "ËùÓÐÎļþ"
ofn.lpstrFile = Space(254)
ofn.nMaxFileTitle = 255
ofn.lpstrInitialDir = App.Path
ofn.lpstrTitle = "´ò¿ªÎļþ"
ofn.flags = 6148
fileopenreturns = GetOpenFileName(ofn)
'If fileopenreturns >= 1 Then
MsgBox fileopenreturns
Text1.Text = ofn.lpstrFile
selectedfilepath = ofn.lpstrFile
MsgBox selectedfilepath
'End If
Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End TypePrivate Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long'=================================================================================
' 关于标志位(flags)的说明
'=================================================================================
' VB常数 十进制数 十六进制 含义说明
'---------------------------------------------------------------------------------
' 524800 &H80200 允许选择多个文件
' cdlOFNCreatePrompt 8192 &H2000
' cdlOFNExtensionDifferent 1024 &H400
' cdlOFNFileMustExist 4096 &H1000 文件必须存在
' cdlOFNHelpButton 16 &H10 显示帮助按钮
' cdlOFNHideReadOnly 4 &H4 隐藏以只读方式打开检查框
' cdlOFNLongNames 2097152 &H200000 允许长文件名
' cdlOFNNoChangeDir 8 &H8
' cdlOFNNoDereferenceLinks 1048576 &H100000
' cdlOFNNoLongNames 262144 &H40000
' cdlOFNNoReadOnlyReturn 32768 &H8000
' cdlOFNNoValidate 256 &H100
' cdlOFNOverwritePrompt 2 &H2 保存文件时,选择的文件已存
' 在时给出提示
' cdlOFNPathMustExist 2048 &H800
' cdlOFNReadOnly 1 &H1
' cdlOFNShareAware 16384 &H4000
'=====================================================================================
'*********************
' 显示保存对话框
'*********************
Public Function ShowSaveDialog(filename As String, Owner As Long, Filter As String, Optional Flage As Long = 8 + 2048 + 2 + 4, Optional InitialDir As String = "C:\My Documents", Optional Extname As String = "", Optional Titel As String = "保存文件") As Long
Dim OFName As OPENFILENAME
With OFName
.lStructSize = Len(OFName)
.hwndOwner = Owner
.hInstance = App.hInstance
.lpstrFile = Space$(254)
.nMaxFile = 255
.lpstrFileTitle = Space$(254)
.nMaxFileTitle = 255
.lpstrFilter = Replace(Filter, "|", Chr(0)) & Chr(0)
.lpstrInitialDir = InitialDir
.lpstrTitle = Titel
.flags = Flage
.lpstrDefExt = Extname
End With
'Show the 'Save File'-dialog
ShowSaveDialog = GetSaveFileName(OFName)
filename = Replace$(Trim$(OFName.lpstrFile), Chr(0), "")
End FunctionPrivate Sub Command1_Click()
Dim filename As String
ShowSaveDialog filename, Me.hWnd, "*.*|*.*"
MsgBox y
End Sub