fix(windows): incorrect UTF8/GBK string encoding handling#74
Conversation
|
Why did you close #73 ? |
Yes, I closed it. Sorry~~ I'm still relatively unfamiliar with the Git force push process. I wanted to performing a commit squash and I closed the PR to temporarily stop the Action runs. Thank you for your understanding. |
Oh, no problem! We will also do a squash and merge when the PR is merged so it will end up as a single commit in the base branch. I'm also manually approving the actions, so it's not a bother if you have new changes/commits. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical internationalization issue on Windows where Chinese, Japanese, and other non-ASCII text appeared garbled in menu items, tooltips, and tray icons. The root cause was the use of ANSI Windows APIs (MENUITEMINFO, Shell_NotifyIcon) which incorrectly interpreted UTF-8 strings as the system's ANSI code page (GBK/CP936 for Chinese systems).
Key changes:
- Migrated all Windows tray APIs from ANSI to Unicode (W-suffix) variants
- Added UTF-8 to UTF-16 string conversion using MultiByteToWideChar with CP_UTF8
- Updated menu item, tooltip, and notification text handling to properly support multi-language environments
Comments suppressed due to low confidence (1)
src/tray_windows.c:74
- Inconsistent API usage: The menu items are now created with MENUITEMINFOW (Unicode), but this WM_COMMAND handler still uses MENUITEMINFO (ANSI) and GetMenuItemInfo (ANSI). For consistency and to match the Unicode conversion throughout the file, this should use MENUITEMINFOW and GetMenuItemInfoW. While the dwItemData field works with either variant, using the Unicode version maintains consistency with the rest of the changes.
MENUITEMINFO item = {
.cbSize = sizeof(MENUITEMINFO),
.fMask = MIIM_ID | MIIM_DATA,
};
if (GetMenuItemInfo(hmenu, wparam, FALSE, &item)) {
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Fix formatting and memory allocation in tray_windows.c Fix formatting and memory allocation in tray_windows.c fix: windows messy code
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
e9b6da8 to
e8f3d03
Compare
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #74 +/- ##
==========================================
- Coverage 60.30% 60.24% -0.07%
==========================================
Files 4 4
Lines 325 332 +7
Branches 61 62 +1
==========================================
+ Hits 196 200 +4
- Misses 95 97 +2
- Partials 34 35 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
|



Description
Fix Windows menu and tray icon text appears Chinese garbled problem.
Older versions use ANSI APIs (MENUITEMINFO, Shell_Icon) resulting in a higher level of API usage when the system code page is GBK/CP936
If you enter a UTF-8 encoded string, garbled text appears.
This change switches to Unicode API:
English ASCII characters (0x00–0x7F) are identical in all common encodings:
English : Open Sunshine
UTF-8: 4F 70 65 6E 20 53 75 6E 73 68 69 6E 65
GBK: 4F 70 65 6E 20 53 75 6E 73 68 69 6E 65
ASCII: 4F 70 65 6E 20 53 75 6E 73 68 69 6E 65
Screenshot
After repair (normal display chinese):

Issues Fixed or Closed
Roadmap Issues
Type of Change
Checklist
AI Usage