From 48cf167a3cabc3d95403d31d6bea746780bc953d Mon Sep 17 00:00:00 2001 From: Andrey Nekrasov Date: Tue, 10 Nov 2020 15:56:05 +0300 Subject: [PATCH] runner: localize tray menu item labels (#7959) * runner: localize tray menu item labels * fixup: please the electronic machinery * Update src/runner/Resources.resx Co-authored-by: Enrico Giordani Co-authored-by: Enrico Giordani --- .github/actions/spell-check/expect.txt | 2 ++ src/runner/Resources.resx | 9 ++++++++- src/runner/tray_icon.cpp | 17 ++++++++++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/.github/actions/spell-check/expect.txt b/.github/actions/spell-check/expect.txt index 4431adcaba..ba6c659ccf 100644 --- a/.github/actions/spell-check/expect.txt +++ b/.github/actions/spell-check/expect.txt @@ -1338,6 +1338,8 @@ memset Mensching MENUITEMINFO menurc +menuitem +MENUITEMINFOW MENUSTART messagebox METACHARSET diff --git a/src/runner/Resources.resx b/src/runner/Resources.resx index 836c1340d3..c8c791df95 100644 --- a/src/runner/Resources.resx +++ b/src/runner/Resources.resx @@ -154,4 +154,11 @@ Snooze - \ No newline at end of file + + Settings + + + Exit + Exit as a verb, as in Exit the application + + diff --git a/src/runner/tray_icon.cpp b/src/runner/tray_icon.cpp index 49ab345eae..1d95d9b73f 100644 --- a/src/runner/tray_icon.cpp +++ b/src/runner/tray_icon.cpp @@ -49,6 +49,14 @@ bool dispatch_run_on_main_ui_thread(main_loop_callback_function _callback, PVOID return true; } +void change_menu_item_text(const UINT item_id, wchar_t* new_text) +{ + MENUITEMINFOW menuitem = { .cbSize = sizeof(MENUITEMINFOW), .fMask = MIIM_TYPE | MIIM_DATA }; + GetMenuItemInfoW(h_menu, item_id, false, &menuitem); + menuitem.dwTypeData = new_text; + SetMenuItemInfoW(h_menu, item_id, false, &menuitem); +} + LRESULT __stdcall tray_icon_window_proc(HWND window, UINT message, WPARAM wparam, LPARAM lparam) { switch (message) @@ -125,6 +133,13 @@ LRESULT __stdcall tray_icon_window_proc(HWND window, UINT message, WPARAM wparam { h_menu = LoadMenu(reinterpret_cast(&__ImageBase), MAKEINTRESOURCE(ID_TRAY_MENU)); } + if (h_menu) + { + static std::wstring settings_menuitem_label = GET_RESOURCE_STRING(IDS_SETTINGS_MENU_TEXT); + static std::wstring exit_menuitem_label = GET_RESOURCE_STRING(IDS_EXIT_MENU_TEXT); + change_menu_item_text(ID_SETTINGS_MENU_COMMAND, settings_menuitem_label.data()); + change_menu_item_text(ID_EXIT_MENU_COMMAND, exit_menuitem_label.data()); + } if (!h_sub_menu) { h_sub_menu = GetSubMenu(h_menu, 0); @@ -193,7 +208,7 @@ void start_tray_icon() tray_icon_data.uID = id_tray_icon; tray_icon_data.uCallbackMessage = wm_icon_notify; std::wstring about_msg_pt_version = L"PowerToys\n" + get_product_version(); - wcscpy_s(tray_icon_data.szTip, sizeof(tray_icon_data.szTip) / sizeof(WCHAR), about_msg_pt_version.c_str()); + wcscpy_s(tray_icon_data.szTip, sizeof(tray_icon_data.szTip) / sizeof(WCHAR), about_msg_pt_version.c_str()); tray_icon_data.uFlags = NIF_ICON | NIF_TIP | NIF_MESSAGE; tray_icon_created = Shell_NotifyIcon(NIM_ADD, &tray_icon_data) == TRUE;