@@ -99,16 +99,16 @@ class Tray::Impl {
9999 // Register window class if not already registered
100100 static bool class_registered = false ;
101101 if (!class_registered) {
102- WNDCLASS wc = {};
102+ WNDCLASSW wc = {};
103103 wc.lpfnWndProc = TrayWindowProc;
104104 wc.hInstance = GetModuleHandle (nullptr );
105105 wc.lpszClassName = TRAY_WINDOW_CLASS;
106- RegisterClass (&wc);
106+ RegisterClassW (&wc);
107107 class_registered = true ;
108108 }
109109
110110 // Create hidden window for tray messages
111- hwnd_ = CreateWindow (
111+ hwnd_ = CreateWindowW (
112112 TRAY_WINDOW_CLASS,
113113 L" TrayWindow" ,
114114 WS_OVERLAPPED,
@@ -122,13 +122,13 @@ class Tray::Impl {
122122 void InitializeTrayIcon () {
123123 if (!hwnd_) return ;
124124
125- nid_.cbSize = sizeof (NOTIFYICONDATA );
125+ nid_.cbSize = sizeof (NOTIFYICONDATAW );
126126 nid_.hWnd = hwnd_;
127127 nid_.uID = tray_uid_;
128128 nid_.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
129129 nid_.uCallbackMessage = g_tray_message;
130130 nid_.hIcon = LoadIcon (nullptr , IDI_APPLICATION); // Default icon
131- wcscpy_s (nid_.szTip , L" Tray Icon" );
131+ wcscpy_s (nid_.szTip , sizeof (nid_. szTip )/ sizeof ( wchar_t ), L" Tray Icon" );
132132
133133 // Store tray pointer in window
134134 SetWindowLongPtr (hwnd_, GWLP_USERDATA, reinterpret_cast <LONG_PTR>(tray_ptr_));
@@ -153,15 +153,14 @@ class Tray::Impl {
153153 if (!hwnd_) return ;
154154
155155 std::wstring wtooltip = StringToWideString (tooltip);
156- wcsncpy_s (nid_.szTip , wtooltip.c_str (), sizeof (nid_.szTip ) / sizeof (wchar_t ) - 1 );
157- nid_.szTip [sizeof (nid_.szTip ) / sizeof (wchar_t ) - 1 ] = L' \0 ' ;
156+ wcsncpy_s (nid_.szTip , sizeof (nid_.szTip ) / sizeof (wchar_t ), wtooltip.c_str (), _TRUNCATE);
158157
159158 Shell_NotifyIcon (NIM_MODIFY, &nid_);
160159 }
161160
162161 HWND hwnd_;
163162 UINT tray_uid_;
164- NOTIFYICONDATA nid_;
163+ NOTIFYICONDATAW nid_;
165164 HICON icon_;
166165 std::string title_;
167166 std::string tooltip_;
@@ -200,7 +199,7 @@ void Tray::SetIcon(std::string icon) {
200199 } else if (!icon.empty ()) {
201200 // Load icon from file path
202201 std::wstring wicon = StringToWideString (icon);
203- pimpl_->icon_ = (HICON)LoadImage (
202+ pimpl_->icon_ = (HICON)LoadImageW (
204203 nullptr ,
205204 wicon.c_str (),
206205 IMAGE_ICON,
@@ -246,9 +245,9 @@ Rectangle Tray::GetBounds() {
246245
247246 if (pimpl_->hwnd_ ) {
248247 // Get the position of the notification area
249- HWND hTray = FindWindow (L" Shell_TrayWnd" , nullptr );
248+ HWND hTray = FindWindowW (L" Shell_TrayWnd" , nullptr );
250249 if (hTray) {
251- HWND hNotify = FindWindowEx (hTray, nullptr , L" TrayNotifyWnd" , nullptr );
250+ HWND hNotify = FindWindowExW (hTray, nullptr , L" TrayNotifyWnd" , nullptr );
252251 if (hNotify) {
253252 RECT rect;
254253 GetWindowRect (hNotify, &rect);
0 commit comments