SHBrowseForFolder 用法

Open3D (C++) 泊松重建【2025最新版】 使用C++版本的Open3D实现点云的泊松重建 阅读详情
CString BrowseDirectory(LPCTSTR title) 
{  
    
char dir[MAX_PATH];
    dir[
0]='"0';

    BROWSEINFO bi;  
    bi.hwndOwner
=NULL;  
    bi.pidlRoot
=NULL;  
    bi.pszDisplayName
=dir;  
    bi.lpszTitle
=title;  
    bi.ulFlags
=0;  
    bi.lpfn
=NULL;  
    bi.lParam
=NULL;  
    bi.iImage
=NULL;  
    
    SHGetPathFromIDList(SHBrowseForFolder(
&bi),dir);
    
return dir; 
}


显示一个用于选择文件夹的对话框.


语法

    PIDLIST_ABSOLUTE SHBrowseForFolder(      
        LPBROWSEINFO lpbi
    );

参数

    lpbi
        [in]  一个指向BROWSEINFO结构的指针,该指针包含了文件夹选择对话框显示的信息。

返回值

    Returns a pointer to an item identifier list (PIDL) that specifies the location of the selected folder relative to the root of the namespace. If the user chooses the Cancel button in the dialog box, the return value is NULL.

    It is possible that the PIDL returned is that of a folder shortcut rather than a folder. For a full discussion of this case, see the Remarks section.

备注

    You must initialize Component Object Model (COM) before you call SHBrowseForFolder. If you initialize COM using CoInitializeEx, you must set the COINIT_APARTMENTTHREADED flag in its dwCoInit parameter. You can also use CoInitialize or OleInitialize, which always use apartment threading. If you require drag-and-drop functionality, OleInitialize is recommended because it initializes the required OLE as well as COM.
    Note  If COM is initialized using CoInitializeEx with the COINIT_MULTITHREADED flag, SHBrowseForFolder fails if the calling application uses the BIF_USENEWUI or BIF_NEWDIALOGSTYLE flag in the BROWSEINFO structure.

    It is the responsibility of the calling application to call CoTaskMemFree to free the IDList returned by SHBrowseForFolder when it is no longer needed.

    There are two styles of dialog box available. The older style is displayed by default and is not resizable. The newer style provides a number of additional features, including drag-and-drop capability within the dialog box, reordering, deletion, shortcut menus, the ability to create new folders, and other shortcut menu commands. Initially, it is larger than the older dialog box, but the user can resize it. To specify a dialog box using the newer style, set the BIF_USENEWUI flag in the ulFlags member of the BROWSEINFO structure.

    If you implement a callback function, specified in the lpfn member of the BROWSEINFO structure, you receive a handle to the dialog box. One use of this window handle is to modify the layout or contents of the dialog box. Because it is not resizable, modifying the older style dialog box is relatively straightforward. Modifying the newer style dialog box is much more difficult, and not recommended. Not only does it have a different size and layout than the old style, but its dimensions and the positions of its controls change every time it is resized by the user.

    If the BIF_RETURNONLYFSDIRS flag is set in the ulFlags member of the BROWSEINFO structure, the OK button remains enabled for """server" items, as well as """server"share" and directory items. However, if the user selects a """server" item, passing the PIDL returned by SHBrowseForFolder to SHGetPathFromIDList fails.

    SHBrowseForFolder does not display libraries.

    Custom Filtering

    As of Microsoft Windows XP, SHBrowseForFolder supports custom filtering on the contents of the dialog box. To create a custom filter, follow these steps.

       1. Set the BIF_NEWDIALOGSTYLE flag in the ulFlags member of the BROWSEINFO structure pointed to by the lpbi parameter.
       2. Specify a callback function in the lpfn member of that same BROWSEINFO structure.
       3. Code the callback function to receive the BFFM_INITIALIZED and BFFM_IUNKNOWN messages. On receipt of the BFFM_IUNKNOWN message, the callback function's lParam parameter contains a pointer to the dialog box's implementation of IUnknown. Call QueryInterface on that IUnknown to obtain a pointer to an instance of IFolderFilterSite.
       4. Create an object that implements IFolderFilter.
       5. Call IFolderFilterSite::SetFilter, passing to it a pointer to your IFolderFilter. IFolderFilter methods can then be used to include and exclude items from the tree.
       6. Once the filter is created, the IFolderFilterSite interface is no longer needed. Call IFolderFilterSite::Release if you have no further use for it.

    Dealing With Shortcuts
    Note  This section applies to only Windows 2000 and earlier systems. By default, Windows XP and later systems return the PIDL of a shortcut's target rather than the shortcut itself, as long as the BIF_NOTRANSLATETARGETS flag is not set in the BROWSEINFO structure.

    If SHBrowseForFolder returns a PIDL to a shortcut, sending that PIDL to SHGetPathFromIDList returns the path of the shortcut itself rather than the path of its target. The path to the shortcut's target can be obtained by using the IShellLink interface as shown in this example.


    #include
    // Macros for interface casts

    #ifdef __cplusplus
    #define IID_PPV_ARG(IType, ppType) IID_##IType, reinterpret_cast(static_cast(ppType))
    #else
    #define IID_PPV_ARG(IType, ppType) &IID_##IType, (void**)(ppType)
    #endif

    // Retrieves the UIObject interface for the specified full PIDL
    STDAPI SHGetUIObjectFromFullPIDL(LPCITEMIDLIST pidl, HWND hwnd, REFIID riid, void **ppv)
    {
    LPCITEMIDLIST pidlChild;
    IShellFolder* psf;
    *ppv = NULL;
    HRESULT hr = SHBindToParent(pidl, IID_PPV_ARG(IShellFolder, &psf), &pidlChild);
    if (SUCCEEDED(hr))
    {
    hr = psf->GetUIObjectOf(hwnd, 1, &pidlChild, riid, NULL, ppv);
    psf->Release();
    }
    return hr;
    }

    #define ILSkip(pidl, cb)       ((LPITEMIDLIST)(((BYTE*)(pidl))+cb))
    #define ILNext(pidl)           ILSkip(pidl, (pidl)->mkid.cb)

    HRESULT SHILClone(LPCITEMIDLIST pidl, LPITEMIDLIST *ppidl)
    {
    DWORD cbTotal = 0;
    if (pidl)
    {
    LPCITEMIDLIST pidl_temp = pidl;
    cbTotal += sizeof (pidl_temp->mkid.cb);
    while (pidl_temp->mkid.cb)
    {
    cbTotal += pidl_temp->mkid.cb;
    pidl_temp += ILNext (pidl_temp);
    }
    }
    *ppidl = (LPITEMIDLIST)CoTaskMemAlloc(cbTotal);
    if (*ppidl)
    CopyMemory(*ppidl, pidl, cbTotal);
    return  *ppidl ? S_OK: E_OUTOFMEMORY;
    }

    // Get the target PIDL for a folder PIDL. This also deals with cases of a folder  
    // shortcut or an alias to a real folder.
    STDAPI SHGetTargetFolderIDList(LPCITEMIDLIST pidlFolder, LPITEMIDLIST *ppidl)
    {
    IShellLink *psl;
    *ppidl = NULL;
    HRESULT hr = SHGetUIObjectFromFullPIDL(pidlFolder, NULL, IID_PPV_ARG(IShellLink, &psl));
    if (SUCCEEDED(hr))
    {
    hr = psl->GetIDList(ppidl);
    psl->Release();
    }

    // It's not a folder shortcut so get the PIDL normally.
    if (FAILED(hr))
    hr = SHILClone(pidlFolder, ppidl);
    return hr;
    }

    // Get the target folder for a folder PIDL. This deals with cases where a folder
    // is an alias to a real folder, folder shortcuts, the My Documents folder, etc.
    STDAPI SHGetTargetFolderPath(LPCITEMIDLIST pidlFolder, LPWSTR pszPath, UINT cchPath)
    {
    LPITEMIDLIST pidlTarget;
    *pszPath = 0;
    HRESULT hr = SHGetTargetFolderIDList(pidlFolder, &pidlTarget);
    if (SUCCEEDED(hr))
    {
    SHGetPathFromIDListW(pidlTarget, pszPath);   // Make sure it is a path
    CoTaskMemFree(pidlTarget);
    }
    return *pszPath ? S_OK : E_FAIL;
    }

    Windows 95/98/Me: SHBrowseForFolder is supported by the Microsoft Layer for Unicode (MSLU). To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows Me/98/95 Systems.
我用C#实现上位机数据一键导出Excel:从乱码到百万行数据秒级导出的实战技巧 ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("日报表");// 1. 标题(合并单元格)worksheet.Cells["A1"].Value = $"产线日报表 -DateTimeNowToString// 2. 表头和数据(同上)worksheet.Cells["A3"].Value = "时间";// ...省略表头和数据填充// 3. 合计行(公式计算) 阅读详情

相关推荐

高速DAC设计与实现--AD9122

目录 芯片简介: 功能配置设计 高速DAC软件驱动设计 芯片简介: AD9122 是一款双通道16位高性能数模转换器(DAC),在800MSPS工作条件下其无杂散动态范围(SFDR)高达72dBc,最高可提供1200 MSPS采样速率。 高速DAC--AD9122电路原理图 硬件设计的电路原理图如上图所示,AD9122具备针对直接变频传输应用进行优化的特性,包括复数数字调制以及增益与失调补偿。DAC输出经过优化后可直接与模拟正交调制器无缝接口,便于后期使...

独木舟216的博客 1万+

使用SHBrowseForFolder函数打开文件目录对话框

使用SHBrowseForFolder函数打开文件目录对话框 自从第一份工作辞职后,差不多三年多没有再搞MFC了,对于微软的Windows桌面开发真的淡忘了,这次接到一个任务,需要开发个小工具,虽然任务很小,但是在一个如何打开文件目录对话框的小问题上卡了下,虽然通过网络找到了解决方法,但是网上七拼八凑的文章太多,看的有点费时,所以就抽时间小结一下,虽然也是简单使用,没有太多扩展,就当

mplus的专栏 1963

张量积曲面:数学原理与Python实现

Suv∑i0m∑j0nPij⋅Bipu⋅BjqvSuvi0∑m​j0∑n​Pij​⋅Bip​u⋅Bjq​v其中PijP_{i,j}Pij​是控制点网格,BipuB_i^p(u)Bip​u和BjqvB_j^q(v)Bjq​v是基函数,分别沿uuu和vvv方向定义。

T20151470的博客 1159

用VC调用Shell中的目录浏览对话框

First Example:有时我们需要获得某个文件夹的路径,而不是文件的路径,这时需要用API函数SHBrowseForFolder来实现。 函数原型为:LPITEMIDLIST SHBrowseForFolder(LPBROWSEINFO lpbi); 其中LPBROWSEINFO为BROWSEINFO结构的指针。BROWSEINFO结构如下:typedef struc

1154

嵌入式系统存储体系

主要分为三种:高速缓存(cache)、主存和外存。

weixin_43586667的博客 2265

无人机航拍图像匹配——SIFT算法实践(含代码)

无人机航拍图像匹配——SIFT算法实践(含代码)

zhangzhao147的博客 6395

SHBrowseForFolder 函数

  示例代码:  CString BrowseDirectory(LPCTSTR title)  {       char dir[MAX_PATH];     dir[0]='"0';     BROWSEINFO bi;       bi.hwndOwner=NULL;       bi.pidlRoot=NULL;       bi.pszDisplayName=...

weixin_34415923的博客 308

面试中常考的数学题——截木棍、圆上取点、赛马、红蓝墨水,测试毒药、坐到正确座位问题

文章目录1.将一根木棒截成三段,问能够组成三角形的概率;2.在圆上任取三点,问能够组成锐角、直角、钝角三角形的概率;3.共有25匹马,找出最快的3匹,只有5个赛道,每次比赛只能得到5匹马的速度排序,最少需要多少次比赛;4 有两瓶红蓝墨水,体积一样,现在从红墨水中舀一勺加入蓝墨水中,搅拌均匀后,在从蓝墨水中舀一勺加到红墨水中,试问这两瓶墨水哪瓶纯度更高。 1.将一根木棒截成三段,问能够组成三角形的概率; 来源:https://blog.youkuaiyun.com/weixin_41245919/article/deta

weixin_41558411的博客 4906

MFC选择目录SHBrowseForFolder选择文件CFileDialog对话框设置默认路径

CFileDialog会自动记住上一次路径,SHBrowseForFolder需要写个回调函数,传值给BROWSEINFOBaseFunc.h#include <string>using namespace std;namespace BaseFunc{    // 选择文件,可设置定位到默认目录    unsigned selFile(string &strFile,cons...

weixin_33854644的博客 832

《AFSim 2.9中文参考手册》

本栏目将对《AFSim 2.9中文参考手册》进行持续更新,欢迎关注交流!对本文或者AFSIM相关内容感兴趣的朋友,可私心联系作者。《AFSim 2.9中文参考手册》内容概览。

henggesim的博客 1万+

aubo i5 + realsense D435i识别抓取实践二

aubo i5 + realsense D435i识别抓取实践二前言一、手眼标定是什么?二、标定软件安装1.aruco_ros安装2.vision_visp安装3.easy_handeye安装4.realsense驱动安装5.安装realsense ROS软件包三、配置1.launch文件修改2.打印二维码四、手眼标定1.启动launch文件2.标定步骤3.发布tf关系 前言 前面配置好了aubo机械臂的ROS软件包,机械臂可以正常运行后,接下来我们进行机械臂与相机的手眼标定。手眼标定分为eye_on_ha

转角 6375

SHBrowseForFolder用法

/********************************************************************  created:  2008/04/24  created:  24:4:2008   12:47  author:    Gohan                 http://feed.feedsky.com/gohan  purpose:  演示

leeeryan 722

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

API函数SHBrowseForFolder用法

这里主要介绍使用SHBrowseForFolder时,如何设置默认路径。还没找到更好的方法,使用的是回调函数//--------------------------------------------------------------------------------------------------------------------------------//在此函数里设置默认路径,这里取的是应用程序的路径int CALLBACK BrowseCallbackProc(HWND hwnd, UIN

minigift的专栏 772

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

Shell API SHBrowseForFolder的用法

Shell API SHBrowseForFolder的用法  Code as bellow{ BROWSEINFO  bi; bi.hwndOwner=NULL; bi.pidlRoot=NULL; bi.pszDisplayName=NULL; bi.lpszTitle=NULL; bi.ulFlags=0; bi.lpfn =NULL; bi.iImage =0; LPCITEMIDLI

坚持,才是力量.老实做人,踏实做事. 1909

wince Vs2005下SHBrowseForFolder用法

添加 文件头#include "Shlobj.h"// CDiagnosParamDlg 对话框#pragma comment (lib,"Ceshell.lib")使用wchar_t dir[200];       BROWSEINFO bi;      bi.hwndOwner=NULL;      bi.pidlRoot=NULL;      bi.pszDisplayName=L"选择诊断文件";      bi.lpszTitle=L"DD";      bi.ulFlags=0;      bi

zmq5411的专栏 1533

浏览文件夹对话框,演示SHBrowseForFolder用法

浏览文件夹对话框,演示SHBrowseForFolder用法 /******************************************************************** created: 2008/04/24 created: 24:4:2008 12:47 author: Gohan http://f

luojiafei的专栏 771

转载:浏览文件夹对话框,演示SHBrowseForFolder用法

浏览文件夹对话框,演示SHBrowseForFolder用法 /********************************************************************  created:  2008/04/24  created:  24:4:2008   12:47  author:    Gohan                 http://

namtaerg的专栏 592

BROWSEINFO结构

SHBrowseForFolde函数包含的参数,并接收由用户选择的文件夹有关的信息 typedef struct _browseinfo { HWND hwndOwner; PCIDLIST_ABSOLUTE pidlRoot; LPTSTR pszDisplayName; LPCTSTR lpszTitle;

JohnnyHu90的专栏 3974

获取给定路径的图标,演示SHGetFileInfo用法

基于上次那个SHBrowseForFolder用法的演示代码 建立的仍然是Win32 命令行的工程,所以入口点为main(),需要手动获取HINSTANCE结构。程序在WINXP+VS2005测试通过 /******************************************************************** created: 2008/05/02 crea

luojiafei的专栏 3190

SHBrowseForFolder

 有时我们需要获得某个文件夹的路径,而不是文件的路径,这时需要用API函数SHBrowseForFolder来实现。  函数原型为:LPITEMIDLIST SHBrowseForFolder(LPBROWSEINFO lpbi); 其中LPBROWSEINFO为BROWSEINFO结构的指针。BROWSEINFO结构如下:typedef struct _browseinf

jxwking2010的专栏 1356

SHBrowseForFolder 的一些使用

   SHBrowseForFolder是一个可以用于获取文件夹路径的Windows API。使用起来可以方便很多,近来在写程序时用到了,现在总结一下。   首先当然要有一些基本认识才行。所以先看一下下面所列的MSDN。http://msdn.microsoft.com/en-us/library/bb762115%28VS.85%29.aspxhttp://msdn.micr

HelloDan的专栏 5298

ShBrowseForFolder

unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, FileCtrl, StdCtrls;type TForm1 = class(TForm) Button1: TButton; pr

jjwwang的专栏 762
上一篇: WinCE下自定义Shell的方法
下一篇: SHGetFileInfo函数详解
dadalan
博客等级 码龄20年 428粉丝 770原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值