#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; if (uMsg == ALF_WM_QUERYSIZE) { HDC hDc = GetDC(hwnd); HFONT font = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0); 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*ALF_Compat_GetSystemMetricsForDpi( SM_CYEDGE, (UINT)ALF_CentipointsToPixels(GetParent(hwnd), 7200)) + 4 /* padding internal to the edit control */; } } SelectFont(hDc, oldfont); ReleaseDC(hwnd, hDc); return 0; } else if (uMsg == ALF_WM_APPLYSIZE) { RECT *p = (RECT *)lParam; // SWP_NOCOPYBITS as a bandaid since NT 3.51 doesn't invalidate properly return (LRESULT)DeferWindowPos((HDWP)wParam, hwnd, NULL, p->left, p->top, p->right - p->left, p->bottom - p->top, SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOCOPYBITS); } else if (uMsg == WM_DESTROY) { ALF_Compat_RemoveWindowSubclass(hwnd, ALF__EditSubclassProc, 0); } else if (uMsg == WM_SETFONT) { ALF_InvalidateLayout(GetParent(hwnd)); } return ALF_Compat_DefSubclassProc(hwnd, uMsg, wParam, lParam); } HWND ALF_AddEdit(HWND win, WORD id, int x, int y, const TCHAR *text) { DWORD exstyle; DWORD style; if (ALF_Compat_IsMinWindowsVersion(4, 0)) { exstyle = WS_EX_CLIENTEDGE; style = 0; } else { exstyle = 0; style = WS_BORDER; } HWND hwndEdit = CreateWindowEx(exstyle, TEXT("EDIT"), text, WS_CHILD | WS_VISIBLE | WS_TABSTOP | style, 0, 0, 100, 100, win, (HMENU)(int)id, (HINSTANCE)GetWindowLongPtr(win, GWLP_HINSTANCE), NULL); ALF_Compat_SetWindowSubclass(hwndEdit, ALF__EditSubclassProc, 0, 0); SetWindowPos(hwndEdit, NULL, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_FRAMECHANGED); ALF_AddWidget(win, x, y, hwndEdit, 0, 0, ALF_LAYOUT_SIZE_QUERY | ALF_LAYOUT_CUSTOMPOS | ALF_LAYOUT_INHERITFONT); return hwndEdit; }