精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>● 编程世界>>VC编程>>调用Win32 API实现文件夹的选择

主题:调用Win32 API实现文件夹的选择
发信人: kingfox()
整理人: jinhu(1999-08-03 20:20:11), 站内信件
编写过Windows Application的程序员一定熟悉经典的用于显示“打开文件”和“
保存文件”对话框的的GetOpenFileName和GetSaveFileName函数。可是这两函数
只能显示选择文件的对话框。那么,如何显示一个只选择文件夹的对话框呢?

Win32 API的Shell Extension外壳扩展接口提供了这种途径。下面是一段用C语言
编写的程序,可以显示上图所示的对话框。 void SelectDirDlg( char Dir[] )

{
   BROWSEINFO bi;
   ITEMIDLIST *pidl;

   bi.hwndOwner = NULL;
   bi.pidlRoot = NULL;
   bi.pszDisplayName = Dir;
   bi.lpszTitle = "Select a directory";
   bi.ulFlags = BIF_RETURNONLYFSDIRS;
   bi.lpfn = NULL;
   bi.lParam = 0;
   bi.iImage = 0;

   pidl = SHBrowseForFolder( &bi );     /* Display "Select Folder" dia
log box, Get the 
                                           folder name and convert it 
into a ITEMLIST 
                                           data structure. */
   if ( pidl == NULL )
      Dir[0] = 0;
   if (!SHGetPathFromIDList( pidl, Dir ))       /* Retrieve folder nam
e from ITEMLIST 
                                                   structure. */
      Dir[0] = 0;
}


--
------------------------------------------------------------
有缘则聚,缘尽则散,随缘而定,随遇而安。
------------------------------------------------------------
欢迎光临“电子工程师园地”http://kingfox.163.net

※ 来源:.月光软件站 http://www.moon-soft.com.[FROM: 202.101.0.54]

[关闭][返回]