INT_PTR Main_OnInitDialog(HWND hWnd, HWND /*hWndFocus*/, LPARAM) { WORD wDefLangID = MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US); // Set the icon. CIconHandle hIcon; hIcon.LoadIcon(IDI_ICON_UPDATESTR); CWindow wnd(hWnd); wnd.SetIcon(hIcon, TRUE); wnd.SetIcon(hIcon, FALSE); CComboBox combo(wnd.GetDlgItem(IDC_COMBO_LANGUAGES)); CString strBuf; // Fill the languages-combobox. int nDefIndex = 0; for(int i = 0; i < NO_OF_LANGUAGES; i++ ) { // Load the string, insert it & specify the language ID as // the item data. strBuf.LoadString(s_langInfo[i].nStrID); int nIndex = combo.AddString(strBuf); combo.SetItemData(nIndex, s_langInfo[i].wLangID); if( wDefLangID == s_langInfo[i].wLangID ) nDefIndex = nIndex; } // Select the default index. combo.SetCurSel(nDefIndex); return TRUE; }
bool CTuoIcon::LoadFromFile() { CIconHandle ico; ico.LoadIcon(m_strFileName.c_str(), 16, 16, LR_LOADFROMFILE); if (ico == NULL) return false; m_hIcon = ico; return true; }
void CToolBarPropertyPage::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) { if (lpDrawItemStruct->CtlID == IDC_LIST_ICON) { CDCHandle dc = lpDrawItemStruct->hDC; // Save these value to restore them when done drawing. COLORREF crOldTextColor = dc.GetTextColor(); COLORREF crOldBkColor = dc.GetBkColor(); // If this item is selected, set the background color // and the text color to appropriate values. Also, erase // rect by filling it with the background color. if ((lpDrawItemStruct->itemAction | ODA_SELECT) && (lpDrawItemStruct->itemState & ODS_SELECTED)) { dc.SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT)); dc.SetBkColor(::GetSysColor(COLOR_HIGHLIGHT)); dc.FillSolidRect(&lpDrawItemStruct->rcItem, ::GetSysColor(COLOR_HIGHLIGHT)); } else dc.FillSolidRect(&lpDrawItemStruct->rcItem, crOldBkColor); #if 0 // If this item has the focus, draw a red frame around the // item's rect. if ((lpDrawItemStruct->itemAction | ODA_FOCUS) && (lpDrawItemStruct->itemState & ODS_FOCUS)) { CBrush br; br.CreateSolidBrush(RGB(255, 0, 0)); dc.FrameRect(&lpDrawItemStruct->rcItem, br); } #endif IconListData* pData = (IconListData*)lpDrawItemStruct->itemData; if (pData) { CIconHandle icon = m_imgList.GetIcon(pData->nIndex); if (icon.m_hIcon) icon.DrawIconEx(dc, lpDrawItemStruct->rcItem.left + cxMargin, lpDrawItemStruct->rcItem.top + cyMargin, m_iconSize.cx, m_iconSize.cy); lpDrawItemStruct->rcItem.left += m_iconSize.cx + cxMargin + IconTextMargin; // Draw the text. dc.DrawText( pData->strText, pData->strText.GetLength(), &lpDrawItemStruct->rcItem, DT_SINGLELINE | DT_VCENTER); } // Reset the background color and the text color back to their // original values. dc.SetTextColor(crOldTextColor); dc.SetBkColor(crOldBkColor); } }
BOOL SaveIconBmpToFile(HICON hIcon, LPCTSTR pszFile, COLORREF clrBkGnd ) { if (hIcon == NULL || pszFile == NULL) return FALSE; CClientDC dcDesk(GetDesktopWindow()); CIconHandle icon = hIcon; ICONINFO iconInfo = { 0 }; if ( !icon.GetIconInfo( &iconInfo ) ) return FALSE; CBitmapHandle bmpIcon = iconInfo.hbmColor; BITMAP bmpInfo = { 0 }; bmpIcon.GetBitmap(&bmpInfo); CBitmap bmp; bmp.CreateCompatibleBitmap( dcDesk, bmpInfo.bmWidth, bmpInfo.bmHeight); CDC dcMem; dcMem.CreateCompatibleDC( dcDesk ); HBITMAP hOldBmp = dcMem.SelectBitmap( bmp ); RECT rcBkGnd = { 0, 0, bmpInfo.bmWidth, bmpInfo.bmHeight }; dcMem.FillSolidRect(&rcBkGnd , clrBkGnd); ::DrawIconEx( dcMem, 0, 0, hIcon, bmpInfo.bmWidth, bmpInfo.bmHeight, 0, NULL, DI_NORMAL ); dcMem.SelectBitmap( hOldBmp ); SaveBitmapToFile(dcMem, bmp, pszFile); //must delete bitmap object if (iconInfo.hbmColor) ::DeleteObject( iconInfo.hbmColor ); //must delete bitmap object if ( iconInfo.hbmMask ) ::DeleteObject( iconInfo.hbmMask ); return TRUE; }
HICON CFaviconManager::GetFaviconFromURL(LPCTSTR url) { CString strFaviconURL; CString strHtmlPath; if (SUCCEEDED(::URLDownloadToCacheFile(NULL, url, strHtmlPath.GetBuffer(MAX_PATH), MAX_PATH, 0, NULL))) { strHtmlPath.ReleaseBuffer(); CAtlFile file; if (SUCCEEDED(file.Create(strHtmlPath, GENERIC_READ, 0, OPEN_EXISTING))) { enum { kMaxReadSize = 2000 }; unique_ptr<char[]> htmlContent(new char[kMaxReadSize + 1]); DWORD dwReadSize = 0; file.Read((LPVOID)htmlContent.get(), kMaxReadSize, dwReadSize); htmlContent[dwReadSize] = '\0'; boost::regex rx("<link (?:(?<rel>rel=[\"']?(?:shortcut icon|icon)[\"']?) (?<href>href=[\"']?(?<url>[^ \"]+)[\"']?)|(?<href>href=[\"']?(?<url>[^ \"]+)[\"']?) (?<rel>rel=[\"']?(?:shortcut icon|icon)[\"']?))[^>]+>", boost::regex::icase); boost::cmatch result; if (boost::regex_search(htmlContent.get(), result, rx)) { CString strhref = result["url"].str().c_str(); DWORD dwSize = INTERNET_MAX_URL_LENGTH; ::UrlCombine(url, strhref, strFaviconURL.GetBuffer(INTERNET_MAX_URL_LENGTH), &dwSize, 0); strFaviconURL.ReleaseBuffer(); } } } if (strFaviconURL.IsEmpty()) { // ルートにあるFaviconのアドレスを得る DWORD cchResult = INTERNET_MAX_URL_LENGTH; if (::CoInternetParseUrl(url, PARSE_ROOTDOCUMENT, 0, strFaviconURL.GetBuffer(INTERNET_MAX_URL_LENGTH), INTERNET_MAX_URL_LENGTH, &cchResult, 0) == S_OK) { strFaviconURL.ReleaseBuffer(); strFaviconURL += _T("/favicon.ico"); } } if (strFaviconURL.GetLength() > 0) { CCritSecLock lock(s_cs); CIconHandle hIcon = GetFavicon(strFaviconURL); if (hIcon == NULL) { hIcon = _DownloadFavicon(strFaviconURL); if (hIcon) { s_mapIcon[std::wstring(strFaviconURL)] = hIcon; hIcon = hIcon.DuplicateIcon(); } } else { hIcon = hIcon.DuplicateIcon(); } return hIcon; } return NULL; }