int main(int argc, char *argv[]) { QGuiApplication a(argc, argv); QStringList arguments = QCoreApplication::arguments(); arguments.pop_front(); const bool large = !arguments.isEmpty() && arguments.front() == "-l"; if (large) arguments.pop_front(); if (arguments.size() < 1) { std::cout << "Usage: iconextractor [OPTIONS] FILE [IMAGE_FILE_FOLDER]\n\n" "Extracts Windows icons from executables, DLL or icon files\n" "and writes them out as numbered .png-files.\n\n" "Options: -l Extract large icons.\n\n" "Based on Qt " << QT_VERSION_STR << "\n"; return 1; } const QString sourceFile = arguments.at(0); QString imageFileRoot = arguments.size() > 1 ? arguments.at(1) : QDir::currentPath(); const QFileInfo imageFileRootInfo(imageFileRoot); if (!imageFileRootInfo.isDir()) { std::cerr << imageFileRoot.toStdString() << " is not a directory.\n"; return 1; } const UINT iconCount = ExtractIconEx((wchar_t *)sourceFile.utf16(), -1, 0, 0, 0); if (!iconCount) { std::cerr << sourceFile.toStdString() << " does not appear to contain icons.\n"; return 1; } QScopedArrayPointer<HICON> icons(new HICON[iconCount]); const UINT extractedIconCount = large ? ExtractIconEx((wchar_t *)sourceFile.utf16(), 0, icons.data(), 0, iconCount) : ExtractIconEx((wchar_t *)sourceFile.utf16(), 0, 0, icons.data(), iconCount); if (!extractedIconCount) { qErrnoWarning("Failed to extract icons from %s", qPrintable(sourceFile)); return 1; } std::cout << sourceFile.toStdString() << " contains " << extractedIconCount << " icon(s).\n"; imageFileRoot = imageFileRootInfo.absoluteFilePath() + QLatin1Char('/') + QFileInfo(sourceFile).baseName(); for (UINT i = 0; i < extractedIconCount; ++i) { const QPixmap pixmap = QtWin::fromHICON(icons[i]); if (pixmap.isNull()) { std::cerr << "Error converting icons.\n"; return 1; } const QString fileName = QString::fromLatin1("%1%2.png").arg(imageFileRoot) .arg(i, 3, 10, QLatin1Char('0')); if (!pixmap.save(fileName)) { std::cerr << "Error writing image file " << fileName.toStdString() << ".\n"; return 1; } std::cout << "Wrote image file " << QDir::toNativeSeparators(fileName).toStdString() << ".\n"; } return 0; }
wxIcon* IconGetter::GetExecutableIcon(const wxString& filePath, int iconSize) { #ifdef __WIN32__ HICON smallIcon; HICON largeIcon; int result; if (iconSize == 16) { result = ExtractIconEx(filePath.c_str(), 0, NULL, &smallIcon, 1); } else { result = ExtractIconEx(filePath.c_str(), 0, &largeIcon, NULL, 1); } // If the function succeeds, the return value is the handle to an icon. // If the file specified was not an executable file, DLL, or icon file, // the return value is 1. If no icons were found in the file, the return // value is NULL. If the file didn't exist, the return value is < 0 if (result > 0) { wxIcon* icon = new wxIcon(); if (iconSize == 16) { icon->SetHICON((WXHICON)smallIcon); icon->SetSize(16, 16); } else { icon->SetHICON((WXHICON)largeIcon); icon->SetSize(32, 32); } return icon; } #endif // __WIN32__ return NULL; }
void ApplicationListDlg::InsertProgram(LPTSTR filename, int value, int idx) { LVITEM item; HICON appicon; //Load the icon for this application if (ExtractIconEx(filename, 0, NULL, &appicon, 1)) { item.iImage = ImageList_AddIcon(m_hImgList, appicon); DestroyIcon(appicon); } else item.iImage = m_defaultIconIdx; //Insert the new item item.mask = LVIF_TEXT | LVIF_IMAGE; item.pszText = filename; item.iItem = idx == -1 ? ListView_GetItemCount(m_hAppListWnd) : idx; item.iSubItem = 0; if (idx == -1) idx = ListView_InsertItem(m_hAppListWnd, &item); else ListView_SetItem(m_hAppListWnd, &item); //Set the value SetProgramParam(idx, value); }
const Icon& IconCache::extract(LPCTSTR path, int icon_idx, ICONCACHE_FLAGS flags) { IdxCacheKey key(path, make_pair(icon_idx, (flags|ICF_HICON)&~ICF_SYSCACHE)); key.first.toLower(); IdxCacheMap::iterator found = _idxCache.find(key); if (found != _idxCache.end()) return _icons[found->second]; HICON hIcon; if ((int)ExtractIconEx(path, icon_idx, NULL, &hIcon, 1) > 0) { const Icon& icon = add(hIcon, IT_CACHED); _idxCache[key] = icon; return icon; } else { ///@todo retreive "http://.../favicon.ico" format icons return _icons[ICID_NONE]; } }
// DestroyIcon() the return value HICON LoadRegClassSmallIcon(const char *pszClassName) { HICON hIcon=NULL; HKEY hClassKey,hIconKey; TCHAR *pszIconLoc,*p; /* using the merged view classes key for reading */ /* class */ if (!RegOpenKeyExA(HKEY_CLASSES_ROOT,pszClassName,0,KEY_QUERY_VALUE,&hClassKey)) { /* default icon */ if (!RegOpenKeyEx(hClassKey,_T("DefaultIcon"),0,KEY_QUERY_VALUE,&hIconKey)) { /* extract icon */ pszIconLoc=GetRegStrValue(hIconKey,NULL); if (pszIconLoc!=NULL) { p=_tcsrchr(pszIconLoc,_T(',')); if (p!=NULL) { *(p++)=0; ExtractIconEx(pszIconLoc,_ttoi(p),NULL,&hIcon,1); } mir_free(pszIconLoc); } RegCloseKey(hIconKey); } RegCloseKey(hClassKey); } return hIcon; }
/* * menu_read_icon - アイコン取得 */ static HICON menu_read_icon(const TCHAR *file_name, const int index, const int icon_size) { SHFILEINFO shfi; HICON hIcon = NULL; HICON hsIcon = NULL; int icon_flag; if (file_name == NULL || *file_name == TEXT('\0')) { return NULL; } // ファイルからアイコン取得 ExtractIconEx(file_name, index, &hIcon, &hsIcon, 1); if (icon_size >= LICONSIZE) { DestroyIcon(hsIcon); } else { DestroyIcon(hIcon); hIcon = hsIcon; } if (hIcon == NULL) { // 関連付けからアイコン取得 icon_flag = SHGFI_ICON | ((icon_size == SICONSIZE) ? SHGFI_SMALLICON : SHGFI_LARGEICON); SHGetFileInfo(file_name, SHGFI_USEFILEATTRIBUTES, &shfi, sizeof(SHFILEINFO), icon_flag); hIcon = shfi.hIcon; } return hIcon; }
TopMenu::TopMenu() : m_thread(NULL) , m_stopEvent(CreateEvent(NULL, TRUE, FALSE, NULL)) { BOOL b; DWORD d; TopMenu_CSLock lock(s_cs); InterlockedIncrement((long*)&shared_instanceCount); WNDCLASS wndClass; ZeroMemory(&wndClass, sizeof(wndClass)); wndClass.lpszClassName = "TrayIconMonitor"; wndClass.hInstance = (HINSTANCE)&__ImageBase; wndClass.lpfnWndProc = TrayIconProc; d=RegisterClass(&wndClass); ASSERT(d != 0); char exePath[MAX_PATH]; d=GetModuleFileName(NULL, exePath, sizeof(exePath)); ASSERT(d != 0); d=ExtractIconEx(exePath, 0, NULL, &m_hProgIcon, 1); ASSERT(d == 1); ASSERTE(m_stopEvent); m_thread = CreateThread(NULL, 0, &TopMenu::beginRun, this, 0, NULL); ASSERTE(m_thread); if(!m_thread) { b=SetEnvironmentVariable("TopMenu_Plugin", "Loaded - cannot start monitor thread"); ASSERT(b); //lint !e534 JLD } else { b=SetEnvironmentVariable("TopMenu_Plugin", "Loaded"); ASSERT(b); //lint !e534 JLD } ASSERTE(!s_pInstance); s_pInstance = this; }
UINT _ExtractIconEx(LPCTSTR lpszFile, int iconIndex, int cxIcon, int cyIcon, HICON *phicon, UINT flags) { HANDLE hFile; WORD magic[6]; DWORD read = 0; UINT res = 0; if (cxIcon == GetSystemMetrics(SM_CXICON) && cyIcon == GetSystemMetrics(SM_CYICON)) res = ExtractIconEx(lpszFile, iconIndex, phicon, NULL, 1); else if (cxIcon == GetSystemMetrics(SM_CXSMICON) && cyIcon == GetSystemMetrics(SM_CYSMICON)) res = ExtractIconEx(lpszFile, iconIndex, NULL, phicon, 1); else if (cxIcon == 0 || cyIcon == 0) res = ExtractIconEx(lpszFile, iconIndex, NULL, phicon, 1); // check if the api succeded, if not try our method too if (res) return res; hFile = CreateFile(lpszFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (hFile == INVALID_HANDLE_VALUE) return 0; // failed to read file signature if (!ReadFile(hFile, &magic, sizeof(magic), &read, NULL) || (read != sizeof(magic))) { CloseHandle(hFile); return 0; } switch (magic[0]) { case IMAGE_DOS_SIGNATURE: res = _ExtractFromExe(hFile, iconIndex, cxIcon, cyIcon, phicon, flags); break; case MAGIC_ANI1: // ani cursors are RIFF file of type 'ACON' if (magic[1] == MAGIC_ANI2 && magic[4] == MAGIC_ANI3 && magic[5] == MAGIC_ANI4) res = _ExtractFromICO(lpszFile, iconIndex, cxIcon, cyIcon, phicon, flags); break; case MAGIC_ICON: if ((magic[1] == MAGIC_ICO1 || magic[1] == MAGIC_CUR) && magic[2] >= 1) res = _ExtractFromICO(lpszFile, iconIndex, cxIcon, cyIcon, phicon, flags); break; } CloseHandle(hFile); return res; }
HICON ShellIcons::ExtractIcon(SHELLICON nIndex, bool bLarge) { HICON hIcon = NULL; // Shell icons can be customized by the registry: // HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Icons // "<ShellIconIndex>" = "<Filename>,<IconIndex>" // E.g. // "3" = "c:\MyFolderIcon.ico,1" HKEY hkeyShellIcons; if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Icons"), 0, KEY_READ, &hkeyShellIcons) == ERROR_SUCCESS) { TCHAR szBuffer[ MAX_PATH * sizeof TCHAR]; DWORD dwSize = MAX_PATH * sizeof TCHAR; TCHAR szIndex[6] = {0}; _stprintf (szIndex, _T("%d"), nIndex); if (RegQueryValueEx (hkeyShellIcons, szIndex, NULL, NULL, (LPBYTE)szBuffer, &dwSize) == ERROR_SUCCESS) { CString strFileName, strIndex; VERIFY (AfxExtractSubString (strFileName, szBuffer, 0, _T(','))); VERIFY (AfxExtractSubString (strIndex, szBuffer, 1, _T(','))); if (bLarge) ExtractIconEx(strFileName, _ttoi(strIndex), &hIcon, NULL, 1); else ExtractIconEx(strFileName, _ttoi(strIndex), NULL, &hIcon, 1); } RegCloseKey( hkeyShellIcons ); } // Not customized? Then get the original icon from shell23.dll if (!hIcon) { if (bLarge) ExtractIconEx(_T("SHELL32.DLL"), nIndex, &hIcon, NULL, 1); else ExtractIconEx(_T("SHELL32.DLL"), nIndex, NULL, &hIcon, 1); } return hIcon; }
// load small icon (not shared) it IS NEED to be destroyed HICON LoadSmallIcon(HINSTANCE hInstance, int index) { TCHAR filename[MAX_PATH] = { 0 }; GetModuleFileName(hInstance, filename, MAX_PATH); HICON hIcon = NULL; ExtractIconEx(filename, index, NULL, &hIcon, 1); return hIcon; }
static HICON LoadSmallIcon(HINSTANCE hInstance, LPCTSTR lpIconName) { HICON hIcon=NULL; // icon handle int index=-(int)lpIconName; TCHAR filename[MAX_PATH]={0}; GetModuleFileName(hInstance,filename,MAX_PATH); ExtractIconEx(filename,index,NULL,&hIcon,1); return hIcon; }
void MenuItem::DrawIcon(HDC hDC) { int size, px, py, d; /* if (m_ItemID & MENUITEM_ID_FOLDER) return; */ if (NULL == m_hIcon) { // if no icon yet, try to load it, either from explicit string // or from pidl_list if (m_pszIcon) { char path[MAX_PATH]; const char *p; int index; p = Tokenize(m_pszIcon, path, ","); index = 0; if (p) { index = atoi(p); if (index) --index; } unquote(path); ExtractIconEx(path, index, NULL, &m_hIcon, 1); } else if (m_pidl_list) { m_hIcon = sh_geticon(first_pidl(m_pidl_list), (Settings_menu.iconSize>16)?(32):(16)); } if (NULL == m_hIcon) return; } size = MenuInfo.nIconSize; d = (m_nHeight - size) / 2; px = m_nLeft + d; py = m_nTop + d; /* DrawIconEx(hDC, px, py, m_hIcon, size, size, 0, NULL, DI_NORMAL ); */ DrawIconSatnHue(hDC, px, py, m_hIcon, //size, size, 0, Settings_menu.iconSize, Settings_menu.iconSize, 0, /* BlackboxZero 1.4.2012 */ NULL, DI_NORMAL, //false == m_bActive, 40, 0 false == m_bActive, Settings_menu.iconSaturation, Settings_menu.iconHue /* BlackboxZero 1.3.2012 */ ); }
// load small icon (not shared) it IS NEED to be destroyed static HICON LoadSmallIcon(HINSTANCE hInstance, LPCTSTR lpIconName) { TCHAR filename[MAX_PATH]; if (GetModuleFileName(hInstance, filename, MAX_PATH) == 0) return NULL; HICON hIcon = NULL; // icon handle int index = -(INT_PTR)lpIconName; ExtractIconEx(filename, index, NULL, &hIcon, 1); return hIcon; }
bool ExtractExeDllIcon(LPCTSTR strExeFile,LPCTSTR strSaveDir,bool bExtractLarge = false ,UINT iIndexICon = 0) { HICON hIconArry[1]={0}; UINT iSuccessCount = 0; if (bExtractLarge) iSuccessCount = ExtractIconEx(strExeFile,iIndexICon,hIconArry,NULL,1); else iSuccessCount = ExtractIconEx(strExeFile,iIndexICon,NULL,hIconArry,1); if (iSuccessCount!=1) { ZTools::WriteZToolsFormatLog("从文件【%s】中获取索引为【%d】的图标失败!",strExeFile,iIndexICon); return false; } string strName = GetFileNameNoExt(strExeFile); string strPngFile = string(strSaveDir) + "\\" + strName + ".png"; string strIconFile = string(strSaveDir) + "\\" + strName + ".ico"; BOOL bok1 = SavePngFile(hIconArry[0],strPngFile.c_str()); if (!bok1) { ZTools::WriteZToolsFormatLog("保存png文件【%s】失败!",strPngFile.c_str()); } BOOL bok2 = SaveIcon(hIconArry[0],strIconFile.c_str(),32); if (!bok2) { ZTools::WriteZToolsFormatLog("保存icon文件【%s】失败!",strIconFile.c_str()); } DestroyIcon(hIconArry[0]); if (bok1 && bok2) return true; return false; }
int Main(HINSTANCE hInstance) { WNDCLASSEX wcx; HWND wnd; MSG msg; if ((wnd = FindWindow(App.Class, App.Title)) != NULL) { /* reload config */ PostMessage(wnd, WM_APP_RELOAD, 0, 0); return 0; } CoInitializeEx(0, COINIT_MULTITHREADED); CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL); WinAPI_Initialize(); Global_Initialize(); Status_Initialize(); Config_Initialize(); SpecialKey_Initialize(); ExtractIconEx(AppIcon.File, IsVistaOrGreater() ? AppIcon.Index.Vista : AppIcon.Index.XP, &Global.hIconLarge, &Global.hIconSmall, 1); ZeroMemory(&wcx, sizeof wcx); wcx.cbSize = sizeof wcx; wcx.style = CS_NOCLOSE; wcx.lpfnWndProc = WndProc; wcx.hInstance = hInstance; wcx.hCursor = (HCURSOR)LoadImage(NULL, IDC_ARROW, IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE | LR_SHARED); wcx.lpszClassName = App.Class; wcx.hIcon = Global.hIconLarge; wcx.hIconSm = Global.hIconSmall; RegisterClassEx(&wcx); CreateWindowEx(0, wcx.lpszClassName, App.Title, WS_POPUP, CW_USEDEFAULT, 0, 10, 10, NULL, NULL, wcx.hInstance, NULL); while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } DestroyIcon(Global.hIconLarge); DestroyIcon(Global.hIconSmall); WinAPI_Uninitialize(); CoUninitialize(); return (int)msg.wParam; }
BOOL CShellExt::LoadMenuIcon() { char vimExeFile[BUFSIZE]; getGvimName(vimExeFile, 1); if (vimExeFile[0] == '\0') return FALSE; HICON hVimIcon; if (ExtractIconEx(vimExeFile, 0, NULL, &hVimIcon, 1) == 0) return FALSE; m_hVimIconBitmap = IconToBitmap(hVimIcon, GetSysColorBrush(COLOR_MENU), GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON)); return TRUE; }
LRESULT CTipDlg::OnInitDialog(UINT , WPARAM , LPARAM , BOOL &) { _Module.GetMessageLoop()->AddMessageFilter(this); //m_list = GetDlgItem(IDC_LIST); m_list.SubclassWindow(GetDlgItem(IDC_LIST)); m_list.SetExtendedListViewStyle(LVS_EX_FULLROWSELECT|LVS_EX_INFOTIP|LVS_EX_BORDERSELECT); m_list.AddColumn(L"", 0); m_list.SetColumnWidth(0, LVSCW_AUTOSIZE_USEHEADER); m_il.Create(16, 16, ILC_COLOR32 | ILC_MASK, 4, 4); m_il.SetBkColor(CLR_NONE); HBITMAP bmp = AtlLoadBitmap(IDB_UD); m_il.Add(bmp); DeleteObject(bmp); cfg::config * c = cfg::config::instance(); for (int i = 0; i < c->index_mgr.cs_count(); i++) { HICON icon = NULL; index_info *ii = c->get_index_info(i); if (!ii->icon.file.empty()) { std::wstring path = hlp::abs_path(ii->icon.file.c_str()); ExtractIconEx(path.c_str(), ii->icon.index, NULL, &icon, 1); if (icon == NULL) { icon = (HICON)LoadImage(NULL, path.c_str(), IMAGE_ICON, 16, 16, LR_LOADFROMFILE); } } if (icon == NULL) { bmp = AtlLoadBitmap(IDB_QUICK_LAUNCH); m_il.Add(bmp); DeleteObject(bmp); } else { m_il.AddIcon(icon); DestroyIcon(icon); } } m_list.SetImageList(m_il, LVSIL_SMALL); return TRUE; }
BOOL CSkin::LoadCommandImages(CXMLElement* pBase, const CString& strPath) { for ( POSITION pos = pBase->GetElementIterator() ; pos ; ) { CXMLElement* pXML = pBase->GetNextElement( pos ); if ( pXML->IsNamed( _T("icon") ) ) { UINT nID = LookupCommandID( pXML ); if ( nID == 0 ) continue; CString strFile = strPath; strFile += pXML->GetAttributeValue( _T("res") ); strFile += pXML->GetAttributeValue( _T("path") ); int nPos = strFile.Find( '$' ); HICON hIcon = NULL; if ( nPos < 0 ) { if ( ExtractIconEx( strFile, 0, NULL, &hIcon, 1 ) != NULL && hIcon != NULL ) { CoolInterface.AddIcon( nID, hIcon ); } } else { HINSTANCE hInstance = NULL; UINT nIconID = 0; if ( _stscanf( strFile.Left( nPos ), _T("%lu"), &hInstance ) != 1 ) return TRUE; if ( _stscanf( strFile.Mid( nPos + 1 ), _T("%lu"), &nIconID ) != 1 ) return TRUE; hIcon = (HICON)LoadImage( hInstance, MAKEINTRESOURCE(nIconID), IMAGE_ICON, 16, 16, 0 ); if ( hIcon != NULL ) CoolInterface.AddIcon( nID, hIcon ); } } else if ( pXML->IsNamed( _T("bitmap") ) ) { if ( ! LoadCommandBitmap( pXML, strPath ) ) return FALSE; } } return TRUE; }
BOOL ShowTrayIcon(BOOL fShow) { BOOL fRet = DeleteTrayIcon(g_hwndMain, IDI_TASKSWITCHXP); g_dwFlags &= ~TSF_SHOWTRAYICON; if (g_hIconTray) { DestroyIcon(g_hIconTray); g_hIconTray = NULL; } if (fShow) { HICON hIconSm = NULL; if (g_dwFlags & TSF_USECUSTOMICON) { HKEY hkey = NULL; if (!RegOpenKeyEx(HKEY_CURRENT_USER, g_szRegKeyTs, 0, KEY_READ, &hkey)) { WCHAR szBuff[MAX_DATALEN] = L""; DWORD cbData = MAX_DATALEN * sizeof(WCHAR); if (!RegQueryValueEx(hkey, RS_CUSTOMICON, 0, NULL, (PBYTE)szBuff, &cbData)) { int nIconIndex; if (_GetIconPathIndex(szBuff, &nIconIndex)) { if (!ExtractIconEx(szBuff, nIconIndex, NULL, &hIconSm, 1)) hIconSm = NULL; } } RegCloseKey(hkey); } } if (!hIconSm) { g_hIconTray = (HICON)LoadImage(g_hinstExe, MAKEINTRESOURCE(IDI_TASKSWITCHXP), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR); } else { g_hIconTray = CopyIcon(hIconSm); DestroyIcon(hIconSm); } if (!g_hIconTray) g_hIconTray = LoadIcon(NULL, IDI_WARNING); fRet = AddTrayIcon(g_hwndMain, IDI_TASKSWITCHXP, g_hIconTray, g_szWindowName); g_dwFlags |= TSF_SHOWTRAYICON; } return(fRet); }
/*------------------------------------------------ initialize --------------------------------------------------*/ BOOL InitSelectIcon(HWND hDlg) { int i, count, index; HICON hicon, hiconl; char msg[MAX_PATH]; char fname[MAX_PATH], num[10]; // common/tclang.c SetDialogLanguage(hDlg, "SelectIcon", g_hfontDialog); parse(fname, m_fname_index, 0, MAX_PATH); parse(num, m_fname_index, 1, 10); if(num[0] == 0) index = 0; else index = atoi(num); count = (int)(INT_PTR)ExtractIcon(m_hInst, fname, (UINT)-1); if(count == 0) { strcpy(msg, MyString(IDS_NOICON, "NoIcon")); strcat(msg, "\n"); strcat(msg, fname); MessageBox(hDlg, msg, "TClock", MB_OK|MB_ICONEXCLAMATION); return FALSE; } EndSelectIcon(hDlg); SendDlgItemMessage(hDlg, IDC_LISTICON, LB_RESETCONTENT, 0, 0); for(i = 0; i < count; i++) { hiconl = NULL; hicon = NULL; ExtractIconEx(fname, i, &hiconl, &hicon, 1); if(hiconl) DestroyIcon(hiconl); SendDlgItemMessage(hDlg, IDC_LISTICON, LB_ADDSTRING, 0, (LPARAM)hicon); } SetDlgItemText(hDlg, IDC_FNAMEICON, fname); SendDlgItemMessage(hDlg, IDC_LISTICON, LB_SETCURSEL, index, 0); strcpy(m_fname_index, fname); return TRUE; }
HICON E_Util::getIconHandle(HWND hwnd) { HICON icon = NULL; wchar_t path[1024] = { 0, }; DWORD pid; DWORD res = GetWindowThreadProcessId(hwnd, &pid); // !!??!! HANDLE handle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid); int copyLength; copyLength = GetModuleFileNameEx(handle, NULL, path, 1024); // 32bit API if (copyLength == 0) { DWORD dwLen = sizeof(path) / sizeof(wchar_t); ::QueryFullProcessImageName(handle, 0, path, &dwLen); // Windows Vista 이상 API } ExtractIconEx(path, 0, &icon, NULL, 1); CloseHandle(handle); return icon; }
ImageType::ImageType(const unsigned id, const CMString& file, const int index, const IcoTypeEnum type) : ImageBase(id) { m_bmp = NULL; m_pPropertyItem = NULL; m_nCurrentFrame = 0; m_nFrameCount = 0; if (!InitGdiPlus()) return; switch (type) { case icoDll: { const HMODULE hModule = LoadDll(file); if (hModule != NULL) { HICON hIcon = (HICON)LoadImage(hModule, MAKEINTRESOURCE(-index), IMAGE_ICON, 0, 0, 0); m_bmp = new Gdiplus::Bitmap(hIcon); DestroyIcon(hIcon); } } break; case icoFile: m_bmp = new Gdiplus::Bitmap(T2W_SM(file.c_str())); break; default: HICON hIcon = NULL; ExtractIconEx(file.c_str(), index, NULL, &hIcon, 1); m_bmp = new Gdiplus::Bitmap(hIcon); DestroyIcon(hIcon); break; } if (m_bmp->GetLastStatus() != Gdiplus::Ok) { delete m_bmp; m_bmp = NULL; return; } }
HICON GetParentProcessIcon() { HICON icon = 0; DWORD parentid; parentid = GetParentProcessId(GetCurrentProcessId()); if(parentid) { HANDLE parent = OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ, FALSE, parentid); if(parent) { TCHAR parentname[MAX_PATH]; /* //Clean HMODULE hMod; DWORD cbNeeded; if(EnumProcessModules(parent, &hMod, sizeof(hMod), &cbNeeded)) { GetModuleFileNameEx(parent, hMod, parentname, sizeof(parentname)); ExtractIconEx(parentname, 0, 0, &icon, 1); } /*/ //Just as good, it seems... GetModuleFileNameEx(parent, 0, parentname, sizeof(parentname)); ExtractIconEx(parentname, 0, 0, &icon, 1); //*/ CloseHandle(parent); } } return icon; }
LogicalItem_Processes_Root::LogicalItem_Processes_Root() { ShellItemGenericIconManager * aMan = Application::Instance().GetShellItemGenericIconManager(); struct { const TCHAR * Name; int Index; REFGUID Guid; } aIcons[] = { { _T("shell32.dll"), 71, OBJ_ProcItem }, { _T("shell32.dll"), 22, OBJ_RevealItem }, { _T("shell32.dll"), 131, OBJ_QuitItem }, }; OSVERSIONINFO aVer; aVer.dwOSVersionInfoSize = sizeof OSVERSIONINFO; GetVersionEx(&aVer); if (aVer.dwMajorVersion == 5 && aVer.dwMinorVersion == 0) //windows 2000 aIcons[2].Index = 105; // this is not the X (as in delete), but the stop sign; close enough const static int NumIcons = sizeof aIcons / sizeof aIcons[0]; for (int i = 0; i < NumIcons; ++i) { ItemIconData aDt; HRESULT aRes = aMan->GetWellKnownIconData(aIcons[i].Guid, &aDt); if ( FAILED(aRes) && aIcons[i].Index > 0) { HICON aIcn = 0; UINT aNumExtracted = ExtractIconEx(aIcons[i].Name, aIcons[i].Index, NULL, &aIcn, 1); if (aNumExtracted > 0 && aIcn != 0) { aRes = aMan->EnsureWellKnownIcon(aIcons[i].Guid, aIcn); ATLASSERT(aRes == S_OK); DestroyIcon(aIcn); } } } }
HICON GoFindAnIcon(LPCTSTR path) { HICON icon = 0; //not using our parent's icon if(_tcsicmp(L"parent", path)) { icon = (HICON)LoadImage(0, path, IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_LOADFROMFILE|LR_LOADMAP3DCOLORS); if(!icon) { //Try something else TCHAR mypath[MAX_PATH]; const TCHAR *cleanpath = path; const TCHAR *comma; comma = _tcsrchr(path, ','); UINT index = 1; if(comma) { _tcsncpy(mypath, path, comma-path); //Can you exploit this buffer overflow ? mypath[comma-path] = TCHAR(0); index = _ttoi(comma+1); cleanpath = mypath; } ExtractIconEx(cleanpath, index, 0, &icon, 1); } } else { icon = GetParentProcessIcon(); } return icon; }
IconType::IconType(const unsigned id, const CMString& file, const int index, const IcoTypeEnum type) : ImageBase(id) { m_SmileyIcon = NULL; switch (type) { case icoDll: { const HMODULE hModule = LoadDll(file); if (hModule != NULL) m_SmileyIcon = (HICON)LoadImage(hModule, MAKEINTRESOURCE(-index), IMAGE_ICON, 0, 0, 0); } break; case icoFile: m_SmileyIcon = (HICON)LoadImage(NULL, file.c_str(), IMAGE_ICON, 0, 0, LR_LOADFROMFILE); break; default: ExtractIconEx(file.c_str(), index, NULL, &m_SmileyIcon, 1); break; } }
int CIconList::CreateTabIconInt(LPCWSTR asIconDescr, bool bAdmin, LPCWSTR asWorkDir) { wchar_t* pszExpanded = ExpandEnvStr(asIconDescr); // Need to be created! int iIconIdx = -1; HICON hFileIcon = NULL; wchar_t szTemp[MAX_PATH]; LPCWSTR pszLoadFile = pszExpanded ? pszExpanded : asIconDescr; LPCWSTR lpszExt = (wchar_t*)PointToExt(pszLoadFile); bool bDirChanged = false; if (asWorkDir && *asWorkDir) { // Executable (or icon) file may be not availbale by %PATH%, let "cd" to it... bDirChanged = gpConEmu->ChangeWorkDir(asWorkDir); } if (!lpszExt) { LPWSTR pszFile = NULL; if (SearchPath(NULL, pszLoadFile, L".exe", countof(szTemp), szTemp, &pszFile)) { pszLoadFile = szTemp; lpszExt = (wchar_t*)PointToExt(pszLoadFile); } if (!lpszExt) goto wrap; } if (lstrcmpi(lpszExt, L".ico") == 0) { hFileIcon = (HICON)LoadImage(0, pszLoadFile, IMAGE_ICON, mn_CxIcon, mn_CyIcon, LR_DEFAULTCOLOR|LR_LOADFROMFILE); } else if ((lstrcmpi(lpszExt, L".exe") == 0) || (lstrcmpi(lpszExt, L".dll") == 0)) { //TODO: May be specified index of an icon in the file HICON hIconLarge = NULL, hIconSmall = NULL; ExtractIconEx(pszLoadFile, 0, &hIconLarge, &hIconSmall, 1); bool bUseLargeIcon = ((mn_CxIcon > 16) && (hIconLarge != NULL)) || (hIconSmall == NULL); HICON hDestroyIcon = bUseLargeIcon ? hIconSmall : hIconLarge; if (hDestroyIcon) DestroyIcon(hDestroyIcon); hFileIcon = bUseLargeIcon ? hIconLarge : hIconSmall; } else { //TODO: Shell icons for registered files (cmd, bat, sh, pl, py, ...) } if (hFileIcon) { wchar_t szIconInfo[80] = L"", szMergedInfo[80] = L""; GetIconInfoStr(hFileIcon, szIconInfo); if (gpSetCls->isAdvLogging) { CEStr lsLog(lstrmerge(L"Icon `", asIconDescr, L"` was loaded: ", szIconInfo)); gpConEmu->LogString(lsLog); } int iIconIdxAdm = -1; iIconIdx = ImageList_ReplaceIcon(mh_TabIcons, -1, hFileIcon); TabIconCache NewIcon = {lstrdup(asIconDescr), iIconIdx, false}; m_Icons.push_back(NewIcon); if (mn_AdminIcon >= 0) { HIMAGELIST hAdmList = ImageList_Merge(mh_TabIcons, iIconIdx, mh_TabIcons, mn_AdminIcon+2, 0,0); if (hAdmList) { HICON hNewIcon = ImageList_GetIcon(hAdmList, 0, ILD_TRANSPARENT); if (hNewIcon) { CEStr lsLog(lstrmerge(L"Admin icon `", asIconDescr, L"` was created: ", GetIconInfoStr(hNewIcon, szMergedInfo))); gpConEmu->LogString(lsLog); iIconIdxAdm = ImageList_ReplaceIcon(mh_TabIcons, -1, hNewIcon); DestroyIcon(hNewIcon); TabIconCache AdmIcon = {lstrdup(asIconDescr), iIconIdxAdm, true}; m_Icons.push_back(AdmIcon); if (bAdmin && (iIconIdxAdm > 0)) { iIconIdx = iIconIdxAdm; } } else { gpConEmu->LogString(L"GetIcon for admin icon was failed"); } ImageList_Destroy(hAdmList); } else { gpConEmu->LogString(L"Admin icon merging was failed"); } } DestroyIcon(hFileIcon); } wrap: if (bDirChanged) { gpConEmu->ChangeWorkDir(NULL); } SafeFree(pszExpanded); if (gpSetCls->isAdvLogging && (iIconIdx < 0)) { CEStr lsLog(lstrmerge(L"Icon `", asIconDescr, L"` loading was failed")); gpConEmu->LogString(lsLog); } return iIconIdx; }
CMenu* CCementBD::SetModulesExtern() { if(gListModuleExternal.GetCount() == 0) return 0; //--------------------------------------------------- //Формируем меню внешних модулей CCementDoc* pDoc = (CCementDoc*)GetDocument(); HINSTANCE hInst = AfxGetResourceHandle(); pDoc->m_DefaultMenu = ::LoadMenu(AfxGetResourceHandle(), MAKEINTRESOURCE(IDR_KRSCEMENTTYPE)); if (pDoc->m_DefaultMenu == NULL) return 0; CMenu* menu = CMenu::FromHandle(pDoc->GetDefaultMenu()); if(menu) { int iPos; CMenu* pPopup = NULL; for(iPos = 0; iPos < (int)menu->GetMenuItemCount(); iPos++) { if(menu->GetSubMenu(iPos)->GetMenuItemID(0) == ID_NASTROIKA_MODULES) { pPopup = menu->GetSubMenu(iPos); int ii = (int)pPopup->GetMenuItemCount(); break; } } if(pPopup == NULL) return 0; CMenu *submenu = menu->GetSubMenu(iPos); if(submenu == NULL) return 0; int ii = (int)submenu->GetMenuItemCount(); int cx = ::GetSystemMetrics(SM_CXMENUCHECK); int cy = ::GetSystemMetrics(SM_CYMENUCHECK); if(pPopup != NULL && gListModuleExternal.GetCount() > 0) { pPopup->AppendMenu(MF_SEPARATOR, 0, LPCTSTR(0)); for(int i = 0; i < gListModuleExternal.GetCount(); i++) { HICON hIconLarge, hIcon; // ExtractIconEx(gListModuleExternal.GetName2(i), 0, &hIconLarge, &hIcon, 1); CString Name2 = gListModuleExternal.GetName2txe(i); if(Name2.GetLength() == 0) continue; ExtractIconEx(Name2, 0, &hIconLarge, &hIcon, 1); //HICON hIcon = ExtractIcon(pApp->m_hInstance, gListModuleExternal.GetName2(i), 0); if(hIcon != NULL) { ICONINFO iconinfo; GetIconInfo(hIcon, &iconinfo); HANDLE hLoad = CopyImage(HANDLE(iconinfo.hbmColor), IMAGE_BITMAP, cx+1, cy+1, LR_COPYFROMRESOURCE); CBitmap *pBmp = CBitmap::FromHandle(HBITMAP(hLoad)); CString str; str.Format(" %d", i); str += ". " + gListModuleExternal.GetName(i); BOOL flg = pPopup->AppendMenu(MF_STRING | MF_ENABLED, ID_MENU_MODULE_EXTERNAL + i, str); pPopup->SetMenuItemBitmaps(i+2, MF_BYPOSITION, pBmp, pBmp); //BOOL res = menu->SetMenuItemBitmaps(2, MF_BYPOSITION, pBmp, pBmp); //int zzz = 0; } } } CMDIFrameWnd* frame = ((CMDIChildWnd *) GetParent())->GetMDIFrame(); frame->MDISetMenu(menu, NULL); frame->DrawMenuBar(); } //------------------------------------------------------------------------- return menu; }
// // wParam = szProto // lParam = status // HICON LoadSkinProtoIcon( const char* szProto, int status, bool big ) { int i, statusIndx = -1; char iconName[MAX_PATH]; HICON hIcon; DWORD caps2 = ( szProto == NULL ) ? ( DWORD )-1 : CallProtoService(szProto,PS_GETCAPS,PFLAGNUM_2,0); if ( status >= ID_STATUS_CONNECTING && status < ID_STATUS_CONNECTING+MAX_CONNECT_RETRIES ) { mir_snprintf( iconName, SIZEOF(iconName), "%s%d", mainIconsFmt, 7 ); return IcoLib_GetIcon( iconName, big ); } for ( i = 0; i < SIZEOF(statusIcons); i++ ) { if ( statusIcons[i].id == status ) { statusIndx = i; break; } } if ( statusIndx == -1 ) return NULL; if ( !szProto ) { // Only return a protocol specific icon if there is only one protocol // Otherwise return the global icon. This affects the global status menu mainly. if ( accounts.getCount() == 1 ) { HICON hIcon; // format: core_status_%proto%statusindex mir_snprintf(iconName, SIZEOF(iconName), "%s%s%d", statusIconsFmt, szProto, statusIndx); hIcon = IcoLib_GetIcon( iconName, big ); if ( hIcon ) return hIcon; } // format: core_status_%s%d mir_snprintf(iconName, SIZEOF(iconName), "%s%s%d", statusIconsFmt, GLOBAL_PROTO_NAME, statusIndx); return IcoLib_GetIcon( iconName, big ); } // format: core_status_%s%d mir_snprintf(iconName, SIZEOF(iconName), "%s%s%d", statusIconsFmt, szProto, statusIndx); hIcon = IcoLib_GetIcon( iconName, big ); if ( hIcon == NULL && ( caps2 == 0 || ( caps2 & statusIcons[statusIndx].pf2 ))) { PROTOACCOUNT* pa = Proto_GetAccount( szProto ); if ( pa ) { TCHAR szPath[MAX_PATH], szFullPath[MAX_PATH], *str; SKINICONDESC sid = { 0 }; // // Queried protocol isn't in list, adding // TCHAR tszSection[MAX_PATH]; mir_sntprintf( tszSection, SIZEOF(tszSection), _T("%s%s"), _T(PROTOCOLS_PREFIX), pa->tszAccountName ); sid.ptszSection = tszSection; sid.cbSize = sizeof(sid); sid.flags = SIDF_ALL_TCHAR; GetModuleFileName( hMirandaInst, szPath, MAX_PATH ); str = _tcsrchr( szPath, '\\' ); if ( str != NULL ) *str = 0; mir_sntprintf( szFullPath, SIZEOF(szFullPath), _T("%s\\Icons\\proto_") _T(TCHAR_STR_PARAM) _T(".dll"), szPath, pa->szProtoName ); if ( GetFileAttributes( szFullPath ) != INVALID_FILE_ATTRIBUTES ) sid.ptszDefaultFile = szFullPath; else { mir_sntprintf( szFullPath, SIZEOF(szFullPath), _T("%s\\Plugins\\") _T(TCHAR_STR_PARAM) _T(".dll"), szPath, szProto ); if (( int )ExtractIconEx( szFullPath, statusIcons[i].resource_id, NULL, &hIcon, 1 ) > 0 ) { DestroyIcon( hIcon ); sid.ptszDefaultFile = szFullPath; hIcon = NULL; } if ( sid.pszDefaultFile == NULL ) { if ( str != NULL ) *str = '\\'; sid.ptszDefaultFile = szPath; } } // // Add global icons to list // { int lowidx, highidx; if ( caps2 == 0 ) lowidx = statusIndx, highidx = statusIndx+1; else lowidx = 0, highidx = SIZEOF(statusIcons); for ( i = lowidx; i < highidx; i++ ) { if ( caps2 == 0 || ( caps2 & statusIcons[i].pf2 )) { // format: core_%s%d mir_snprintf( iconName, SIZEOF(iconName), "%s%s%d", statusIconsFmt, szProto, i ); sid.pszName = iconName; sid.ptszDescription = cli.pfnGetStatusModeDescription( statusIcons[i].id, 0 ); sid.iDefaultIndex = statusIcons[i].resource_id; IcoLib_AddNewIcon( &sid ); } } } } // format: core_status_%s%d mir_snprintf( iconName, SIZEOF(iconName), "%s%s%d", statusIconsFmt, szProto, statusIndx ); hIcon = IcoLib_GetIcon( iconName, big ); if ( hIcon ) return hIcon; } if ( hIcon == NULL ) { mir_snprintf( iconName, SIZEOF(iconName), "%s%s%d", statusIconsFmt, GLOBAL_PROTO_NAME, statusIndx ); hIcon = IcoLib_GetIcon( iconName, big ); } return hIcon; }
int CIconList::CreateTabIcon(LPCWSTR asIconDescr, bool bAdmin) { if (!asIconDescr || !*asIconDescr) return GetTabIcon(bAdmin); for (INT_PTR i = 0; i < m_Icons.size(); i++) { const TabIconCache& icn = m_Icons[i]; if ((icn.bAdmin!=FALSE) != bAdmin) continue; if (lstrcmpi(icn.pszIconDescr, asIconDescr) != 0) continue; // Already was created! return icn.nIconIdx; } wchar_t* pszExpanded = ExpandEnvStr(asIconDescr); // Need to be created! int iIconIdx = -1; HICON hFileIcon = NULL; wchar_t szTemp[MAX_PATH]; LPCWSTR pszLoadFile = pszExpanded ? pszExpanded : asIconDescr; LPCWSTR lpszExt = (wchar_t*)PointToExt(pszLoadFile); if (!lpszExt) { LPWSTR pszFile = NULL; if (SearchPath(NULL, pszLoadFile, L".exe", countof(szTemp), szTemp, &pszFile)) { pszLoadFile = szTemp; lpszExt = (wchar_t*)PointToExt(pszLoadFile); } if (!lpszExt) goto wrap; } if (lstrcmpi(lpszExt, L".ico") == 0) { hFileIcon = (HICON)LoadImage(0, pszLoadFile, IMAGE_ICON, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR|LR_LOADFROMFILE); } else if ((lstrcmpi(lpszExt, L".exe") == 0) || (lstrcmpi(lpszExt, L".dll") == 0)) { //TODO: May be specified index of an icon in the file HICON hIconLarge = NULL; ExtractIconEx(pszLoadFile, 0, &hIconLarge, &hFileIcon, 1); if (hIconLarge) DestroyIcon(hIconLarge); } else { //TODO: Shell icons for registered files (cmd, bat, sh, pl, py, ...) } if (hFileIcon) { int iIconIdxAdm = -1; iIconIdx = ImageList_ReplaceIcon(mh_TabIcons, -1, hFileIcon); TabIconCache NewIcon = {lstrdup(asIconDescr), false, iIconIdx}; m_Icons.push_back(NewIcon); HIMAGELIST hAdmList = ImageList_Merge(mh_TabIcons, iIconIdx, mh_TabIcons, mn_AdminIcon+2, 0,0); if (hAdmList) { HICON hNewIcon = ImageList_GetIcon(hAdmList, 0, ILD_TRANSPARENT); if (hNewIcon) { iIconIdxAdm = ImageList_ReplaceIcon(mh_TabIcons, -1, hNewIcon); DestroyIcon(hNewIcon); TabIconCache AdmIcon = {lstrdup(asIconDescr), true, iIconIdxAdm}; m_Icons.push_back(AdmIcon); if (bAdmin && (iIconIdxAdm > 0)) { iIconIdx = iIconIdxAdm; } } } //TODO: bAdmin!!! DestroyIcon(hFileIcon); } wrap: SafeFree(pszExpanded); return iIconIdx; }