Shgetfileinfo function details

Source: Internet
Author: User

Shgetfileinfo Function

WINSHELLAPI DWORD WINAPI SHGetFileInfo(    LPCTSTR pszPath,    DWORD dwFileAttributes,    SHFILEINFO FAR *psfi,    UINT cbFileInfo,    UINT uFlags);

Pszpath: Specifies the file name.
When the uflags value does not contain shgfi_pidl, you can directly specify it;
When the uflags value contains shgfi_pidl, pszpath must be calculated and cannot be specified directly;

Dwfileattributes parameter: file attribute.
This parameter is valid only when the uflags value contains shgfi_usefileattributes;

Psfi parameter: The file information returned. It is a record type and has the following fields:
_ Shfileinfoa = record
Hicon: hicon; {out: icon} // file icon handle
Iicon: integer; {out: icon index} // system index of the icon
Dwattributes: DWORD; {out: sfgao _ flags} // File Attribute Value
Szdisplayname: array [0 .. MAX_PATH-1] of ansichar; {out: Display name (or path)} // display name of the file
Sztypename: array [0 .. 79] of ansichar; {out: type name} // file type name
End;

Cbfileinfo parameter: bit value of psfi;

Uflags parameter: Specifies the identifier of the file information to be returned. The following constants are commonly used:
Shgfi_icon; // get the icon
Shgfi_displayname; // obtain the display name
Shgfi_typename; // obtain the type name
Shgfi_attributes; // get attributes
Shgfi_largeicon; // get the big icon
Shgfi_smallicon; // get the small icon
Shgfi_pidl; // pszpath is an identifier.
The Return Value of the shgetfileinfo () function varies with the value of uflags.

You can call shgetfileinfo () to obtain the file icon handle by using the psfi parameter. Note that when shgfi_pidl is not used in the uflags parameter, shgetfileinfo () cannot obtain information such as "My Computer" and other virtual folders.
Before calling shgetfileinfo (), you must use coinitialize or oleinitialize to initialize COM. For example, a common example: if you do not compile the compose, you can call the icons of the .htm/. MHT/. xml file without authorization.
The following are two examples:

1. Obtain the System icon list:
// Retrieve the System icon list
Uses
Shellapi
VaR
Imagelisthandle: thandle;
Fileinfo: tshfileinfo;
// Small icon
Imagelisthandle: = shgetfileinfo ('C :/',
0,
Fileinfo,
Sizeof (fileinfo ),
Shgfi_sysiconindex or shgfi_smallicon );
// Associate the icon list with a small icon of the listview1 listview control.
Sendmessage (listview1.handle, lvm_setimagelist, lvsil_small, imagelisthandle );
// Large icon
Imagelisthandle: = shgetfileinfo ('C :/',
0,
Fileinfo,
Sizeof (fileinfo ),
Shgfi_sysiconindex or shgfi_largeicon );
// Associate the large icon of the listview control with listview1 in the icon list.
Sendmessage (listview1.handle, lvm_setimagelist, lvsil_normal, imagelisthandle );

2. Get the display name and icon of a file
VaR
SFI: tshfileinfo;
Iconindex: integer;
// Retrieve the index number and other information of the icon
Shgetfileinfo (pansichar (filename ),
0,
SFI,
Sizeof (tshfileinfo ),
Shellapi. shgfi_displayname or shellapi. shgfi_typename or shellapi. shgfi_largeicon or shellapi. shgfi_icon );
// The display name and Icon number in the System icon list are in SFI. szdisplayname and SFI. iicon respectively.

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.