我正在创建 Win32 控件:
m_progress = CreateWindowExW(0, PROGRESS_CLASSW, L"ProgressBar", WS_VISIBLE | WS_CHILD | WS_TABSTOP, 153, 339, 135, 33, m_window, (HMENU)0, m_instance, 0);
SendMessageW(m_progress, WM_SETFONT, (WPARAM)m_fontBold, TRUE);
SendMessageW(m_progress, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
它正在工作,但我也想在上面绘制带有百分比的文本所以我将进度控制子类化如下:
m_progressPrevProc = (WNDPROC)SetWindowLongPtrW(m_progress, GWLP_WNDPROC, (LONG_PTR)ProgressMsgProcessor);
...
static LRESULT CALLBACK ProgressMsgProcessor(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
if (msg == WM_PAINT)
{
PAINTSTRUCT ps;
RECT rc = { 5, 5, 135, 33 };
//HDC hdc = BeginPaint(hwnd, &ps);
//SelectObject(hdc, g_App.m_fontBold);
//DrawTextA(hdc, "100 %", -1, &rc, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
//EndPaint(hwnd, &ps);
}
return CallWindowProcW((WNDPROC)PrevWndProcProzess, hwnd, msg, wparam, lparam);
}
但如果至少取消注释“HDC hdc = BeginPaint(hwnd, &ps);” 然后出现文本,但默认控件绝对消失(就像它没有被绘制) 我怎样才能修复它以显示带有文本的默认 Windows 控件,因为我不需要绘制自定义控件,只添加覆盖文本?谢谢