[英]Cannot set font on edit control
我在為編輯控件設置字體時遇到困難。 我使用過SendMessage(hwnd, WM_FONT, args)
但它似乎沒有效果。 我添加了EM_SETMODIFY
消息,但這也沒有效果。 這是我一直在使用的代碼:
class EditBox : public Wide::OS::EditBox {
HWND box;
std::unique_ptr<std::decay<decltype(*HFONT())>::type, decltype(&DeleteObject)> font;
Math::AbsolutePoint curr_pos;
Math::AbsolutePoint curr_dim;
public:
void SetFont(std::shared_ptr<Render::Font> f) {
font = decltype(this->font)(CreateFontIndirect(&dynamic_cast<Wide::Direct3D9::Font*>(f.get())->GetLogFont()), &DeleteObject);
SendMessage(box, WM_SETFONT, reinterpret_cast<WPARAM>(font.get()), true);
SendMessage(box, EM_SETMODIFY, true, 0);
}
EditBox(std::shared_ptr<Render::Font> font, HWND owner, Math::AbsolutePoint position, Math::AbsolutePoint dimensions, HINSTANCE hinst)
: curr_pos(position), curr_dim(dimensions), font(CreateFontIndirect(&dynamic_cast<Wide::Direct3D9::Font*>(font.get())->GetLogFont()), &DeleteObject){
box = CreateWindowEx(
0,
L"EDIT",
L"Type here",
WS_VISIBLE | WS_CHILD | WS_TABSTOP | ES_LEFT,
position.x,
position.y,
dimensions.x,
dimensions.y,
owner,
0,
hinst,
0);
/*SetWindowSubclass(box, [](HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam, UINT_PTR, DWORD_PTR) -> LRESULT {
if (msg != WM_PAINT)
return DefSubclassProc(hwnd, msg, wparam, lparam);
PAINTSTRUCT paint;
BeginPaint(hwnd, &paint);
EndPaint(hwnd, &paint);
return 0;
}, 0, 0);*/
SendMessage(box, WM_SETFONT, reinterpret_cast<WPARAM>(font.get()), true);
SendMessage(box, EM_SETMODIFY, true, 0);
}
~EditBox() { DestroyWindow(box); }
};
我檢查了我要回來的 LOGFONT 上的值,它們非常合理,但我可以根據要求顯示它們。
關於為什么字體沒有被改變的任何建議?
構造函數中該死的變量陰影。 傳遞的指針實際上是一個Render::Font*
,而不是來自存儲變量的HFONT
。 當然,我沒有正確測試是SetFont
不起作用,還是構造函數不起作用。 如果只有 Windows 使用實際函數而不是那些令人討厭的消息,所以我不必reinterpret_cast
,將會有一個很好的編譯器錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.