https://git.reactos.org/?p=reactos.git;a=commitdiff;h=06cd45353b1acd836449c…
commit 06cd45353b1acd836449c3c3509ac2c76cace690
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Sun Oct 30 06:18:58 2022 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Sun Oct 30 06:18:58 2022 +0900
[KBSWITCH] Menu with icons (#4822)
Add icons to the left-click menu. CORE-10667
---
base/applications/kbswitch/kbswitch.c | 42 ++++++++++++++++++++++++++++++++++-
1 file changed, 41 insertions(+), 1 deletion(-)
diff --git a/base/applications/kbswitch/kbswitch.c
b/base/applications/kbswitch/kbswitch.c
index 89159701fc7..67e250d4259 100644
--- a/base/applications/kbswitch/kbswitch.c
+++ b/base/applications/kbswitch/kbswitch.c
@@ -236,6 +236,27 @@ static HICON FakeExtractIcon(LPCTSTR szIconPath, INT cxIcon, INT
cyIcon)
return LoadIcon.hIcon;
}
+static HBITMAP BitmapFromIcon(HICON hIcon)
+{
+ HDC hdcScreen = GetDC(NULL);
+ HDC hdc = CreateCompatibleDC(hdcScreen);
+ INT cxIcon = GetSystemMetrics(SM_CXSMICON);
+ INT cyIcon = GetSystemMetrics(SM_CYSMICON);
+ HBITMAP hbm = CreateCompatibleBitmap(hdcScreen, cxIcon, cyIcon);
+ HGDIOBJ hbmOld;
+
+ if (hbm != NULL)
+ {
+ hbmOld = SelectObject(hdc, hbm);
+ DrawIconEx(hdc, 0, 0, hIcon, cxIcon, cyIcon, 0, GetSysColorBrush(COLOR_MENU),
DI_NORMAL);
+ SelectObject(hdc, hbmOld);
+ }
+
+ DeleteDC(hdc);
+ ReleaseDC(NULL, hdcScreen);
+ return hbm;
+}
+
static HICON
CreateTrayIcon(LPTSTR szLCID, LPCTSTR szImeFile OPTIONAL)
{
@@ -447,6 +468,9 @@ BuildLeftPopupMenu(VOID)
HKEY hKey;
DWORD dwIndex, dwSize;
TCHAR szLayoutNum[CCH_ULONG_DEC + 1], szName[MAX_PATH];
+ TCHAR szLCID[CCH_LAYOUT_ID + 1], szImeFile[80];
+ HICON hIcon;
+ MENUITEMINFO mii = { sizeof(mii) };
/* Add the keyboard layouts to the popup menu */
if (RegOpenKeyEx(HKEY_CURRENT_USER, _T("Keyboard Layout\\Preload"), 0,
@@ -461,10 +485,26 @@ BuildLeftPopupMenu(VOID)
break;
}
+ GetLayoutID(szLayoutNum, szLCID, ARRAYSIZE(szLCID));
+ GetImeFile(szImeFile, ARRAYSIZE(szImeFile), szLCID);
+
if (!GetLayoutName(szLayoutNum, szName, ARRAYSIZE(szName)))
continue;
- AppendMenu(hMenu, MF_STRING, _ttoi(szLayoutNum), szName);
+ mii.fMask = MIIM_ID | MIIM_STRING;
+ mii.wID = _ttoi(szLayoutNum);
+ mii.dwTypeData = szName;
+
+ hIcon = CreateTrayIcon(szLCID, szImeFile);
+ if (hIcon)
+ {
+ mii.hbmpItem = BitmapFromIcon(hIcon);
+ if (mii.hbmpItem)
+ mii.fMask |= MIIM_BITMAP;
+ }
+
+ InsertMenuItem(hMenu, -1, TRUE, &mii);
+ DestroyIcon(hIcon);
}
CheckMenuItem(hMenu, ulCurrentLayoutNum, MF_CHECKED);