#include "alfpriv.h" /* EDIT */ static LRESULT CALLBACK ALF__EditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData) { (void)uIdSubclass; (void)dwRefData; ALFAPP app = (ALFAPP)dwRefData; if (uMsg == ALF_WM_QUERYSIZE) { HDC hDc = GetDC(hwnd); HFONT font = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0); if (font) { HFONT oldfont = SelectFont(hDc, font); TEXTMETRIC tm; ZeroMemory(&tm, sizeof(tm)); if (GetTextMetrics(hDc, &tm)) { SIZE *ps = (SIZE*)lParam; if (!ps->cx) { ps->cx = ALF_CentipointsToPixels(GetParent(hwnd), 12000); } if (!ps->cy) { ps->cy = tm.tmHeight + 2*app->compatFn->GetSystemMetricsForDpi( SM_CYEDGE, ALF_CentipointsToPixels(GetParent(hwnd), 7200)) + 2 /* padding internal to the edit control */ + 2 /* external padding to line up with themed button */; } } SelectFont(hDc, oldfont); } ReleaseDC(hwnd, hDc); return 0; } else if (uMsg == ALF_WM_APPLYSIZE) { RECT *p = (RECT *)lParam; return (LRESULT)DeferWindowPos((HDWP)wParam, hwnd, NULL, p->left, p->top + 1, p->right - p->left, p->bottom - p->top - 2, SWP_NOZORDER|SWP_NOACTIVATE); } return app->compatFn->DefSubclassProc(hwnd, uMsg, wParam, lParam); } HWND ALF_AddEdit(HWND win, WORD id, UINT x, UINT y, const TCHAR *text) { HWND hwndEdit = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("EDIT"), text, WS_CHILD | WS_VISIBLE | WS_TABSTOP, 0, 0, 100, 100, win, (HMENU)(int)id, (HINSTANCE)GetWindowLongPtr(win, GWLP_HINSTANCE), NULL); ALFAPP app = ALF_ApplicationFromWindow(win); app->compatFn->SetWindowSubclass(hwndEdit, ALF__EditSubclassProc, 0, (DWORD_PTR)app); SetWindowPos(hwndEdit, NULL, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_FRAMECHANGED); ALFAddWidgetParams p; ZeroMemory(&p, sizeof(p)); p.hwnd = hwndEdit; p.x = x; p.y = y; p.width = 0; p.height = 0; p.flags = ALF_QUERYSIZE | ALF_APPLYSIZE | ALF_MESSAGEFONT; ALF_AddWidgetEx(win, &p); return hwndEdit; }