强制SHBrowseForFolder()显示所需目录 [英] force SHBrowseForFolder() to show desired directory
问题描述
我一直在网上搜索并为这个问题进行了一个多小时的战斗,但似乎仍然无法正常工作。大多数人在论坛等上获得这种帮助时似乎都感到满意。但是我的仍然无法使用。
我试图强制SHBrowseForFolder()函数在我选择的文件夹中启动。
I've been searching online and fighting this thing for over an hour and still can't seem to get it to work. Most people seem to be satisfied when they get it this far on forums etc. but mine still doesn't work. I'm trying to force the SHBrowseForFolder() function to start in a folder of my choosing.
char current[MAX_PATH];
strcpy(current,"C:\\Users");
char outbuf[MAX_PATH];
BROWSEINFO bis;
bis.hwndOwner = NULL;
bis.pidlRoot = NULL;
bis.pszDisplayName = outbuf;
bis.lpszTitle = (LPCSTR)"HERE";
bis.ulFlags = BIF_NEWDIALOGSTYLE|BIF_RETURNONLYFSDIRS;
bis.lpfn = NULL;
bis.lParam = (LPARAM)current;
SHBrowseForFolder(
&bis
);
似乎这应该是一个相对简单的任务。 :/
目前,以上代码仍显示默认值:Desktop文件夹。
除了从特定文件夹开始之外,如果可能的话,我还希望它仅显示该文件夹及其下面的文件夹,而不能访问父目录。
It seems like this should be a relatively simple task. :/ At the moment, the above code is still showing the default: the Desktop folder. Beyond starting in a specific folder, if possible, I'd also like it to ONLY show that folder and below, with no access to parent directories.
我在这里错过了什么?
推荐答案
您还可以发送 BFFM_SETSELECTION
来自您的 BrowseCallbackProc
的消息,例如:
You can also send a BFFM_SETSELECTION
message from your BrowseCallbackProc
, like:
int FAR PASCAL BrowseNotify(HWND hWnd, UINT iMessage, long wParam, LPARAM lParam)
{ if (iMessage == BFFM_INITIALIZED)
{ SendMessage(hWnd, BFFM_SETSELECTION, 1, (LPARAM) szInitialPathName); // Set initial folder
return 1;
}
return 0;
}
这篇关于强制SHBrowseForFolder()显示所需目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!