1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
#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))
+ 4 /* 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);
} else if (uMsg == WM_DESTROY) {
app->compatFn->RemoveWindowSubclass(hwnd, ALF__EditSubclassProc, 0);
}
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);
ALFWidgetLayoutParams 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;
}
|