To determine Windows desktop and other directories

Source: Internet
Author: User

Shgetspecialfolder using API functions. Shlobj.h has Shgetspecialfolder's prototype statement. This function can help us find the Windows Desktop directory, startup directory, my document directory, and so on.

Shgetspecialfolder requires three parameters. The first argument is the HWND, which specifies the owner window: a dialog box or message box that may appear when the function is called. The second argument is an integer ID that determines which directory is to be found, and its value may be:

Csidl_bitbucket Recycle Bin

Csidl_controls Control Panel

Csidl_desktop Windows Desktop DESKTOP

Directory of Csidl_desktopdirectory Desktop

Csidl_drives My Computer.

Csidl_fonts Font Directory

Csidl_nethood Network Neighborhood

Csidl_network Network Neighborhood Virtual folder

Csidl_personal My Documents

Csidl_printers Printer

Csidl_programs program Group

Csidl_recent Most recently opened documents are listed in one

Csidl_sendto "Send to" menu item

Csidl_startmenu task bar Start menu item

Csidl_startup Startup directory

Csidl_templates Temporary Document

The last parameter is the PIDL address. SHGetSpecialFolderLocation wrote the address to Pidl.

The following code shows how to use shgetspecialfolderlocation:

//----------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
LPITEMIDLIST pidl;
LPMALLOC pShellMalloc;
char szDir[MAX_PATH];
if(SUCCEEDED(SHGetMalloc(&pShellMalloc)))
{
if(SUCCEEDED(SHGetSpecialFolderLocation(NULL,
CSIDL_DESKTOPDIRECTORY,
&pidl)))
{
// 如果成功返回true
if(SHGetPathFromIDList(pidl, szDir))
{
Label1->Caption = szDir;
}
pShellMalloc->Free(pidl);
}
pShellMalloc->Release();
}
}
//----------------------------------------------------------------------

Note: Some directories are empty. Some specific directories do not have a corresponding directory on this filesystem.

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.