SHBrowseForFolder 用法

KEPServer EX6的Modbus、MQTT和REST Server一站式配置整理说明 阅读详情
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.
X书关键词协议搜索 【代码】X书关键词协议搜索。 阅读详情

相关推荐

【Simscape】用Simscape实现三维物理仿真(三)——创建一个滑块单摆系统

1 首先创建一个Simscape Multibody 模型 (方法见 【Simscape】用Simscape实现三维物理仿真(一)——创建一个自由落体小球) 2 创建四个Solid模块 (1)摆杆 Shape : Brick Dimensions : [0.1 0.05 1] m (2)摆杆轴 Shape : Cylinder Radius : 0.02 m Le...

ReadAir的专栏 9046

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

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

mplus的专栏 1963

Qt 5.9.1 32位下,手把手搞定周立功CAN二次开发库的加载与配置(含常见错误排查)

本文详细介绍了在Qt 5.9.1 32位环境下配置周立功CAN二次开发库的完整流程,包括环境准备、项目配置、常见错误排查及性能优化建议。特别针对MinGW 32bit环境,提供了.pro文件的精准配置和DLL部署策略,帮助开发者快速解决库文件匹配、编译报错和运行时问题,实现高效的CAN总线通信开发。

weixin_28717431的博客 359

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

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

1155

RAG——RAG 索引(文档解析技术)

本文介绍了RAG系统中文档解析的关键技术,重点分析了如何通过LangChain的Document Loaders处理多种格式文档。文章指出高质量文档解析对RAG系统效果的决定性作用,并详细讲解了PDF、TXT、Word等常见格式的解析方法。作者提供了代码示例和Gitee开源项目链接,特别强调了PDF解析的深入方案,同时介绍了相关依赖库的安装配置。文章还展示了如何定义通用文档加载方法,为开发者提供了实用的技术参考。

小志的博客 775

SHBrowseForFolder 函数

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

weixin_34415923的博客 309

PWM调节DCDC参数计算原理

SOC芯片的核电压、GPU电压、NPU电压、GPU电压等,都会根据性能和实际应用场景来进行电压和频率的调整。 即动态电压频率调整DVFS(Dynamic Voltage and Frequency scaling),优化性能和功耗。

电子绿洲的博客 3184

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

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

weixin_33854644的博客 834

20.Labview使用子vi进行VI间的数据传递详解(模块化)

子VI(模块化)题主在题注中也提到, 子VI的建立只是为了减少程序的负担,那么我们当使用子VI的时候首先就要明确什么是子VI?什么样的程序可以作为子VI?首先我们来看NI官方给的定义,具体说明如下图所示:题主已经将重点画出来了,在官方的解释中将子VI定义为了模块化,大家可以看到创建模块化子VI的特点在于减少代码重复工作优化了程序的框架结构。把一个代码打包,需要的时候就拎出来让他处理处理,不需要的时候就让它躺在我的列表里就行了也不占用运行空间。那么创建子VI需要需要注意以下几点:①任何一个程序。

关注我,更多技术问题欢迎私聊~ 3525

【模型之美】3、文本聚类与智能摘要,让AI帮你做个总结

在信息过载时代,文本聚类与摘要技术成为关键工具。本文提出了一种结合OpenAI Embedding与传统机器学习的方法,实现从文本预处理到智能分析的完整流程。技术方案分为三阶段:1)通过Embedding将文本转化为语义向量;2)采用K-Means等算法进行无监督聚类;3)利用大模型生成可解释的标签和摘要。实验证明,该方法能有效提升信息处理效率,如在新闻聚合系统中自动分类10,000篇文章,准确率较传统方法提高15%。方案包含实用代码示例,涵盖文本清洗、向量化、聚类优化等关键技术细节,可应用于对话记忆、舆情

2025博客之星Top81。专注AI工程化与架构实战。从分布式思维到模型部署,用工程化视角为你厘清AI落地的真实路径。 1453

SHBrowseForFolder用法

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

leeeryan 722

LeRobot 入门教程(七)数据集

LeRobot Dataset v3.0 是机器人学习数据的标准化格式,支持多模态时间序列数据和视频的统一访问。该版本通过基于文件的存储(Parquet/MP4)、关联元数据和Hub原生流式处理等新特性,显著提升了性能并降低了存储开销。文档详细介绍了格式设计、安装使用、数据记录与加载方法,以及从v2.1迁移到v3.0的步骤,特别针对大型数据集(如DROID 1.0.1)的处理提供了SLURM集群移植方案。v3.0通过优化文件组织和元数据管理,实现了更快的加载速度、更高的内存效率和更好的可扩展性。

2506_90492529的博客 2067

API函数SHBrowseForFolder用法

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

minigift的专栏 773

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

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

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

贝叶斯统计 [韦来生编]

贝叶斯(Bayes)统计是近几十年来迅速发展起来的数理统计的一个重要分支。贝叶斯方法与经典统计方法的主要不同之处是进行统计推断时除了利用样本信息外,还要利用参数的先验信息,因此可以提高统计推断或统计决策的效果。它在经济、金融、生物、医学、自然科学和社会科学等许多领域具有广泛的应用。贝叶斯方法的研究已渗透到了统计学的几乎所有领域。作者在给中国科学技术大学概率论与数理统计专业本科生开设的“数理统计”课程中有一章专门讲授“贝叶斯方法和统计决策理论”,近十年来也给中国科学技术大学概率统计专业研究生开设过几次“贝叶斯分析”课。本书是在对过去讲稿的内容作了适当的增减和调整的基础上完成的。  本书共分六章。第1章是绪论,介绍了贝叶斯统计的若干基本概念,同时对必要的数理统计的基础知识有重点地作了回顾。第二章介绍了确定先验分布的若干可供选择的方法。第三章介绍了几类常见统计模型参数的后验分布的主要结果和计算方法。第四章和第五章分别介绍了“贝叶斯统计推断”和“贝叶斯统计决策”的内容。第六章介绍了贝叶斯统计计算的若干方法,包括蒙特卡洛方法和马尔可夫链蒙特卡洛(MCMC)方法以及相关统计软件的简介。本书的每一章附右大量的例题和习题,书末附有常用的几个表格和部分习题解答供读者查用。  大约可在54学时内讲授本书的第1章至第六章的主要内容,教师可根据学时需要选讲本书第1章至第六章的部分内容。书中标“*”号的章节可略去不讲,留给读者作为阅读材料。第六章例题中的R代码和部分例题的数据文件等可从作者个人主页下载。  作者在编写本书的过程中参考了J.O.Berger教授的《统计决策论及贝叶斯分析》和茆诗松教授编写的《贝叶斯统计》等书中的一些内容,以及《贝叶斯分析》一书中由张伟平博士编写的有关贝叶斯统计计算的一些内容。在此表示衷心感谢。  本书编写准备过程中,中国科学技术大学统计与金融系的几个研究生帮助完成了本书部分中文的录入和排版,作者对他们的辛勤工作表示真诚的感谢。高等教育出版社为本书的出版给予了大力支持。在此一并致谢。

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

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

浏览文件夹对话框,演示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的专栏 3978

获取给定路径的图标,演示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的专栏 5300

ShBrowseForFolder

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

jjwwang的专栏 763
上一篇: 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、付费专栏及课程。

余额充值