Exemplo n.º 1
0
        // 打开资源管理器,获取选择的文件夹地址(不选择则返回空字符串)
        public static string GetDirPath2()
        {
            OpenDirName odn = new OpenDirName();

            // 存放目录路径缓冲区
            odn.pszDisplayName = new string(new char[2000]);
            // 标题
            odn.lpszTitle = "Open Project";
            // 新的样式,带编辑框
//            odn.ulFlags = BIF_NEWDIALOGSTYLE | BIF_EDITBOX;
            IntPtr ptr = SHBrowseForFolder(odn);

            char[] chars = new char[2000];
            for (int i = 0; i < chars.Length; i++)
            {
                chars[i] = '\0';
            }
            SHGetPathFromIDList(ptr, chars);
            string fullPath = new string(chars);
            string path     = fullPath.Substring(0, fullPath.IndexOf('\0'));

            return(path);
        }
Exemplo n.º 2
0
 public static extern IntPtr SHBrowseForFolder([In, Out] OpenDirName ofn);