未公开API函数揭秘——通用对话框
 
COMDLG32.DLL 为我们提供了一些很有用的对话框,但是仍然有部分我们可能会用到的系统对话框它却没有提供。如果试图复制这些系统对话框将是一件麻烦的苦差事。幸好shell32.dll为我们提供了这些对话框,本文将带你去发掘一些未公开的API函数,以实现这些对话框。在使用未公开的API函数之前,你必须知道声明未公开的API函数与声明那些公开的API函数略有不同,那就是,你必须用到未公开API函数的顺序号(ordinal number)。这个顺序号就是未公开函数的别名。也就是说在声明未公开API函数时,必须加上它的别名。例如下面要说到的PickIconDlg函数的顺序号为62,它的别名就是"#62"。如果不这样做,系统会提示你找不到函数的入口点。选取图标BOOL WINAPI PickIconDlg(
     HWND     hwndOwner, 
     LPSTR    lpstrFile, 
     DWORD    nMaxFile, 
     LPDWORD  lpdwIconIndex);
该函数的顺序号为62。hwndOwner拥有该对话框的窗口句柄 lpstrFile指向一个缓冲,包含初始的文件名。函数返回后它就包含新的文件名。nMaxFile指定缓冲的大小,以字符为单位。 lpdwIconIndex指向一个变量其中包含基于零的图标的索引。函数返回后它包含新图标的索引值。 如果用户选择了图标,则返回值为真,如果用户选择取消按钮或是系统菜单的关闭选项则返回值为假。运行程序对话框void WINAPI RunFileDlg(
     HWND    hwndOwner, 
     HICON   hIcon, 
     LPCSTR  lpstrDirectory, 
     LPCSTR  lpstrTitle, 
     LPCSTR  lpstrDescription,
     UINT    uFlags);
该函数的顺序号为61。在VB中可声明如下:Private Declare Function RunFileDlg Lib "shell32" Alias "#61" (ByVal hwndOwner As Long, ByVal hIcon As Long, ByVal lpstrDirectory As String, ByVal lpstrTitle As String, ByVal lpstrDescription As String, ByVal uFlags As Long) As Long其中uFlags参数的可选值为RFF_NOBROWSE 0x01 Removes the browse button. 
RFF_NODEFAULT 0x02 No default item selected. 
RFF_CALCDIRECTORY 0x04 Calculates the working directory from the file name. 
RFF_NOLABEL 0x08 Removes the edit box label. 
RFF_NOSEPARATEMEM 0x20 Removes the Separate Memory Space check box (Windows NT only).  

解决方案 »

  1.   

    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
    Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
    成功返回0,失败返回其他值