Skip to content

Commit 65f7ddc

Browse files
Copilotlijy91
andcommitted
Complete Windows API fixes - Shell_NotifyIconW, GetMenuItemInfoW, and strdup
Co-authored-by: lijy91 <3889523+lijy91@users.noreply.github.com>
1 parent c55484e commit 65f7ddc

3 files changed

Lines changed: 18 additions & 12 deletions

File tree

src/capi/display_manager_c.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
#include <iostream>
33
#include <vector>
44

5+
#ifdef _WIN32
6+
#define STRDUP _strdup
7+
#else
8+
#define STRDUP strdup
9+
#endif
10+
511
#include "../display.h"
612
#include "../display_manager.h"
713

@@ -31,13 +37,13 @@ native_display_t to_native_display(const Display& raw_display) {
3137
native_display_t display = {};
3238

3339
// Allocate and copy strings
34-
display.id = strdup(raw_display.id.c_str());
35-
display.name = strdup(raw_display.name.c_str());
40+
display.id = STRDUP(raw_display.id.c_str());
41+
display.name = STRDUP(raw_display.name.c_str());
3642
display.manufacturer = raw_display.manufacturer.empty()
3743
? nullptr
38-
: strdup(raw_display.manufacturer.c_str());
44+
: STRDUP(raw_display.manufacturer.c_str());
3945
display.model =
40-
raw_display.model.empty() ? nullptr : strdup(raw_display.model.c_str());
46+
raw_display.model.empty() ? nullptr : STRDUP(raw_display.model.c_str());
4147
display.serial_number = nullptr; // Not available in the C++ API
4248

4349
// Copy position

src/platform/windows/tray_windows.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,19 +133,19 @@ class Tray::Impl {
133133
// Store tray pointer in window
134134
SetWindowLongPtr(hwnd_, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(tray_ptr_));
135135

136-
Shell_NotifyIcon(NIM_ADD, &nid_);
136+
Shell_NotifyIconW(NIM_ADD, &nid_);
137137
}
138138

139139
void RemoveTrayIcon() {
140140
if (hwnd_) {
141-
Shell_NotifyIcon(NIM_DELETE, &nid_);
141+
Shell_NotifyIconW(NIM_DELETE, &nid_);
142142
}
143143
}
144144

145145
void UpdateIcon() {
146146
if (hwnd_ && icon_) {
147147
nid_.hIcon = icon_;
148-
Shell_NotifyIcon(NIM_MODIFY, &nid_);
148+
Shell_NotifyIconW(NIM_MODIFY, &nid_);
149149
}
150150
}
151151

@@ -155,7 +155,7 @@ class Tray::Impl {
155155
std::wstring wtooltip = StringToWideString(tooltip);
156156
wcsncpy_s(nid_.szTip, sizeof(nid_.szTip) / sizeof(wchar_t), wtooltip.c_str(), _TRUNCATE);
157157

158-
Shell_NotifyIcon(NIM_MODIFY, &nid_);
158+
Shell_NotifyIconW(NIM_MODIFY, &nid_);
159159
}
160160

161161
HWND hwnd_;

src/platform/windows/window_windows.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,10 @@ bool Window::IsClosable() const {
390390
if (pimpl_->hwnd_) {
391391
HMENU hMenu = GetSystemMenu(pimpl_->hwnd_, FALSE);
392392
if (hMenu) {
393-
MENUITEMINFO mii = {};
394-
mii.cbSize = sizeof(MENUITEMINFO);
393+
MENUITEMINFOW mii = {};
394+
mii.cbSize = sizeof(MENUITEMINFOW);
395395
mii.fMask = MIIM_STATE;
396-
if (GetMenuItemInfo(hMenu, SC_CLOSE, FALSE, &mii)) {
396+
if (GetMenuItemInfoW(hMenu, SC_CLOSE, FALSE, &mii)) {
397397
return !(mii.fState & MFS_GRAYED);
398398
}
399399
}
@@ -448,7 +448,7 @@ void Window::SetTitle(std::string title) {
448448

449449
std::string Window::GetTitle() {
450450
if (pimpl_->hwnd_) {
451-
int length = GetWindowTextLength(pimpl_->hwnd_);
451+
int length = GetWindowTextLengthW(pimpl_->hwnd_);
452452
if (length > 0) {
453453
std::wstring wtitle(length + 1, L'\0');
454454
GetWindowTextW(pimpl_->hwnd_, &wtitle[0], length + 1);

0 commit comments

Comments
 (0)