Make a dialog box for selecting folders in VC

xiaoxiao2021-03-06  27

There are no ready-made functions in the VC to select a folder, but this is often used, what should I do?

Automatic hands, full of clothing!

Using ShbrowseForfolder, the code is as follows:

#include

Int Selfolder (HWND HParent, CString & Strfolder)

{

Strfolder.empty ();

LPMalloc LPMalloc;

IF (: shgetmalloc)! = noerror) Return 0;

Char szdisplayname [_max_path];

Char szbuffer [_MAX_PATH];

Browseinfo Browseinfo;

Browseinfo.hwndowner = hparent;

Browseinfo.pidlroot = null; // set root at desktop

Browseinfo.pszdisplayName = szdisplayName;

Browseinfo.lpsztitle = "SELECT A FOLDER";

Browseinfo.ulflags = bif_returnfsancestors | Bif_Returnonlyfsdirs;

Browseinfo.lpfn = null;

Browseinfo.lparam = 0;

LPITEMIDLIST LPITEMIDLIST;

IF ((LPITEMIDLIST =: ShbrowseForfolder (& BrowseInfo))! = null)

{

// get the path of the selected folder from the itemid.

IF (: ShgetPathfromidList (LPITEMIDLIST, SZBuffer)

{

// at this point, szbuffer contains the path the user chose.

IF (SZBuffer [0] == '/ 0') Return 0;

// We Have a path in szbuffer! Return IT.

Strfolder = szbuffer;

Return 1;

}

Else Return 1; // Strresult IS Empty

LPMalloc-> Free (LPITEMIDLIST);

LPMALLOC-> Release ();

}

Return 1;

}

转载请注明原文地址:https://www.9cbs.com/read-76706.html

New Post(0)