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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
#include "main.h"
#include ".\infoBox.h"
MLInfoBox::MLInfoBox(void)
{
oldWndProc = NULL;
m_hwnd = NULL;
bodyBrush = NULL;
headerBrush = NULL;
headerText[0] = 0;
SetColors(RGB(0,0,0), RGB(255,255,255), RGB(0,60,0));
SetRect(&rcBody, 0,0,0,0);
drawHeader = TRUE;
SetRect(&rcHeader, 0,0,0,20); // default height
headerFont = NULL;
}
MLInfoBox::~MLInfoBox(void)
{
SetWindowLong(m_hwnd, GWLP_WNDPROC, (LONGX86)(LONG_PTR)oldWndProc);
oldWndProc = NULL;
if (headerBrush) DeleteObject(headerBrush);
headerBrush = NULL;
if (bodyBrush) DeleteObject(bodyBrush);
bodyBrush = NULL;
if (headerFont) DeleteObject(headerFont);
headerFont = NULL;
}
void MLInfoBox::SetColors(COLORREF bodyBG, COLORREF headerFG, COLORREF headerBG)
{
this->bodyBG = bodyBG;
this->headerFG = headerFG;
this->headerBG = headerBG;
if (headerBrush) DeleteObject(headerBrush);
headerBrush = NULL;
headerBrush = CreateSolidBrush(headerBG);
if (bodyBrush) DeleteObject(bodyBrush);
bodyBrush = NULL;
bodyBrush = CreateSolidBrush(bodyBG);
}
void MLInfoBox::Init(HWND hwnd)
{
m_hwnd = hwnd;
HDC hdc = GetDC(hwnd);
long lfHeight;
lfHeight = -MulDiv(8, GetDeviceCaps(hdc, LOGPIXELSY), 72);
headerFont = CreateFontW(lfHeight, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, L"Arial");
ReleaseDC(hwnd, hdc);
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONGX86)(LONG_PTR)this);
oldWndProc= (WNDPROC)(LONG_PTR)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONGX86)(LONG_PTR)newWndProc);
RECT rc;
GetWindowRect(hwnd, &rc);
SetSize(rc.right - rc.left, rc.bottom - rc.top);
}
void MLInfoBox::SetSize(int cx, int cy)
{
int offset = 0;
if (drawHeader)
{
SetRect(&rcHeader, 0,0, cx, rcHeader.bottom);
offset = rcHeader.bottom;
}
SetRect(&rcBody, 0, offset, cx, cy);
}
LRESULT CALLBACK MLInfoBox::newWndProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
{
MLInfoBox *box = (MLInfoBox*)(LONG_PTR)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
switch(uMsg)
{
case WM_SIZE:
if (SIZE_MINIMIZED != wParam)
{
box->SetSize(LOWORD(lParam), HIWORD(lParam));
}
break;
case WM_ERASEBKGND:
{
HDC hdc = GetDC(hwndDlg);
SetTextColor(hdc, box->headerFG);
SetBkColor(hdc, box->headerBG);
RECT txtRect;
SetRect(&txtRect, box->rcHeader.left + 8, box->rcHeader.top + 2, box->rcHeader.right -2, box->rcHeader.bottom -2);
HFONT oldFont = (HFONT)SelectObject(hdc, box->headerFont);
GetWindowTextW(hwndDlg, box->headerText, CAPTION_LENGTH);
DrawTextW(hdc, box->headerText, -1, &txtRect, DT_VCENTER | DT_LEFT | DT_SINGLELINE);
SelectObject(hdc, oldFont);
ReleaseDC(hwndDlg, hdc);
}
return TRUE;
break;
case WM_PAINT:
{
PAINTSTRUCT pt;
HDC hdc = BeginPaint(hwndDlg, &pt);
RECT drawRect ;
if(box->drawHeader && IntersectRect(&drawRect, &box->rcHeader, &pt.rcPaint))
{
FillRect(hdc, &drawRect, box->headerBrush);
SetTextColor(hdc, box->headerFG);
SetBkColor(hdc, box->headerBG);
SetRect(&drawRect, box->rcHeader.left + 8, box->rcHeader.top + 2, box->rcHeader.right -2, box->rcHeader.bottom -2);
HFONT oldFont = (HFONT)SelectObject(hdc, box->headerFont);
GetWindowTextW(hwndDlg, box->headerText, CAPTION_LENGTH);
DrawTextW(hdc, box->headerText, -1, &drawRect, DT_VCENTER | DT_LEFT | DT_SINGLELINE);
SelectObject(hdc, oldFont);
ValidateRect(hwndDlg, &drawRect);
}
if(IntersectRect(&drawRect, &box->rcBody, &pt.rcPaint))
{
FillRect(hdc, &drawRect, box->bodyBrush);
ValidateRect(hwndDlg, &drawRect);
}
EndPaint(hwndDlg, &pt);
}
break;
}
return CallWindowProc(box->oldWndProc, hwndDlg, uMsg, wParam, lParam);
}
|