当前位置:网站首页>C language calls the file browser to realize the effect of selecting files
C language calls the file browser to realize the effect of selecting files
2022-07-19 06:08:00 【Shining uncle】
c A program written in a language , Want to call the file browser of the system , Realize the effect of selecting files , You can use the following code
#include <ShlObj.h>
#include <windows.h>
TCHAR szPathName[MAX_PATH];
BROWSEINFO bInfo = {
0 };
bInfo.hwndOwner = GetForegroundWindow();// The parent window
bInfo.lpszTitle = TEXT(" Browse folders ");
//bInfo.pidlRoot=CSIDL_DRIVES;
bInfo.ulFlags = BIF_BROWSEINCLUDEFILES |BIF_EDITBOX/*| BIF_USENEWUI/* Contains an edit box Users can fill in the path manually The dialog box can be resized and so on ..*/ |
BIF_UAHINT/* belt TIPS Tips */ | BIF_NONEWFOLDERBUTTON/* Without the new folder button */;
LPITEMIDLIST lpDlist;
lpDlist = SHBrowseForFolder(&bInfo);
if (lpDlist != NULL)
{
SHGetPathFromIDList(lpDlist,szPathName);
MessageBox(NULL, szPathName, L"Dir Name", MB_OK);
// printf("%s",bInfo.pszDisplayName);
}
else
{
printf("user cancle\n");
}
Which USES BROWSEINFO structure
●BROWSEINFO Structure definition
typedef struct_browseinfo
{
undefined
HWND hwndOwner;
LPCITEMIDLIST pidlRoot;
LPSTR pszDisplayName;
LPCSTR lpszTitle;
UINT ulFlags;
BFFCALLBACK lpfn;
LPARAM lParam;
int iImage;
}BROWSEINFO,*PBROWSEINFO,*LPBROWSEINFO;
● BROWSEINFO Structure member variables
hwndOwner: Browse folder dialog parent Form handle .
pidlRoot:ITEMIDLIST Address of structure , Contains the initial root directory when browsing , And only the specified directory and its subdirectories are displayed in the Browse Folder dialog box . The Member variables can be NULL, At this time, the desktop directory will be used .
pszDisplayName: The memory address used to save the directory string selected by the user . The size of the buffer is defined by default MAX_PATH Constant macros .
lpszTitle: The displayed text of the Browse Folder dialog , Functions used to prompt the Browse Folder dialog 、 Role and purpose .
ulFlags: This flag bit describes the options of the dialog . It can be 0, It can also be the following Any combination of constants :
BIF_BROWSEFORCOMPUTER: Return computer name . Unless the user selects a computer name in the browser , Otherwise “OK” The button is gray .
BIF_BROWSEFORPRINTER: Return the printer name . Unless you select a printer name , otherwise “OK” The button is gray .
BIF_BROWSEINCLUDEFILES: The browser will display the directory , It also shows the file .
BIF_DONTGOBELOWDOMAIN: In the tree window , Does not include the network directory structure under the domain name .
BIF_EDITBOX: The browse dialog box contains an edit box , In this edit box, the user can enter the name of the selected item .
BIF_RETURNFSANCESTORS: Return to a node of the file system . Only when the selected node is a meaningful node ,“OK” Button can be used .
BIF_RETURNONLYFSDIRS: Just return the directory of the file system . for example : In the Browse Folder dialog , When any directory is selected , The “OK” Button available , And when selected “ My computer ” or “ Online neighbors ” When waiting for non meaningful nodes ,“OK” The button is gray .
BIF_STATUSTEXT: Include a status area in the dialog . Send a message to the dialog box to make The callback function sets the status text .
BIF_VALIDATE: When there is no BIF_EDITBOX When the flag bit , This flag bit is ignored . If the name entered by the user in the edit box is illegal , The browse dialog will send BFFM_VALIDATEFAILED Message to callback function .
lpfn: Application defined browse dialog The address of the callback function . When the event in the dialog box occurs , The dialog will call Callback function . This parameter can be used as NULL.
lParam: The dialog box is passed to A parameter of the callback function The pointer .
iImage: Images related to the selected directory . The image will be specified as the index value in the system image list .
边栏推荐
猜你喜欢

DSL实现自动补全查询

解决:无法加载文件 C:\Program Files\.. 因为在此系统上禁止运行脚本...

简单Chrome脚本 自动跳过b站视频播放结束后的的充电鸣谢页面

设置索引库结构,给用户添加可自动补全的suggestion,并将一些字段变成集合放到suggestion里面去

【力扣】另一棵树的子树

Chrome浏览器设置 【显示右上角 翻译语言图标】

【力扣】环形链表 II

Wireless charging mouse pad RGB LED lighting wireless charging mouse pad

2021-11-26 pyautogui cooperates with lightning simulator to realize the automation of mobile app check-in and answer questions

Thermal resistance PT100 cu50 isolation converter to 4-20mA analog output temperature transmitter 0-10V
随机推荐
计算几何(2)
Thermal resistance PT100 cu50 isolation converter to 4-20mA analog output temperature transmitter 0-10V
2021-11-26 pyautogui cooperates with lightning simulator to realize the automation of mobile app check-in and answer questions
2021-09-15
Hm9922 switching buck LED constant current driver IC
[bjoi2019] platoon formation (Group backpack)
[transfer] Darwin streaming server core code analysis
Guess The String (二分,交互)
索引库中的文档的操作
2022/07/14 学习笔记 (day07)数组
Baby Ehab Partitions Again(dp,构造,位运算)
mapping索引属性 & 创建索的操作
Ehab the Xorcist (异或性质,构造)
Rs-485/232 to 4-20ma/0-10v isolated d/a converter
【力扣】用队列实现栈
BusyBox 1.21.1 有udpsvd功能 可以编译成功 不干涉本机busybox方法
filezilla传输虚拟机速度慢解决方法
[antdv: Each record in table should have a unique `key` prop,or set `rowKey` to an unique.....
Addition and subtraction of busybox date time
Fs68001 wireless charging SOC chip has simple periphery and schematic diagram of 5W wireless charging scheme