#define WIN32_LEAN_AND_MEAN
#include <list>
#include <afxwin.h>
#include <stdio.h>
#include <windows.h>
#include <commctrl.h>
#include <tchar.h>
#include <iostream>
#include <atlstr.h>
#include "shlobj.h"
#include <CommonControls.h>
#include <CString>
using namespace std;
#include "QtGuiApplication1.h"
#include <QFileInfo>
#include <QFileIconProvider>
#include <QStandardPaths>
#include <QDir>
#include <QtWin>
typedef struct tagLVITEM64
{
UINT mask;
int iItem;
int iSubItem;
UINT state;
UINT stateMask;
_int64 pszText;
int cchTextMax;
int iImage;
_int64 lParam;
#if (_WIN32_IE >= 0x0300)
int iIndent;
#endif
#if (_WIN32_WINNT >= 0x0501)
int iGroupId;
UINT cColumns;
_int64 puColumns;
#endif
#if _WIN32_WINNT >= 0x0600
_int64 piColFmt;
int iGroup;
#endif
} LVITEM64;
QtGuiApplication1::QtGuiApplication1(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
CoInitialize(NULL);
LPITEMIDLIST lpItemIDList;
SHFILEINFO shinfo;
TCHAR szPath[MAX_PATH];
::SHGetSpecialFolderLocation(NULL, CSIDL_DRIVES, &lpItemIDList);
::SHGetFileInfo((LPCTSTR)lpItemIDList, NULL, &shinfo, sizeof(shinfo),
SHGFI_SYSICONINDEX | SHGFI_DISPLAYNAME | SHGFI_ICON | SHGFI_SMALLICON | SHGFI_PIDL);
::SHGetPathFromIDList(lpItemIDList, szPath);
CString strDisplayName, strPath;
strDisplayName.Format(_T("%s"), shinfo.szDisplayName);
strPath.Format(_T("%s"), szPath);
strPath = strPath ;
AfxMessageBox(strPath);
SHFILEINFO sfi;
SHGetFileInfo(strPath, -1, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX);
IImageList* imageList;
HRESULT hResult = SHGetImageList(SHIL_EXTRALARGE, IID_IImageList, (void**)&imageList);
if (hResult == S_OK)
{
HICON hIcon;
hResult = (imageList)->GetIcon(sfi.iIcon, ILD_IMAGE | ILD_PRESERVEALPHA, &hIcon);
if (hResult == S_OK)
{
QPixmap pixmap;
pixmap = QtWin::fromHICON(hIcon);
ui.label->setPixmap(pixmap);
}
}
CoUninitialize();
}
转载请注明原文地址: https://www.6miu.com/read-83403.html