无法在编辑控件上设置字体
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
,就会有一个很好的编译器错误。
相关文章:
- C++ wxWidgets:在创建小部件后设置字体
- 从 QFontDatabase 设置 QFont 将所有标签设置为等宽字体?Qt C++
- 如何获取控制面板设置值,如字体大小
- QPlainTextEdit 仅设置一行字体
- 我如何将编程控制台字体设置为Lucida
- 应用字体更改后,丢失样式表设置
- 轮廓字体倒置 - glOrtho() 设置不正确
- 无法在编辑控件上设置字体
- Qt4/PyQt4-无法设置QTextDocument的默认字体
- 如何在Windows日历控件上设置字体
- Win32:设置富编辑的默认字体和文本颜色
- 如何获取样式表设置的Qt中小部件的字体
- 在全屏模式下设置控制台字体大小
- 如何以编程方式将控制台字体设置为“光栅字体”
- QAxObject Excel工作表--为整个Excel工作表设置默认字体
- 使用DEFAULT_GUI_Font设置HFONT的字体大小
- 如何在富编辑中设置字体
- 使用QStandardItemModel的QComboBox样式表设置字体
- 如何在win-api中设置整个应用程序的字体
- 在C++中以编程方式设置 Firemonkey 控件字体