SHBrowseForFolder

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/dong1528313271/article/details/80788138
typedef struct _browseinfoW {
    HWND        hwndOwner;              //父窗口句柄
    PCIDLIST_ABSOLUTE pidlRoot;     //要显示的文件夹的根
    LPWSTR       pszDisplayName;        // Return display name buffer of item selected.
    LPCWSTR      lpszTitle;             // text to go in the banner over the tree.
    UINT         ulFlags;               // 对话框外观和功能的标志参数
    BFFCALLBACK  lpfn;              //处理事件的回调函数
    LPARAM       lParam;                // extra info that's passed back in callbacks
    int          iImage;                // output var: where to return the Image index.
} BROWSEINFOW, *PBROWSEINFOW, *LPBROWSEINFOW;

#define BROWSEINFO      BROWSEINFOW

Paramter:            

ulFlag:

// Browsing for directory.
#define BIF_RETURNONLYFSDIRS    0x00000001  // For finding a folder to start document searching
#define BIF_DONTGOBELOWDOMAIN   0x00000002  // For starting the Find Computer
#define BIF_STATUSTEXT          0x00000004   // Top of the dialog has 2 lines of text for BROWSEINFO.lpszTitle and one line if
                                        // this flag is set.  Passing the message BFFM_SETSTATUSTEXTA to the hwnd can set the
                                        // rest of the text.  This is not used with BIF_USENEWUI and BROWSEINFO.lpszTitle gets
                                        // all three lines of text.
#define BIF_RETURNFSANCESTORS   0x00000008
#define BIF_EDITBOX             0x00000010   // Add an editbox to the dialog
#define BIF_VALIDATE            0x00000020   // insist on valid result (or CANCEL)

#define BIF_NEWDIALOGSTYLE      0x00000040   // Use the new dialog layout with the ability to resize
                                        // Caller needs to call OleInitialize() before using this API

#define BIF_USENEWUI            (BIF_NEWDIALOGSTYLE | BIF_EDITBOX)

#define BIF_BROWSEINCLUDEURLS   0x00000080   // Allow URLs to be displayed or entered. (Requires BIF_USENEWUI)
#define BIF_UAHINT              0x00000100   // Add a UA hint to the dialog, in place of the edit box. May not be combined with BIF_EDITBOX
#define BIF_NONEWFOLDERBUTTON   0x00000200   // Do not add the "New Folder" button to the dialog.  Only applicable with BIF_NEWDIALOGSTYLE.
#define BIF_NOTRANSLATETARGETS  0x00000400   // don't traverse target as shortcut

#define BIF_BROWSEFORCOMPUTER   0x00001000  // Browsing for Computers.
#define BIF_BROWSEFORPRINTER    0x00002000  // Browsing for Printers
#define BIF_BROWSEINCLUDEFILES  0x00004000  // Browsing for Everything
#define BIF_SHAREABLE           0x00008000  // sharable resources displayed (remote shares, requires BIF_USENEWUI)
#define BIF_BROWSEFILEJUNCTIONS 0x00010000  // allow folder junctions like zip files and libraries to be browsed


#define PCIDLIST_ABSOLUTE
#define PCIDLIST_ABSOLUTE        LPCITEMIDLIST
typedef /* [wire_marshal] */ const ITEMIDLIST __unaligned *LPCITEMIDLIST;

typedef struct _ITEMIDLIST
    {
    SHITEMID mkid;
}   ITEMIDLIST;

typedef struct _SHITEMID
    {
    USHORT cb;
    BYTE abID[ 1 ];
    }   SHITEMID;
  Windows Shell的一个功能在于管理并提供方法存取系统中的众多对像,這些对像包括了文件,网路上的计算机,控制面板程序,回收站等等,为了识别每一个对像,Windows Shell使用了Item ID来表示它們,而Iten ID Lists用来表示一个对像的路径。所以,ITEMID和ITEMIDLIST的关系类似于文件名和路径的关系。如果只对文件系统而言的话,ITEMIDLIST可以看成是路径的另一中表示法,Windows Shell也提供了函数來进行转化。



用SHBrowseFolder获取结构体:LPCITEMIDLIST
然后通过SHGetPathFromIDList来取出获取的路径信息

、、、、实例尽量简单点吧

//environment: vs2013
//date:2018.6.23
//win32.project


#include<windows.h>
#include<Shlobj.h >


void SelectFolder(TCHAR szBuff[128])
{
    BROWSEINFO browseinfo = { 0 }; 
    LPITEMIDLIST pidl;
    browseinfo.lpszTitle = L"en";
    pidl = SHBrowseForFolder(&browseinfo);
    SHGetPathFromIDList(pidl, szBuff);


}


int WINAPI WinMain(HINSTANCE prehistance, HINSTANCE hinstance, LPSTR str, int showCmd)
{

    TCHAR szBuffer[128];
    SelectFolder(szBuffer);
    MessageBox(NULL, szBuffer, L"", MB_OK);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/dong1528313271/article/details/80788138