我很难为编辑控件设置字体。我用过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 上的值,它们非常合理,但我可以根据要求显示它们。
关于为什么字体没有被改变的任何建议?