Encapsulation in the Select File Dialog Box

Source: Internet
Author: User

We often need to use the "select folder" dialog box. The corresponding API is very useful, but it is a little troublesome. So I encapsulated it specifically and tried to get it in one step.

The function is encapsulated as follows:
/*************************************** **************************
** Function name: getpath
** Input: None
** Output: cstring strpath
** The strpath is not empty, indicating the folder path selected by the user
** If strpath is empty, the user clicks the "cancel" key to cancel the selection.
** Function Description: The "select folder" dialog box is displayed, allowing users to select folders.
**************************************** ************************/

Cstring getpath ()
{
Cstring strpath = "";
Browseinfo binfo;
Zeromemory (& binfo, sizeof (binfo ));
Binfo. hwndowner = m_hwnd;
Binfo. lpsztitle = _ T ("select the path :");
Binfo. ulflags = bif_returnonlyfsdirs;
 
Lpitemidlist lpdlist; // The idlist used to save the returned information
Lpdlist = shbrowseforfolder (& binfo); // display the selection dialog box
If (lpdlist! = NULL) // The user presses the OK button.
{
Tchar chpath [255]; // string used to store the path
Shgetpathfromidlist (lpdlist, chpath); // converts the Project ID list to a string.
Strpath = chpath; // convert a tchar string to a cstring.
}
Return strpath;
}

You only need to use the followingCode:
Cstring strpath = getpath ();
Then, strpath is the selected folder path. If you click the cancel key in the dialog box, strpath is a null string ("");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.