Changeset 2253
- Timestamp:
- 10/24/2010 7:50:10 AM (3 years ago)
- File:
-
- 1 edited
-
branches/eraser6/6.0/ShellExt/CtxMenu.cpp (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/eraser6/6.0/ShellExt/CtxMenu.cpp
r2225 r2253 344 344 MENUITEMINFO mii = { sizeof(MENUITEMINFO) }; 345 345 mii.wID = uID++; 346 mii.fMask = MIIM_SUBMENU | MIIM_STRING | MIIM_ID ;346 mii.fMask = MIIM_SUBMENU | MIIM_STRING | MIIM_ID | MIIM_BITMAP; 347 347 mii.hSubMenu = hSubmenu; 348 348 mii.dwTypeData = const_cast<wchar_t*>(MenuTitle); … … 353 353 if (isVistaOrLater) 354 354 { 355 mii.fMask |= MIIM_BITMAP;356 355 Handle<HICON> icon(GetMenuIcon()); 357 356 mii.hbmpItem = GetMenuBitmapFromIcon(icon); … … 359 358 else if (InvokeReason != INVOKEREASON_DRAGDROP) 360 359 { 361 mii.fMask |= MIIM_FTYPE; 362 mii.fType = MFT_OWNERDRAW; 360 mii.hbmpItem = HBMMENU_CALLBACK; 363 361 } 364 362 … … 401 399 if (mis->itemID == MenuID) 402 400 handleResult = OnMeasureItem(mis->itemWidth, mis->itemHeight); 403 else404 handleResult = false;405 401 break; 406 402 } … … 411 407 if (dis->itemID == MenuID) 412 408 handleResult = OnDrawItem(dis->hDC, dis->rcItem, dis->itemAction, dis->itemState); 413 else414 handleResult = false;415 409 } 416 410 } … … 423 417 bool CCtxMenu::OnMeasureItem(UINT& itemWidth, UINT& itemHeight) 424 418 { 425 LOGFONT logFont;426 if (!SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(logFont), &logFont, 0))427 return false;428 429 //Measure the size of the text.430 Handle<HDC> screenDC = GetDC(NULL);431 Handle<HFONT> font = CreateFontIndirect(&logFont);432 SelectObject(screenDC, font);433 SIZE textSize;434 if (!GetTextExtentPoint32(screenDC, MenuTitle, static_cast<DWORD>(wcslen(MenuTitle)), &textSize))435 return false;436 437 itemWidth = textSize.cx;438 itemHeight = textSize.cy;439 440 419 //Account for the size of the bitmap. 441 UINT iconWidth = GetSystemMetrics(SM_CXMENUCHECK); 442 itemWidth += iconWidth; 443 itemHeight = std::max(iconWidth, itemHeight); 444 445 //And remember the minimum size for menu items. 446 itemHeight = std::max((int)itemHeight, GetSystemMetrics(SM_CXMENUSIZE)); 420 itemWidth = 0; 421 itemHeight = std::max<UINT>(GetSystemMetrics(SM_CYMENUCHECK), itemHeight); 447 422 return true; 448 423 } … … 450 425 bool CCtxMenu::OnDrawItem(HDC hdc, RECT rect, UINT /*action*/, UINT state) 451 426 { 452 //Draw the background. 453 LOGBRUSH logBrush = { BS_SOLID, 454 (state & ODS_SELECTED) ? 455 GetSysColor(COLOR_HIGHLIGHT) : GetSysColor(COLOR_MENU), 456 0 457 }; 458 Handle<HBRUSH> bgBrush = CreateBrushIndirect(&logBrush); 459 FillRect(hdc, &rect, bgBrush); 460 461 //Then the bitmap. 462 { 463 //Draw the icon with alpha and all first. 464 Handle<HICON> icon(GetMenuIcon()); 465 int iconSize = GetSystemMetrics(SM_CXMENUCHECK); 466 int iconMargin = GetSystemMetrics(SM_CXEDGE); 467 DrawState(hdc, NULL, NULL, reinterpret_cast<LPARAM>(static_cast<HICON>(icon)), 468 NULL, rect.left + iconMargin, rect.top + (rect.bottom - rect.top - iconSize) / 2, 469 0, 0, DST_ICON | ((state & ODS_DISABLED) ? DSS_DISABLED : 0)); 470 471 //Move the rectangle's left bound to the text starting position 472 rect.left += iconMargin * 2 + iconSize; 473 } 474 475 //Draw the text. 476 SetBkMode(hdc, TRANSPARENT); 477 LOGFONT logFont; 478 if (!SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(logFont), &logFont, 0)) 479 return false; 480 481 SIZE textSize; 482 if (!GetTextExtentPoint32(hdc, MenuTitle, static_cast<DWORD>(wcslen(MenuTitle)), &textSize)) 483 return false; 484 485 COLORREF oldColour = SetTextColor(hdc, 486 (state & ODS_DISABLED) ? GetSysColor(COLOR_GRAYTEXT) : //Disabled menu item 487 (state & ODS_SELECTED) ? GetSysColor(COLOR_HIGHLIGHTTEXT) : //Highlighted menu item 488 GetSysColor(COLOR_MENUTEXT)); //Normal menu item 489 UINT flags = DST_PREFIXTEXT; 490 if (state & ODS_NOACCEL) 491 flags |= DSS_HIDEPREFIX; 492 ::DrawState(hdc, NULL, NULL, reinterpret_cast<LPARAM>(MenuTitle), wcslen(MenuTitle), 493 rect.left, rect.top + (rect.bottom - rect.top - textSize.cy) / 2, textSize.cx, textSize.cy, flags); 494 SetTextColor(hdc, oldColour); 427 //Get the icon and calculate its size. 428 Handle<HICON> icon(GetMenuIcon()); 429 int iconSize = GetSystemMetrics(SM_CXMENUCHECK); 430 int iconMargin = GetSystemMetrics(SM_CXEDGE); 431 432 //Draw the bitmap. 433 DrawState(hdc, NULL, NULL, reinterpret_cast<LPARAM>(static_cast<HICON>(icon)), 434 NULL, rect.left - iconMargin - iconSize, 435 rect.top + (rect.bottom - rect.top - iconSize) / 2, 0, 0, 436 DST_ICON | ((state & ODS_DISABLED) ? DSS_DISABLED : 0)); 437 495 438 return true; 496 439 }
Note: See TracChangeset
for help on using the changeset viewer.
