to Shines:rosement的答案是用了一个封装了MS CommDialog控件功能的DLL完成的,dll必须在使用前实例化,完成了res里的Dialog里的控件的WM_INITDIALOG的工作,以及这些控件的消息捕获工作,并未把这些工作和CommFileDialog的选中的文件等内部功能变化同步起来,而且没有SendDlgItemMessage()给Dialog的子控件发消息,解决了对Dialog的标准控件的消息捕获,它确实已解答了我上述的问题,但未完成你我的问题。这些你都知道了,鉴于文件包比较大,我就不把答案给你了!
资源文件被添加到工程后,.res 文件将出现在“工程”窗口中。与窗体或模块不同,在 Visual Basic 中不能查看 .res 文件。该文件是标准的资源文件,可由 Microsoft Visual C++ 和其它大部分的 Windows 开发工具创建或使用。一旦在“文件”菜单中选中“生成 projectname.exe”一项,Visual Basic 将把该文件中的所有资源编译到 .exe 文件中作为 Windows 的资源。
在编译 .exe 文件之前和之后,.res 文件都是标准的 Windows 资源文件,这意味着任何标准的 Windows 资源编辑器都可以加载该文件。
Option Explicit
Public Const OFN_ALLOWMULTISELECT As Long = &H200
Public Const OFN_CREATEPROMPT As Long = &H2000
Public Const OFN_ENABLEHOOK As Long = &H20
Public Const OFN_ENABLETEMPLATE As Long = &H40
Public Const OFN_ENABLETEMPLATEHANDLE As Long = &H80
Public Const OFN_EXPLORER As Long = &H80000
Public Const OFN_EXTENSIONDIFFERENT As Long = &H400
Public Const OFN_FILEMUSTEXIST As Long = &H1000
Public Const OFN_HIDEREADONLY As Long = &H4
Public Const OFN_LONGNAMES As Long = &H200000
Public Const OFN_NOCHANGEDIR As Long = &H8
Public Const OFN_NODEREFERENCELINKS As Long = &H100000
Public Const OFN_NOLONGNAMES As Long = &H40000
Public Const OFN_NONETWORKBUTTON As Long = &H20000
Public Const OFN_NOREADONLYRETURN As Long = &H8000
Public Const OFN_NOTESTFILECREATE As Long = &H10000
Public Const OFN_NOVALIDATE As Long = &H100
Public Const OFN_OVERWRITEPROMPT As Long = &H2
Public Const OFN_PATHMUSTEXIST As Long = &H800
Public Const OFN_READONLY As Long = &H1
Public Const OFN_SHAREAWARE As Long = &H4000
Public Const OFN_SHAREFALLTHROUGH As Long = 2
Public Const OFN_SHAREWARN As Long = 0
Public Const OFN_SHARENOWARN As Long = 1
Public Const OFN_SHOWHELP As Long = &H10
Public Const OFS_MAXPATHNAME As Long = 260
'OFS_FILE_OPEN_FLAGS and OFS_FILE_SAVE_FLAGS below
'are mine to save long statements; they're not
'a standard Win32 type.
Public Const OFS_FILE_OPEN_FLAGS = OFN_EXPLORER _
Or OFN_LONGNAMES _
Or OFN_CREATEPROMPT _
Or OFN_NODEREFERENCELINKS
Public Const OFS_FILE_SAVE_FLAGS = OFN_EXPLORER _
Or OFN_LONGNAMES _
Or OFN_OVERWRITEPROMPT _
Or OFN_HIDEREADONLY
Public Type OPENFILENAME
nStructSize As Long
hWndOwner As Long
hInstance As Long
sFilter As String
sCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
sFile As String
nMaxFile As Long
sFileTitle As String
nMaxTitle As Long
sInitialDir As String
sDialogTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
sDefFileExt As String
nCustData As Long
fnHook As Long
sTemplateName As String
End Type
Public OFN As OPENFILENAME
Public Declare Function GetOpenFileName Lib "comdlg32.dll" _
Alias "GetOpenFileNameA" _
(pOpenfilename As OPENFILENAME) As Long
Public Declare Function GetSaveFileName Lib "comdlg32.dll" _
Alias "GetSaveFileNameA" _
(pOpenfilename As OPENFILENAME) As Long
Public Declare Function GetShortPathName Lib "kernel32" _
Alias "GetShortPathNameA" _
(ByVal lpszLongPath As String, _
ByVal lpszShortPath As String, _
ByVal cchBuffer As Long) As Long
'new additions to original code
'supporting the Hook method
Public Const WM_INITDIALOG = &H110
Private Const SW_SHOWNORMAL = 1
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Declare Function GetParent Lib "user32" _
(ByVal hwnd As Long) As Long
Public Declare Function SetWindowText Lib "user32" _
Alias "SetWindowTextA" _
(ByVal hwnd As Long, _
ByVal lpString As String) As Long
Public Declare Function MoveWindow Lib "user32" _
(ByVal hwnd As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal bRepaint As Long) As Long
Public Declare Function GetWindowRect Lib "user32" _
(ByVal hwnd As Long, _
lpRect As RECT) As Long
Public Function FARPROC(pfn As Long) As Long
'Dummy procedure that receives and returns
'the return value of the AddressOf operator.
'Obtain and set the address of the callback
'This workaround is needed as you can't assign
'AddressOf directly to a member of a user-
'defined type, but you can assign it to another
'long and use that (as returned here)
FARPROC = pfn
End Function
Public Function OFNHookProc(ByVal hwnd As Long, _
ByVal uMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
'On initialization, set aspects of the
'dialog that are not obtainable through
'manipulating the OPENFILENAME structure members.
Dim hwndParent As Long
Dim rc As RECT
'temporary vars for demo
Dim newLeft As Long
Dim newTop As Long
Dim dlgWidth As Long
Dim dlgHeight As Long
Dim scrWidth As Long
Dim scrHeight As Long
Select Case uMsg
Case WM_INITDIALOG
'obtain the handle to the parent dialog
hwndParent = GetParent(hwnd)
If hwndParent <> 0 Then
'Just to prove the handle was obtained,
'change the dialog's caption.
Call SetWindowText(hwndParent, "I'm Hooked on Hooked Dialogs!")
'Position the dialog in the centre of
'the screen. First get the current dialog size.
Call GetWindowRect(hwndParent, rc)
'(To show the calculations involved, I've
'used variables instead of creating a
'one-line MoveWindow call.)
dlgWidth = rc.Right - rc.Left
dlgHeight = rc.Bottom - rc.Top