基于VC2005 MFC对话框工程,//定义全局变量
CImageList m_imagelist;//在OnInitDialog里面添加以下代码
m_imagelist.Create(16, 16, ILC_COLOR32 | ILC_MASK, 2, 1);
m_list.SetImageList(&m_imagelist, LVSIL_SMALL);//显示代码
void CShowIcoDlg::show(void)
{
DWORD dwQQ = GetProcessIdByName(L"QQ.exe");
DWORD dwExplorer= GetProcessIdByName(L"explorer.exe");
CString strQQPath = GetProcPath(dwQQ);
CString strExplorerPath = GetProcPath(dwExplorer); SHFILEINFO sfi;
ZeroMemory(&sfi,sizeof(SHFILEINFO)); SHGetFileInfo(strQQPath,0,&sfi,sizeof(SHFILEINFO),SHGFI_ICON);
HICON hSmallIco = sfi.hIcon;
int i = m_imagelist.Add(hSmallIco);
m_list.InsertItem(i,L"QQ.EXE");
m_list.SetItemText(i,1,strQQPath);
DestroyIcon(hSmallIco); ZeroMemory(&sfi,sizeof(SHFILEINFO));
SHGetFileInfo(strExplorerPath,0,&sfi,sizeof(SHFILEINFO),SHGFI_ICON);
HICON hFFIco = sfi.hIcon;
int j = m_imagelist.Add(hFFIco);
m_list.InsertItem(j,L"Explorer.EXE");
m_list.SetItemText(j,1,strExplorerPath);
DestroyIcon(hFFIco);
}