I’m having difficulty setting a font for an edit control. I’ve used SendMessage(hwnd, WM_FONT, args) but it appears to have no effect. I added EM_SETMODIFY message but that also has had no effect. Here’s the code I’ve been using:
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); }
};
I checked the values on the LOGFONT I’m getting back and they are quite reasonable, but I could show them upon request.
Any suggestions as to why the font is not being altered?
The damn variable shadowing in the constructor. The pointer being passed is actually a
Render::Font*, not theHFONTfrom the stored variable. I, of course, did not correctly test whether it wasSetFontwhich did not work, or the constructor which did not work. If only Windows used actual functions instead of those icky messages so I didn’t have toreinterpret_cast, woulda had a nice compiler error.