| 1729 | } |
| 1730 | |
| 1731 | STDMETHODIMP CShellExt::HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pResult) |
| 1732 | { |
| 1733 | PreserveChdir preserveChdir; |
| 1734 | |
| 1735 | LRESULT res; |
| 1736 | if (!pResult) |
| 1737 | pResult = &res; |
| 1738 | *pResult = FALSE; |
| 1739 | |
| 1740 | LoadLangDll(); |
| 1741 | switch (uMsg) |
| 1742 | { |
| 1743 | case WM_MEASUREITEM: |
| 1744 | { |
| 1745 | auto lpmis = reinterpret_cast<MEASUREITEMSTRUCT*>(lParam); |
| 1746 | if (!lpmis) |
| 1747 | break; |
| 1748 | lpmis->itemWidth = 16; |
| 1749 | lpmis->itemHeight = 16; |
| 1750 | *pResult = TRUE; |
| 1751 | } |
| 1752 | break; |
| 1753 | case WM_DRAWITEM: |
| 1754 | { |
| 1755 | LPCWSTR resource; |
| 1756 | auto lpdis = reinterpret_cast<DRAWITEMSTRUCT*>(lParam); |
| 1757 | if (!lpdis || lpdis->CtlType != ODT_MENU) |
| 1758 | return S_OK; //not for a menu |
| 1759 | resource = GetMenuTextFromResource(myIDMap[lpdis->itemID]); |
| 1760 | if (!resource) |
| 1761 | return S_OK; |
| 1762 | int iconWidth = GetSystemMetrics(SM_CXSMICON); |
| 1763 | int iconHeight = GetSystemMetrics(SM_CYSMICON); |
| 1764 | CAutoIcon hIcon = LoadIconEx(g_hResInst, resource, iconWidth, iconHeight); |
| 1765 | if (!hIcon) |
| 1766 | return S_OK; |
| 1767 | DrawIconEx(lpdis->hDC, |
| 1768 | lpdis->rcItem.left, |
| 1769 | lpdis->rcItem.top + (lpdis->rcItem.bottom - lpdis->rcItem.top - iconHeight) / 2, |
| 1770 | hIcon, iconWidth, iconHeight, |
| 1771 | 0, nullptr, DI_NORMAL); |
| 1772 | *pResult = TRUE; |
| 1773 | } |
| 1774 | break; |
| 1775 | case WM_MENUCHAR: |
| 1776 | { |
| 1777 | wchar_t* szItem; |
| 1778 | if (HIWORD(wParam) != MF_POPUP) |
| 1779 | return S_OK; |
| 1780 | int nChar = LOWORD(wParam); |
| 1781 | if (_istascii(static_cast<wint_t>(nChar)) && _istupper(static_cast<wint_t>(nChar))) |
| 1782 | nChar = tolower(nChar); |
| 1783 | // we have the char the user pressed, now search that char in all our |
| 1784 | // menu items |
| 1785 | std::vector<UINT_PTR> accmenus; |
| 1786 | for (auto It = mySubMenuMap.cbegin(); It != mySubMenuMap.cend(); ++It) |
| 1787 | { |
| 1788 | LPCWSTR resource = GetMenuTextFromResource(mySubMenuMap[It->first]); |
no test coverage detected