Set the default folder for shbrowseforfolder

Source: Internet
Author: User

Shbrowseforfolder is a Windows Shell function that can be viewed in a directory. Its prototype is:
Lpitemidlist shbrowseforfolder (lpbrowseinfolpbi );

The parameter lpbi is a pointer to the structure browseinfo. The structure is defined as follows:

Typedef struct _ browseinfo {
Hwnd hwndowner;
Lpcitemidlist pidlroot; // points to an item identifier list pointer and sets the default directory for browsing.
Lptstr pszdisplayname;
Lpctstr lpsztitle; // you can use this variable to indicate the title of the browser dialog box.
Uint ulflags;
Bffcallback lpfn; // callback function address, that is, the window process based on the browser dialog box
Lparam;
Int iimage;
} Browseinfo, * pbrowseinfo, * lpbrowseinfo; The broseinfo prototype shows that it is difficult to set a default directory. You can set bif_validate in ulflags and set a callback function to process the bffm_initialized message (this message indicates that the dialog box is ready for calling ), when processing the message, sendmessage A bffm_setselection message is sent to the window, and the string of the initial directory is passed as the lparam parameter. the following code sets the initial directory to "C:/program filese "......
If (umsg = bffm_initialized)
{
Sendmessage (hwnd, bffm_setselection, true, (lparam) _ T ("C: // Program Files "));
}
... The following is an example in VC ++. NET 2003.
# Include <shlobj. h> // shbrowseforfolder defined in shlobj. h
# Include <tchar. h>
# Include <windows. h> int callback browsecallbackproc (hwnd, uint umsg, lparam, lparam lpdata)
{
If (umsg = bffm_initialized)
{
Sendmessage (hwnd, bffm_setselection,
True, (lparam) _ T ("C: // Program Files "));
}
Return 0;
} Void showshbrowseforfolderdemodlg ()
{
Tchar m_dir [500];
Browseinfo Bi = {0 };
Bi. ulflags = bif_newdialogstyle | bif_returnonlyfsdirs | bif_validate;
Bi. lpsztitle = _ T ("select the location where the computing result file is saved ");
Bi. lpfn = browsecallbackproc; // specify the callback function address.
Itemidlist * pidl = shbrowseforfolder (& BI );
If (shgetpathfromidlist (pidl, m_dir) = true) // The complete path of the selected directory is stored in the m_dir variable.
{
MessageBox (null, m_dir, "sample", 0 );
}
} Int winapi winmain (hinstance, hinstance hprevinstance, lpstr szcmdline, int icmdshow)
{
Showshbrowseforfolderdemodlg ();
Return 0;
}

 

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.