Updater: Replace incorrect ANSI Win32 calls

This commit is contained in:
Stenzek
2025-11-20 12:55:23 +10:00
parent acadbffe1c
commit 8f5a1fdcf0
2 changed files with 42 additions and 36 deletions

View File

@@ -15,6 +15,11 @@ Win32ProgressCallback::Win32ProgressCallback() : ProgressCallback()
Create();
}
Win32ProgressCallback::~Win32ProgressCallback()
{
Destroy();
}
void Win32ProgressCallback::PushState()
{
ProgressCallback::PushState();
@@ -34,7 +39,7 @@ void Win32ProgressCallback::SetCancellable(bool cancellable)
void Win32ProgressCallback::SetTitle(const std::string_view title)
{
SetWindowTextW(m_window_hwnd, StringUtil::UTF8StringToWideString(title).c_str());
SetWindowText(m_window_hwnd, StringUtil::UTF8StringToWideString(title).c_str());
}
void Win32ProgressCallback::SetStatusText(const std::string_view text)
@@ -73,7 +78,7 @@ bool Win32ProgressCallback::Create()
wc.hCursor = LoadCursor(NULL, IDC_WAIT);
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.lpszClassName = CLASS_NAME;
if (!RegisterClassExW(&wc))
if (!RegisterClassEx(&wc))
{
ERROR_LOG("Failed to register window class");
return false;
@@ -82,8 +87,8 @@ bool Win32ProgressCallback::Create()
class_registered = true;
}
m_window_hwnd = CreateWindowExW(WS_EX_CLIENTEDGE, CLASS_NAME, L"", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
WINDOW_WIDTH, WINDOW_HEIGHT, nullptr, nullptr, GetModuleHandle(nullptr), this);
m_window_hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, CLASS_NAME, L"", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
WINDOW_WIDTH, WINDOW_HEIGHT, nullptr, nullptr, GetModuleHandle(nullptr), this);
if (!m_window_hwnd)
{
ERROR_LOG("Failed to create window");
@@ -110,10 +115,10 @@ void Win32ProgressCallback::Destroy()
void Win32ProgressCallback::PumpMessages()
{
MSG msg;
while (PeekMessageA(&msg, m_window_hwnd, 0, 0, PM_REMOVE))
while (PeekMessage(&msg, m_window_hwnd, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessageA(&msg);
DispatchMessage(&msg);
}
}
@@ -129,9 +134,9 @@ void Win32ProgressCallback::Redraw(bool force)
m_last_progress_percent = percent;
SendMessageA(m_progress_hwnd, PBM_SETRANGE, 0, MAKELPARAM(0, m_progress_range));
SendMessageA(m_progress_hwnd, PBM_SETPOS, static_cast<WPARAM>(m_progress_value), 0);
SetWindowTextA(m_text_hwnd, m_status_text.c_str());
SendMessage(m_progress_hwnd, PBM_SETRANGE, 0, MAKELPARAM(0, m_progress_range));
SendMessage(m_progress_hwnd, PBM_SETPOS, static_cast<WPARAM>(m_progress_value), 0);
SetWindowText(m_text_hwnd, StringUtil::UTF8StringToWideString(m_status_text).c_str());
RedrawWindow(m_text_hwnd, nullptr, nullptr, RDW_INVALIDATE);
PumpMessages();
}
@@ -141,7 +146,7 @@ LRESULT CALLBACK Win32ProgressCallback::WndProcThunk(HWND hwnd, UINT msg, WPARAM
Win32ProgressCallback* cb;
if (msg == WM_CREATE)
{
const CREATESTRUCTA* cs = reinterpret_cast<CREATESTRUCTA*>(lparam);
const CREATESTRUCT* cs = reinterpret_cast<CREATESTRUCT*>(lparam);
cb = static_cast<Win32ProgressCallback*>(cs->lpCreateParams);
}
else
@@ -158,31 +163,31 @@ LRESULT CALLBACK Win32ProgressCallback::WndProc(HWND hwnd, UINT msg, WPARAM wpar
{
case WM_CREATE:
{
const CREATESTRUCTA* cs = reinterpret_cast<CREATESTRUCTA*>(lparam);
HFONT default_font = reinterpret_cast<HFONT>(GetStockObject(ANSI_VAR_FONT));
SendMessageA(hwnd, WM_SETFONT, WPARAM(default_font), TRUE);
const CREATESTRUCT* cs = reinterpret_cast<CREATESTRUCT*>(lparam);
const HFONT default_font = reinterpret_cast<HFONT>(GetStockObject(DEFAULT_GUI_FONT));
SendMessage(hwnd, WM_SETFONT, WPARAM(default_font), TRUE);
int y = WINDOW_MARGIN;
m_text_hwnd = CreateWindowExA(0, "Static", nullptr, WS_VISIBLE | WS_CHILD, WINDOW_MARGIN, y, SUBWINDOW_WIDTH, 16,
hwnd, nullptr, cs->hInstance, nullptr);
SendMessageA(m_text_hwnd, WM_SETFONT, WPARAM(default_font), TRUE);
m_text_hwnd = CreateWindowEx(0, L"Static", nullptr, WS_VISIBLE | WS_CHILD, WINDOW_MARGIN, y, SUBWINDOW_WIDTH, 16,
hwnd, nullptr, cs->hInstance, nullptr);
SendMessage(m_text_hwnd, WM_SETFONT, WPARAM(default_font), TRUE);
y += 16 + WINDOW_MARGIN;
m_progress_hwnd = CreateWindowExA(0, PROGRESS_CLASSA, nullptr, WS_VISIBLE | WS_CHILD, WINDOW_MARGIN, y,
SUBWINDOW_WIDTH, 32, hwnd, nullptr, cs->hInstance, nullptr);
m_progress_hwnd = CreateWindowEx(0, PROGRESS_CLASSW, nullptr, WS_VISIBLE | WS_CHILD, WINDOW_MARGIN, y,
SUBWINDOW_WIDTH, 32, hwnd, nullptr, cs->hInstance, nullptr);
y += 32 + WINDOW_MARGIN;
m_list_box_hwnd =
CreateWindowExA(0, "LISTBOX", nullptr, WS_VISIBLE | WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_BORDER | LBS_NOSEL,
WINDOW_MARGIN, y, SUBWINDOW_WIDTH, 170, hwnd, nullptr, cs->hInstance, nullptr);
SendMessageA(m_list_box_hwnd, WM_SETFONT, WPARAM(default_font), TRUE);
CreateWindowEx(0, L"LISTBOX", nullptr, WS_VISIBLE | WS_CHILD | WS_VSCROLL | WS_HSCROLL | WS_BORDER | LBS_NOSEL,
WINDOW_MARGIN, y, SUBWINDOW_WIDTH, 170, hwnd, nullptr, cs->hInstance, nullptr);
SendMessage(m_list_box_hwnd, WM_SETFONT, WPARAM(default_font), TRUE);
y += 170;
}
break;
default:
return DefWindowProcA(hwnd, msg, wparam, lparam);
return DefWindowProc(hwnd, msg, wparam, lparam);
}
return 0;
@@ -191,27 +196,27 @@ LRESULT CALLBACK Win32ProgressCallback::WndProc(HWND hwnd, UINT msg, WPARAM wpar
void Win32ProgressCallback::DisplayError(const std::string_view message)
{
ERROR_LOG(message);
SendMessageW(m_list_box_hwnd, LB_ADDSTRING, 0,
reinterpret_cast<LPARAM>(StringUtil::UTF8StringToWideString(message).c_str()));
SendMessageW(m_list_box_hwnd, WM_VSCROLL, SB_BOTTOM, 0);
SendMessage(m_list_box_hwnd, LB_ADDSTRING, 0,
reinterpret_cast<LPARAM>(StringUtil::UTF8StringToWideString(message).c_str()));
SendMessage(m_list_box_hwnd, WM_VSCROLL, SB_BOTTOM, 0);
PumpMessages();
}
void Win32ProgressCallback::DisplayWarning(const std::string_view message)
{
WARNING_LOG(message);
SendMessageW(m_list_box_hwnd, LB_ADDSTRING, 0,
reinterpret_cast<LPARAM>(StringUtil::UTF8StringToWideString(message).c_str()));
SendMessageW(m_list_box_hwnd, WM_VSCROLL, SB_BOTTOM, 0);
SendMessage(m_list_box_hwnd, LB_ADDSTRING, 0,
reinterpret_cast<LPARAM>(StringUtil::UTF8StringToWideString(message).c_str()));
SendMessage(m_list_box_hwnd, WM_VSCROLL, SB_BOTTOM, 0);
PumpMessages();
}
void Win32ProgressCallback::DisplayInformation(const std::string_view message)
{
INFO_LOG(message);
SendMessageW(m_list_box_hwnd, LB_ADDSTRING, 0,
reinterpret_cast<LPARAM>(StringUtil::UTF8StringToWideString(message).c_str()));
SendMessageW(m_list_box_hwnd, WM_VSCROLL, SB_BOTTOM, 0);
SendMessage(m_list_box_hwnd, LB_ADDSTRING, 0,
reinterpret_cast<LPARAM>(StringUtil::UTF8StringToWideString(message).c_str()));
SendMessage(m_list_box_hwnd, WM_VSCROLL, SB_BOTTOM, 0);
PumpMessages();
}
@@ -223,21 +228,21 @@ void Win32ProgressCallback::DisplayDebugMessage(const std::string_view message)
void Win32ProgressCallback::ModalError(const std::string_view message)
{
PumpMessages();
MessageBoxW(m_window_hwnd, StringUtil::UTF8StringToWideString(message).c_str(), L"Error", MB_ICONERROR | MB_OK);
MessageBox(m_window_hwnd, StringUtil::UTF8StringToWideString(message).c_str(), L"Error", MB_ICONERROR | MB_OK);
PumpMessages();
}
bool Win32ProgressCallback::ModalConfirmation(const std::string_view message)
{
PumpMessages();
bool result = MessageBoxW(m_window_hwnd, StringUtil::UTF8StringToWideString(message).c_str(), L"Confirmation",
MB_ICONQUESTION | MB_YESNO) == IDYES;
bool result = MessageBox(m_window_hwnd, StringUtil::UTF8StringToWideString(message).c_str(), L"Confirmation",
MB_ICONQUESTION | MB_YESNO) == IDYES;
PumpMessages();
return result;
}
void Win32ProgressCallback::ModalInformation(const std::string_view message)
{
MessageBoxW(m_window_hwnd, StringUtil::UTF8StringToWideString(message).c_str(), L"Information",
MB_ICONINFORMATION | MB_OK);
MessageBox(m_window_hwnd, StringUtil::UTF8StringToWideString(message).c_str(), L"Information",
MB_ICONINFORMATION | MB_OK);
}

View File

@@ -9,6 +9,7 @@ class Win32ProgressCallback final : public ProgressCallback
{
public:
Win32ProgressCallback();
~Win32ProgressCallback() override;
void PushState() override;
void PopState() override;