Skip to content

fix(windows): incorrect UTF8/GBK string encoding handling#74

Merged
ReenigneArcher merged 2 commits into
LizardByte:masterfrom
Yundi339:fix_win_messy
Nov 25, 2025
Merged

fix(windows): incorrect UTF8/GBK string encoding handling#74
ReenigneArcher merged 2 commits into
LizardByte:masterfrom
Yundi339:fix_win_messy

Conversation

@Yundi339

@Yundi339 Yundi339 commented Oct 30, 2025

Copy link
Copy Markdown

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:

  • Use MENUITEMINFOW, Shell_NotifyIconW
  • Convert UTF-8 to UTF-16 via MultiByteToWideChar before invocation
  • Solved the abnormal display problem of multi-language environment such as Chinese and Japanese.

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):
33a1446b103252af4f95fc87519106a7

Issues Fixed or Closed

Roadmap Issues

  • None

Type of Change

  • fix: Bug fix (non-breaking change which fixes an issue)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas
  • Code docstring/documentation-blocks for new or existing methods/components have been added or updated
  • Unit tests have been added or updated for any new or modified functionality

AI Usage

  • Moderate: AI helped with code generation or debugging specific parts

@ReenigneArcher

Copy link
Copy Markdown
Member

Why did you close #73 ?

@Yundi339

Copy link
Copy Markdown
Author

Why did you close #73 ?

Yes, I closed it. Sorry~~
My intention was to reopen the PR once the git force push was successful. However, I've since found out that GitHub does not allow a closed Pull Request to be reopened after its history has been forcefully overwritten.

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.

@ReenigneArcher

Copy link
Copy Markdown
Member

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.

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/tray_windows.c
Yundi339 and others added 2 commits November 24, 2025 18:58
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>
@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Nov 24, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 61.90476% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.24%. Comparing base (4d1dafc) to head (e8f3d03).
⚠️ Report is 11 commits behind head on master.

Files with missing lines Patch % Lines
src/tray_windows.c 61.90% 7 Missing and 1 partial ⚠️
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     
Flag Coverage Δ
Linux 49.05% <ø> (ø)
Windows 53.60% <61.90%> (+0.13%) ⬆️
libappindicator3-dev 49.05% <ø> (ø)
libayatana-appindicator3-dev 49.05% <ø> (ø)
macOS 56.41% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/tray_windows.c 60.81% <61.90%> (-0.16%) ⬇️

@ReenigneArcher ReenigneArcher merged commit d43f4c2 into LizardByte:master Nov 25, 2025
19 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Simplified Chinese characters are garbled under Windows 10 platform

3 participants