1*b4d691baSGiannis Adamopoulos #include <windows.h>
2*b4d691baSGiannis Adamopoulos #include <uxtheme.h>
3*b4d691baSGiannis Adamopoulos #include <stdlib.h>
4*b4d691baSGiannis Adamopoulos #include <tchar.h>
5*b4d691baSGiannis Adamopoulos #include "resource.h"
6*b4d691baSGiannis Adamopoulos
7*b4d691baSGiannis Adamopoulos LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
8*b4d691baSGiannis Adamopoulos
9*b4d691baSGiannis Adamopoulos HICON hico;
10*b4d691baSGiannis Adamopoulos HBITMAP hbmp;
11*b4d691baSGiannis Adamopoulos HIMAGELIST himl;
12*b4d691baSGiannis Adamopoulos POINT scPos;
13*b4d691baSGiannis Adamopoulos
14*b4d691baSGiannis Adamopoulos HBRUSH hbrNULL;
15*b4d691baSGiannis Adamopoulos HBRUSH hbrRed;
16*b4d691baSGiannis Adamopoulos HBRUSH hbrGreen;
17*b4d691baSGiannis Adamopoulos HBRUSH hbrBlue;
18*b4d691baSGiannis Adamopoulos HBRUSH hbrCyan;
19*b4d691baSGiannis Adamopoulos HBRUSH hbrYellow;
20*b4d691baSGiannis Adamopoulos
21*b4d691baSGiannis Adamopoulos HBRUSH hbrCtlColorStatic;
22*b4d691baSGiannis Adamopoulos HBRUSH hbrCtlColorBtn;
23*b4d691baSGiannis Adamopoulos HBRUSH hbrPrintClientClear;
24*b4d691baSGiannis Adamopoulos HBRUSH hbrErase;
25*b4d691baSGiannis Adamopoulos
26*b4d691baSGiannis Adamopoulos BOOL bSkipErase;
27*b4d691baSGiannis Adamopoulos BOOL bSkipPaint;
28*b4d691baSGiannis Adamopoulos
RegisterMyClass(HINSTANCE hInst)29*b4d691baSGiannis Adamopoulos static void RegisterMyClass(HINSTANCE hInst)
30*b4d691baSGiannis Adamopoulos {
31*b4d691baSGiannis Adamopoulos WNDCLASSEXW wcex;
32*b4d691baSGiannis Adamopoulos
33*b4d691baSGiannis Adamopoulos wcex.cbSize = sizeof(WNDCLASSEX);
34*b4d691baSGiannis Adamopoulos
35*b4d691baSGiannis Adamopoulos wcex.style = CS_HREDRAW | CS_VREDRAW;
36*b4d691baSGiannis Adamopoulos wcex.lpfnWndProc = WndProc;
37*b4d691baSGiannis Adamopoulos wcex.cbClsExtra = 0;
38*b4d691baSGiannis Adamopoulos wcex.cbWndExtra = 0;
39*b4d691baSGiannis Adamopoulos wcex.hInstance = hInst;
40*b4d691baSGiannis Adamopoulos wcex.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_WIN32PROJECT1));
41*b4d691baSGiannis Adamopoulos wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
42*b4d691baSGiannis Adamopoulos wcex.hbrBackground = NULL;
43*b4d691baSGiannis Adamopoulos wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_MENU);
44*b4d691baSGiannis Adamopoulos wcex.lpszClassName = L"ButtonTests";
45*b4d691baSGiannis Adamopoulos wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
46*b4d691baSGiannis Adamopoulos
47*b4d691baSGiannis Adamopoulos RegisterClassExW(&wcex);
48*b4d691baSGiannis Adamopoulos }
49*b4d691baSGiannis Adamopoulos
50*b4d691baSGiannis Adamopoulos #define TOP_MARGIN 50
51*b4d691baSGiannis Adamopoulos #define LEFT_MARGIN 160
52*b4d691baSGiannis Adamopoulos #define X_GAP 10
53*b4d691baSGiannis Adamopoulos #define Y_GAP 10
54*b4d691baSGiannis Adamopoulos #define Y_HEIGHT 40
55*b4d691baSGiannis Adamopoulos #define X_WIDTH 150
56*b4d691baSGiannis Adamopoulos
CreateWnd(HWND hWnd,LPCWSTR Class,LPCWSTR Text,LONG style,int i,int j)57*b4d691baSGiannis Adamopoulos static HWND CreateWnd(HWND hWnd, LPCWSTR Class, LPCWSTR Text, LONG style, int i, int j)
58*b4d691baSGiannis Adamopoulos {
59*b4d691baSGiannis Adamopoulos return CreateWindowW(Class,
60*b4d691baSGiannis Adamopoulos Text,
61*b4d691baSGiannis Adamopoulos style | WS_CHILD | WS_VISIBLE,
62*b4d691baSGiannis Adamopoulos LEFT_MARGIN + (X_GAP + X_WIDTH) * i,
63*b4d691baSGiannis Adamopoulos TOP_MARGIN + ((Y_GAP + Y_HEIGHT) *j),
64*b4d691baSGiannis Adamopoulos X_WIDTH,
65*b4d691baSGiannis Adamopoulos Y_HEIGHT,
66*b4d691baSGiannis Adamopoulos hWnd, NULL, NULL, NULL);
67*b4d691baSGiannis Adamopoulos }
68*b4d691baSGiannis Adamopoulos
CreateBtn(HWND hWnd,LPCWSTR Text,LONG style,int i,int j)69*b4d691baSGiannis Adamopoulos static HWND CreateBtn(HWND hWnd, LPCWSTR Text, LONG style, int i, int j)
70*b4d691baSGiannis Adamopoulos {
71*b4d691baSGiannis Adamopoulos WCHAR buffer[100];
72*b4d691baSGiannis Adamopoulos SIZE s;
73*b4d691baSGiannis Adamopoulos
74*b4d691baSGiannis Adamopoulos HWND ret = CreateWnd(hWnd, L"Button", Text, style, i, j);
75*b4d691baSGiannis Adamopoulos if (GetWindowLongW(ret, GWL_STYLE) != (style | WS_CHILD | WS_VISIBLE))
76*b4d691baSGiannis Adamopoulos {
77*b4d691baSGiannis Adamopoulos swprintf(buffer, L"expected 0x%x got 0x%x", (style | WS_CHILD | WS_VISIBLE), GetWindowLongW(ret, GWL_STYLE));
78*b4d691baSGiannis Adamopoulos MessageBox(0, buffer, L"error", MB_OK);
79*b4d691baSGiannis Adamopoulos }
80*b4d691baSGiannis Adamopoulos
81*b4d691baSGiannis Adamopoulos if (SendMessageW(ret, BCM_GETIDEALSIZE, 0, (LPARAM)&s))
82*b4d691baSGiannis Adamopoulos {
83*b4d691baSGiannis Adamopoulos swprintf(buffer, L"%s (%d, %d)", Text, s.cx, s.cy);
84*b4d691baSGiannis Adamopoulos SendMessageW(ret, WM_SETTEXT, 0, (LPARAM)buffer);
85*b4d691baSGiannis Adamopoulos }
86*b4d691baSGiannis Adamopoulos return ret;
87*b4d691baSGiannis Adamopoulos }
88*b4d691baSGiannis Adamopoulos
CreateButtonSet(HWND hwndParent,HWND * ahwnd,int i,int j,DWORD style)89*b4d691baSGiannis Adamopoulos static void CreateButtonSet(HWND hwndParent, HWND *ahwnd, int i, int j, DWORD style)
90*b4d691baSGiannis Adamopoulos {
91*b4d691baSGiannis Adamopoulos ahwnd[0] = CreateBtn(hwndParent, L"TestButton", style, i, j + 0);
92*b4d691baSGiannis Adamopoulos ahwnd[1] = CreateBtn(hwndParent, L"TestButton1", style, i, j + 1);
93*b4d691baSGiannis Adamopoulos ahwnd[2] = CreateBtn(hwndParent, L"TestButton2", style, i, j + 2);
94*b4d691baSGiannis Adamopoulos ahwnd[3] = CreateBtn(hwndParent, L"TestButton3", style | BS_BITMAP, i, j + 3);
95*b4d691baSGiannis Adamopoulos ahwnd[4] = CreateBtn(hwndParent, L"TestButton4", style | BS_ICON, i, j + 4);
96*b4d691baSGiannis Adamopoulos
97*b4d691baSGiannis Adamopoulos SendMessageW(ahwnd[1], BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hbmp);
98*b4d691baSGiannis Adamopoulos SendMessageW(ahwnd[2], BM_SETIMAGE, IMAGE_ICON, (LPARAM)hico);
99*b4d691baSGiannis Adamopoulos
100*b4d691baSGiannis Adamopoulos SendMessageW(ahwnd[3], BM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hbmp);
101*b4d691baSGiannis Adamopoulos SendMessageW(ahwnd[4], BM_SETIMAGE, IMAGE_ICON, (LPARAM)hico);
102*b4d691baSGiannis Adamopoulos }
103*b4d691baSGiannis Adamopoulos
wWinMain(_In_ HINSTANCE hInstance,_In_opt_ HINSTANCE hPrevInstance,_In_ LPWSTR lpCmdLine,_In_ int nCmdShow)104*b4d691baSGiannis Adamopoulos int WINAPI wWinMain(_In_ HINSTANCE hInstance,
105*b4d691baSGiannis Adamopoulos _In_opt_ HINSTANCE hPrevInstance,
106*b4d691baSGiannis Adamopoulos _In_ LPWSTR lpCmdLine,
107*b4d691baSGiannis Adamopoulos _In_ int nCmdShow)
108*b4d691baSGiannis Adamopoulos {
109*b4d691baSGiannis Adamopoulos HWND hwnd[200];
110*b4d691baSGiannis Adamopoulos HANDLE hActCtx;
111*b4d691baSGiannis Adamopoulos ULONG_PTR cookie;
112*b4d691baSGiannis Adamopoulos BOOL bActivated;
113*b4d691baSGiannis Adamopoulos
114*b4d691baSGiannis Adamopoulos ACTCTXW actctx = { sizeof(actctx) };
115*b4d691baSGiannis Adamopoulos actctx.hModule = hInstance;
116*b4d691baSGiannis Adamopoulos actctx.dwFlags = ACTCTX_FLAG_RESOURCE_NAME_VALID| ACTCTX_FLAG_HMODULE_VALID;
117*b4d691baSGiannis Adamopoulos actctx.lpResourceName = MAKEINTRESOURCEW(500);
118*b4d691baSGiannis Adamopoulos hActCtx = CreateActCtxW(&actctx);
119*b4d691baSGiannis Adamopoulos
120*b4d691baSGiannis Adamopoulos hico = LoadIconW(hInstance, MAKEINTRESOURCEW(IDI_WIN32PROJECT1));
121*b4d691baSGiannis Adamopoulos hbmp = LoadBitmapW(hInstance, MAKEINTRESOURCEW(IDB_BITMAP1));
122*b4d691baSGiannis Adamopoulos
123*b4d691baSGiannis Adamopoulos scPos.x = 0;
124*b4d691baSGiannis Adamopoulos scPos.y = 0;
125*b4d691baSGiannis Adamopoulos
126*b4d691baSGiannis Adamopoulos hbrNULL = (HBRUSH)GetStockObject (NULL_BRUSH);
127*b4d691baSGiannis Adamopoulos hbrRed = CreateSolidBrush(0x00000FF);
128*b4d691baSGiannis Adamopoulos hbrGreen = CreateSolidBrush(0x0000FF00);
129*b4d691baSGiannis Adamopoulos hbrBlue = CreateSolidBrush(0x00FF0000);
130*b4d691baSGiannis Adamopoulos hbrCyan = CreateSolidBrush(0x00FFFF00);
131*b4d691baSGiannis Adamopoulos hbrYellow = CreateSolidBrush(0x0000FFFF);
132*b4d691baSGiannis Adamopoulos
133*b4d691baSGiannis Adamopoulos hbrCtlColorStatic = hbrRed;
134*b4d691baSGiannis Adamopoulos hbrCtlColorBtn = hbrCyan;
135*b4d691baSGiannis Adamopoulos hbrPrintClientClear = hbrYellow;
136*b4d691baSGiannis Adamopoulos hbrErase = hbrGreen;
137*b4d691baSGiannis Adamopoulos
138*b4d691baSGiannis Adamopoulos bSkipErase = FALSE;
139*b4d691baSGiannis Adamopoulos bSkipPaint = FALSE;
140*b4d691baSGiannis Adamopoulos
141*b4d691baSGiannis Adamopoulos RegisterMyClass(hInstance);
142*b4d691baSGiannis Adamopoulos
143*b4d691baSGiannis Adamopoulos HWND hWnd = CreateWindowExW(WS_EX_CLIENTEDGE, L"ButtonTests", L"Button tests", WS_OVERLAPPEDWINDOW| WS_HSCROLL| WS_VSCROLL,
144*b4d691baSGiannis Adamopoulos CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
145*b4d691baSGiannis Adamopoulos
146*b4d691baSGiannis Adamopoulos CreateWnd(hWnd, L"Static", L"no images", 0, -1, 0);
147*b4d691baSGiannis Adamopoulos CreateWnd(hWnd, L"Static", L"with BM_SETIMAGE", 0, -1, 1);
148*b4d691baSGiannis Adamopoulos CreateWnd(hWnd, L"Static", L"with BM_SETIMAGE", 0, -1, 2);
149*b4d691baSGiannis Adamopoulos CreateWnd(hWnd, L"Static", L"with BM_SETIMAGE and BS_BITMAP", 0, -1, 3);
150*b4d691baSGiannis Adamopoulos CreateWnd(hWnd, L"Static", L"with BM_SETIMAGE and BS_ICON", 0, -1, 4);
151*b4d691baSGiannis Adamopoulos
152*b4d691baSGiannis Adamopoulos CreateWnd(hWnd, L"Static", L"Button V5", 0, 0, -1);
153*b4d691baSGiannis Adamopoulos CreateButtonSet(hWnd, &hwnd[0], 0, 0, BS_PUSHBUTTON);
154*b4d691baSGiannis Adamopoulos CreateButtonSet(hWnd, &hwnd[5], 1, 0, BS_DEFPUSHBUTTON);
155*b4d691baSGiannis Adamopoulos CreateButtonSet(hWnd, &hwnd[10], 0, 5, BS_PUSHBUTTON|WS_DISABLED);
156*b4d691baSGiannis Adamopoulos CreateButtonSet(hWnd, &hwnd[15], 1, 5, BS_GROUPBOX);
157*b4d691baSGiannis Adamopoulos CreateButtonSet(hWnd, &hwnd[20], 0, 10, BS_CHECKBOX);
158*b4d691baSGiannis Adamopoulos CreateButtonSet(hWnd, &hwnd[25], 1, 10, BS_RADIOBUTTON);
159*b4d691baSGiannis Adamopoulos
160*b4d691baSGiannis Adamopoulos bActivated = ActivateActCtx(hActCtx, &cookie);
161*b4d691baSGiannis Adamopoulos LoadLibraryW(L"comctl32.dll");
162*b4d691baSGiannis Adamopoulos
163*b4d691baSGiannis Adamopoulos himl = ImageList_LoadImageW(hInstance, MAKEINTRESOURCEW(IDB_BITMAP2), 16, 0, CLR_DEFAULT, IMAGE_BITMAP, LR_CREATEDIBSECTION);
164*b4d691baSGiannis Adamopoulos BUTTON_IMAGELIST btniml = {himl, {1,1,1,1}, BUTTON_IMAGELIST_ALIGN_LEFT};
165*b4d691baSGiannis Adamopoulos
166*b4d691baSGiannis Adamopoulos CreateWnd(hWnd, L"Static", L"Button V6 without themes", 0, 2, -1);
167*b4d691baSGiannis Adamopoulos CreateButtonSet(hWnd, &hwnd[30], 2, 0, BS_PUSHBUTTON);
168*b4d691baSGiannis Adamopoulos CreateButtonSet(hWnd, &hwnd[35], 3, 0, BS_DEFPUSHBUTTON);
169*b4d691baSGiannis Adamopoulos CreateButtonSet(hWnd, &hwnd[40], 2, 5, BS_PUSHBUTTON|WS_DISABLED);
170*b4d691baSGiannis Adamopoulos CreateButtonSet(hWnd, &hwnd[55], 3, 5, BS_GROUPBOX);
171*b4d691baSGiannis Adamopoulos CreateButtonSet(hWnd, &hwnd[50], 2, 10, BS_CHECKBOX);
172*b4d691baSGiannis Adamopoulos CreateButtonSet(hWnd, &hwnd[55], 3, 10, BS_RADIOBUTTON);
173*b4d691baSGiannis Adamopoulos
174*b4d691baSGiannis Adamopoulos CreateWnd(hWnd, L"Static", L"Button V6 with imagelist and no themes", 0, 4, -1);
175*b4d691baSGiannis Adamopoulos CreateButtonSet(hWnd, &hwnd[60], 4, 0, BS_PUSHBUTTON);
176*b4d691baSGiannis Adamopoulos CreateButtonSet(hWnd, &hwnd[65], 5, 0, BS_DEFPUSHBUTTON);
177*b4d691baSGiannis Adamopoulos CreateButtonSet(hWnd, &hwnd[70], 4, 5, BS_PUSHBUTTON|WS_DISABLED);
178*b4d691baSGiannis Adamopoulos CreateButtonSet(hWnd, &hwnd[75], 5, 5, BS_GROUPBOX);
179*b4d691baSGiannis Adamopoulos CreateButtonSet(hWnd, &hwnd[80], 4, 10, BS_CHECKBOX);
180*b4d691baSGiannis Adamopoulos CreateButtonSet(hWnd, &hwnd[85], 5, 10, BS_RADIOBUTTON);
181*b4d691baSGiannis Adamopoulos
182*b4d691baSGiannis Adamopoulos for (int i = 30; i < 90; i++)
183*b4d691baSGiannis Adamopoulos SetWindowTheme(hwnd[i], L"", L"");
184*b4d691baSGiannis Adamopoulos
185*b4d691baSGiannis Adamopoulos for (int i = 60; i< 90; i++)
186*b4d691baSGiannis Adamopoulos SendMessageW(hwnd[i], BCM_SETIMAGELIST, 0, (LPARAM)&btniml);
187*b4d691baSGiannis Adamopoulos
188*b4d691baSGiannis Adamopoulos CreateWnd(hWnd, L"Static", L"Button V6 with themes and imagelist", 0, 6, -1);
189*b4d691baSGiannis Adamopoulos CreateButtonSet(hWnd, &hwnd[120], 6, 0, BS_PUSHBUTTON);
190*b4d691baSGiannis Adamopoulos CreateButtonSet(hWnd, &hwnd[125], 7, 0, BS_DEFPUSHBUTTON);
191*b4d691baSGiannis Adamopoulos CreateButtonSet(hWnd, &hwnd[130], 6, 5, BS_PUSHBUTTON|WS_DISABLED);
192*b4d691baSGiannis Adamopoulos CreateButtonSet(hWnd, &hwnd[135], 7, 5, BS_GROUPBOX);
193*b4d691baSGiannis Adamopoulos CreateButtonSet(hWnd, &hwnd[140], 6, 10, BS_CHECKBOX);
194*b4d691baSGiannis Adamopoulos CreateButtonSet(hWnd, &hwnd[145], 7, 10, BS_RADIOBUTTON);
195*b4d691baSGiannis Adamopoulos
196*b4d691baSGiannis Adamopoulos CreateWnd(hWnd, L"Static", L"Button V6 with themes", 0, 8, -1);
197*b4d691baSGiannis Adamopoulos CreateButtonSet(hWnd, &hwnd[90], 8, 0, BS_PUSHBUTTON);
198*b4d691baSGiannis Adamopoulos CreateButtonSet(hWnd, &hwnd[95], 9, 0, BS_DEFPUSHBUTTON);
199*b4d691baSGiannis Adamopoulos CreateButtonSet(hWnd, &hwnd[100], 8, 5, BS_PUSHBUTTON|WS_DISABLED);
200*b4d691baSGiannis Adamopoulos CreateButtonSet(hWnd, &hwnd[105], 9, 5, BS_GROUPBOX);
201*b4d691baSGiannis Adamopoulos CreateButtonSet(hWnd, &hwnd[110], 8, 10, BS_CHECKBOX);
202*b4d691baSGiannis Adamopoulos CreateButtonSet(hWnd, &hwnd[115], 9, 10, BS_RADIOBUTTON);
203*b4d691baSGiannis Adamopoulos
204*b4d691baSGiannis Adamopoulos for (int i = 120; i< 150; i++)
205*b4d691baSGiannis Adamopoulos SendMessageW(hwnd[i], BCM_SETIMAGELIST, 0, (LPARAM)&btniml);
206*b4d691baSGiannis Adamopoulos
207*b4d691baSGiannis Adamopoulos if (bActivated) DeactivateActCtx(0, cookie);
208*b4d691baSGiannis Adamopoulos
209*b4d691baSGiannis Adamopoulos SCROLLINFO vsi = {sizeof(SCROLLINFO), SIF_ALL, 0, 2 * TOP_MARGIN + 10 * (Y_GAP + Y_HEIGHT), Y_HEIGHT, 0, 0};
210*b4d691baSGiannis Adamopoulos SCROLLINFO hsi = {sizeof(SCROLLINFO), SIF_ALL, 0, 2 * LEFT_MARGIN + 13 * (X_GAP + X_WIDTH), X_WIDTH, 0, 0};
211*b4d691baSGiannis Adamopoulos
212*b4d691baSGiannis Adamopoulos SetScrollInfo(hWnd, SB_HORZ, &hsi, FALSE);
213*b4d691baSGiannis Adamopoulos SetScrollInfo(hWnd, SB_VERT, &vsi, FALSE);
214*b4d691baSGiannis Adamopoulos
215*b4d691baSGiannis Adamopoulos ShowScrollBar(hWnd, SB_HORZ, TRUE);
216*b4d691baSGiannis Adamopoulos ShowScrollBar(hWnd, SB_VERT, TRUE);
217*b4d691baSGiannis Adamopoulos
218*b4d691baSGiannis Adamopoulos ShowWindow(hWnd, nCmdShow);
219*b4d691baSGiannis Adamopoulos UpdateWindow(hWnd);
220*b4d691baSGiannis Adamopoulos
221*b4d691baSGiannis Adamopoulos MSG msg;
222*b4d691baSGiannis Adamopoulos while (GetMessage(&msg, NULL, 0, 0))
223*b4d691baSGiannis Adamopoulos {
224*b4d691baSGiannis Adamopoulos TranslateMessage(&msg);
225*b4d691baSGiannis Adamopoulos DispatchMessage(&msg);
226*b4d691baSGiannis Adamopoulos }
227*b4d691baSGiannis Adamopoulos
228*b4d691baSGiannis Adamopoulos return (int) msg.wParam;
229*b4d691baSGiannis Adamopoulos }
230*b4d691baSGiannis Adamopoulos
231*b4d691baSGiannis Adamopoulos static VOID
OnScroll(HWND hwnd,INT nBar,WORD sbCode)232*b4d691baSGiannis Adamopoulos OnScroll(HWND hwnd, INT nBar, WORD sbCode)
233*b4d691baSGiannis Adamopoulos {
234*b4d691baSGiannis Adamopoulos RECT rect;
235*b4d691baSGiannis Adamopoulos
236*b4d691baSGiannis Adamopoulos SCROLLINFO sInfo;
237*b4d691baSGiannis Adamopoulos INT oldPos, Maximum;
238*b4d691baSGiannis Adamopoulos PLONG pOriginXY;
239*b4d691baSGiannis Adamopoulos
240*b4d691baSGiannis Adamopoulos //ASSERT(nBar == SB_HORZ || nBar == SB_VERT);
241*b4d691baSGiannis Adamopoulos
242*b4d691baSGiannis Adamopoulos GetClientRect(hwnd, &rect);
243*b4d691baSGiannis Adamopoulos
244*b4d691baSGiannis Adamopoulos if (nBar == SB_HORZ)
245*b4d691baSGiannis Adamopoulos {
246*b4d691baSGiannis Adamopoulos Maximum =1000;//pData->cxMin - (rect.right-rect.left) /* pData->cxOld */;
247*b4d691baSGiannis Adamopoulos pOriginXY = &scPos.x;
248*b4d691baSGiannis Adamopoulos }
249*b4d691baSGiannis Adamopoulos else // if (nBar == SB_VERT)
250*b4d691baSGiannis Adamopoulos {
251*b4d691baSGiannis Adamopoulos Maximum = 1000;//pData->cyMin - (rect.bottom-rect.top) /* pData->cyOld */;
252*b4d691baSGiannis Adamopoulos pOriginXY = &scPos.y;
253*b4d691baSGiannis Adamopoulos }
254*b4d691baSGiannis Adamopoulos
255*b4d691baSGiannis Adamopoulos /* Set scrollbar sizes */
256*b4d691baSGiannis Adamopoulos sInfo.cbSize = sizeof(sInfo);
257*b4d691baSGiannis Adamopoulos sInfo.fMask = SIF_RANGE | SIF_POS | SIF_PAGE | SIF_TRACKPOS;
258*b4d691baSGiannis Adamopoulos
259*b4d691baSGiannis Adamopoulos if (!GetScrollInfo(hwnd, nBar, &sInfo))
260*b4d691baSGiannis Adamopoulos return;
261*b4d691baSGiannis Adamopoulos
262*b4d691baSGiannis Adamopoulos oldPos = sInfo.nPos;
263*b4d691baSGiannis Adamopoulos
264*b4d691baSGiannis Adamopoulos switch (sbCode)
265*b4d691baSGiannis Adamopoulos {
266*b4d691baSGiannis Adamopoulos case SB_LINEUP: // SB_LINELEFT:
267*b4d691baSGiannis Adamopoulos sInfo.nPos--;
268*b4d691baSGiannis Adamopoulos break;
269*b4d691baSGiannis Adamopoulos
270*b4d691baSGiannis Adamopoulos case SB_LINEDOWN: // SB_LINERIGHT:
271*b4d691baSGiannis Adamopoulos sInfo.nPos++;
272*b4d691baSGiannis Adamopoulos break;
273*b4d691baSGiannis Adamopoulos
274*b4d691baSGiannis Adamopoulos case SB_PAGEUP: // SB_PAGELEFT:
275*b4d691baSGiannis Adamopoulos sInfo.nPos -= sInfo.nPage;
276*b4d691baSGiannis Adamopoulos break;
277*b4d691baSGiannis Adamopoulos
278*b4d691baSGiannis Adamopoulos case SB_PAGEDOWN: // SB_PAGERIGHT:
279*b4d691baSGiannis Adamopoulos sInfo.nPos += sInfo.nPage;
280*b4d691baSGiannis Adamopoulos break;
281*b4d691baSGiannis Adamopoulos
282*b4d691baSGiannis Adamopoulos case SB_THUMBTRACK:
283*b4d691baSGiannis Adamopoulos sInfo.nPos = sInfo.nTrackPos;
284*b4d691baSGiannis Adamopoulos break;
285*b4d691baSGiannis Adamopoulos
286*b4d691baSGiannis Adamopoulos case SB_THUMBPOSITION:
287*b4d691baSGiannis Adamopoulos sInfo.nPos = sInfo.nTrackPos;
288*b4d691baSGiannis Adamopoulos break;
289*b4d691baSGiannis Adamopoulos
290*b4d691baSGiannis Adamopoulos case SB_TOP: // SB_LEFT:
291*b4d691baSGiannis Adamopoulos sInfo.nPos = sInfo.nMin;
292*b4d691baSGiannis Adamopoulos break;
293*b4d691baSGiannis Adamopoulos
294*b4d691baSGiannis Adamopoulos case SB_BOTTOM: // SB_RIGHT:
295*b4d691baSGiannis Adamopoulos sInfo.nPos = sInfo.nMax;
296*b4d691baSGiannis Adamopoulos break;
297*b4d691baSGiannis Adamopoulos
298*b4d691baSGiannis Adamopoulos default:
299*b4d691baSGiannis Adamopoulos break;
300*b4d691baSGiannis Adamopoulos }
301*b4d691baSGiannis Adamopoulos
302*b4d691baSGiannis Adamopoulos sInfo.nPos = min(max(sInfo.nPos, 0), Maximum);
303*b4d691baSGiannis Adamopoulos
304*b4d691baSGiannis Adamopoulos if (oldPos != sInfo.nPos)
305*b4d691baSGiannis Adamopoulos {
306*b4d691baSGiannis Adamopoulos POINT scOldPos = scPos;
307*b4d691baSGiannis Adamopoulos
308*b4d691baSGiannis Adamopoulos /* We now modify scPos */
309*b4d691baSGiannis Adamopoulos *pOriginXY = sInfo.nPos;
310*b4d691baSGiannis Adamopoulos
311*b4d691baSGiannis Adamopoulos ScrollWindowEx(hwnd,
312*b4d691baSGiannis Adamopoulos (scOldPos.x - scPos.x),
313*b4d691baSGiannis Adamopoulos (scOldPos.y - scPos.y),
314*b4d691baSGiannis Adamopoulos NULL,
315*b4d691baSGiannis Adamopoulos NULL,
316*b4d691baSGiannis Adamopoulos NULL,
317*b4d691baSGiannis Adamopoulos NULL,
318*b4d691baSGiannis Adamopoulos SW_INVALIDATE | SW_ERASE | SW_SCROLLCHILDREN);
319*b4d691baSGiannis Adamopoulos
320*b4d691baSGiannis Adamopoulos sInfo.fMask = SIF_POS;
321*b4d691baSGiannis Adamopoulos SetScrollInfo(hwnd, nBar, &sInfo, TRUE);
322*b4d691baSGiannis Adamopoulos }
323*b4d691baSGiannis Adamopoulos }
324*b4d691baSGiannis Adamopoulos
WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)325*b4d691baSGiannis Adamopoulos LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
326*b4d691baSGiannis Adamopoulos {
327*b4d691baSGiannis Adamopoulos RECT rc = {0,0,5000,5000};
328*b4d691baSGiannis Adamopoulos switch (message)
329*b4d691baSGiannis Adamopoulos {
330*b4d691baSGiannis Adamopoulos case WM_DESTROY:
331*b4d691baSGiannis Adamopoulos PostQuitMessage(0);
332*b4d691baSGiannis Adamopoulos break;
333*b4d691baSGiannis Adamopoulos case WM_CTLCOLORSTATIC:
334*b4d691baSGiannis Adamopoulos return (LRESULT)hbrCtlColorStatic;
335*b4d691baSGiannis Adamopoulos case WM_CTLCOLORBTN:
336*b4d691baSGiannis Adamopoulos return (LRESULT)hbrCtlColorBtn;
337*b4d691baSGiannis Adamopoulos case WM_ERASEBKGND:
338*b4d691baSGiannis Adamopoulos FillRect((HDC)wParam, &rc, hbrErase);
339*b4d691baSGiannis Adamopoulos return TRUE;
340*b4d691baSGiannis Adamopoulos case WM_PRINTCLIENT:
341*b4d691baSGiannis Adamopoulos FillRect((HDC)wParam, &rc, hbrPrintClientClear);
342*b4d691baSGiannis Adamopoulos break;
343*b4d691baSGiannis Adamopoulos case WM_HSCROLL:
344*b4d691baSGiannis Adamopoulos OnScroll(hWnd, SB_HORZ, LOWORD(wParam));
345*b4d691baSGiannis Adamopoulos break;
346*b4d691baSGiannis Adamopoulos case WM_VSCROLL:
347*b4d691baSGiannis Adamopoulos OnScroll(hWnd, SB_VERT, LOWORD(wParam));
348*b4d691baSGiannis Adamopoulos break;
349*b4d691baSGiannis Adamopoulos case WM_DRAWITEM :
350*b4d691baSGiannis Adamopoulos {
351*b4d691baSGiannis Adamopoulos DRAWITEMSTRUCT* di = (DRAWITEMSTRUCT*)lParam;
352*b4d691baSGiannis Adamopoulos INT oldBkMode;
353*b4d691baSGiannis Adamopoulos INT state = (di->itemState == ODS_SELECTED) ? DFCS_BUTTONPUSH|DFCS_PUSHED : DFCS_BUTTONPUSH;
354*b4d691baSGiannis Adamopoulos DrawFrameControl( di->hDC, &di->rcItem, DFC_BUTTON, state );
355*b4d691baSGiannis Adamopoulos oldBkMode = SetBkMode(di->hDC, TRANSPARENT);
356*b4d691baSGiannis Adamopoulos DrawTextW(di->hDC, L"Ownder drawn text", -1, &di->rcItem, DT_VCENTER | DT_CENTER);
357*b4d691baSGiannis Adamopoulos SetBkMode(di->hDC, oldBkMode);
358*b4d691baSGiannis Adamopoulos break;
359*b4d691baSGiannis Adamopoulos }
360*b4d691baSGiannis Adamopoulos case WM_NOTIFY:
361*b4d691baSGiannis Adamopoulos {
362*b4d691baSGiannis Adamopoulos NMHDR* phdr = (NMHDR*)lParam;
363*b4d691baSGiannis Adamopoulos if (phdr->code == NM_CUSTOMDRAW)
364*b4d691baSGiannis Adamopoulos {
365*b4d691baSGiannis Adamopoulos LPNMCUSTOMDRAW lpNMCustomDraw = (LPNMCUSTOMDRAW) lParam;
366*b4d691baSGiannis Adamopoulos if (lpNMCustomDraw->dwDrawStage == CDDS_PREERASE && bSkipErase)
367*b4d691baSGiannis Adamopoulos return CDRF_SKIPDEFAULT;
368*b4d691baSGiannis Adamopoulos else if (lpNMCustomDraw->dwDrawStage == CDDS_PREPAINT && bSkipPaint)
369*b4d691baSGiannis Adamopoulos return CDRF_SKIPDEFAULT;
370*b4d691baSGiannis Adamopoulos return CDRF_DODEFAULT;
371*b4d691baSGiannis Adamopoulos }
372*b4d691baSGiannis Adamopoulos }
373*b4d691baSGiannis Adamopoulos case WM_COMMAND:
374*b4d691baSGiannis Adamopoulos {
375*b4d691baSGiannis Adamopoulos UINT id = LOWORD(wParam);
376*b4d691baSGiannis Adamopoulos switch(id)
377*b4d691baSGiannis Adamopoulos {
378*b4d691baSGiannis Adamopoulos case IDM_NULL_WIN: hbrErase = hbrNULL; break;
379*b4d691baSGiannis Adamopoulos case IDM_RED_WIN: hbrErase = hbrRed; break;
380*b4d691baSGiannis Adamopoulos case IDM_GREEN_WIN: hbrErase = hbrGreen; break;
381*b4d691baSGiannis Adamopoulos case IDM_BLUE_WIN: hbrErase = hbrBlue; break;
382*b4d691baSGiannis Adamopoulos case IDM_YELLOW_WIN: hbrErase = hbrYellow; break;
383*b4d691baSGiannis Adamopoulos case IDM_CYAN_WIN: hbrErase = hbrCyan; break;
384*b4d691baSGiannis Adamopoulos
385*b4d691baSGiannis Adamopoulos case IDM_NULL_STATIC: hbrCtlColorStatic = hbrNULL; break;
386*b4d691baSGiannis Adamopoulos case IDM_RED_STATIC: hbrCtlColorStatic = hbrRed; break;
387*b4d691baSGiannis Adamopoulos case IDM_GREEN_STATIC: hbrCtlColorStatic = hbrGreen; break;
388*b4d691baSGiannis Adamopoulos case IDM_BLUE_STATIC: hbrCtlColorStatic = hbrBlue; break;
389*b4d691baSGiannis Adamopoulos case IDM_YELLOW_STATIC: hbrCtlColorStatic = hbrYellow; break;
390*b4d691baSGiannis Adamopoulos case IDM_CYAN_STATIC: hbrCtlColorStatic = hbrCyan; break;
391*b4d691baSGiannis Adamopoulos
392*b4d691baSGiannis Adamopoulos case IDM_NULL_BTN: hbrCtlColorBtn = hbrNULL; break;
393*b4d691baSGiannis Adamopoulos case IDM_RED_BTN: hbrCtlColorBtn = hbrRed; break;
394*b4d691baSGiannis Adamopoulos case IDM_GREEN_BTN: hbrCtlColorBtn = hbrGreen; break;
395*b4d691baSGiannis Adamopoulos case IDM_BLUE_BTN: hbrCtlColorBtn = hbrBlue; break;
396*b4d691baSGiannis Adamopoulos case IDM_YELLOW_BTN: hbrCtlColorBtn = hbrYellow; break;
397*b4d691baSGiannis Adamopoulos case IDM_CYAN_BTN: hbrCtlColorBtn = hbrCyan; break;
398*b4d691baSGiannis Adamopoulos
399*b4d691baSGiannis Adamopoulos case IDM_NULL_PRINTCLNT: hbrPrintClientClear = hbrNULL; break;
400*b4d691baSGiannis Adamopoulos case IDM_RED_PRINTCLNT: hbrPrintClientClear = hbrRed; break;
401*b4d691baSGiannis Adamopoulos case IDM_GREEN_PRINTCLNT: hbrPrintClientClear = hbrGreen; break;
402*b4d691baSGiannis Adamopoulos case IDM_BLUE_PRINTCLNT: hbrPrintClientClear = hbrBlue; break;
403*b4d691baSGiannis Adamopoulos case IDM_YELLOW_PRINTCLNT: hbrPrintClientClear = hbrYellow; break;
404*b4d691baSGiannis Adamopoulos case IDM_CYAN_PRINTCLNT: hbrPrintClientClear = hbrCyan; break;
405*b4d691baSGiannis Adamopoulos
406*b4d691baSGiannis Adamopoulos case IDM_SKIP_ERASE: bSkipErase = !bSkipErase; break;
407*b4d691baSGiannis Adamopoulos case IDM_SKIP_PAINT: bSkipPaint = !bSkipPaint; break;
408*b4d691baSGiannis Adamopoulos default:
409*b4d691baSGiannis Adamopoulos return 0;
410*b4d691baSGiannis Adamopoulos }
411*b4d691baSGiannis Adamopoulos
412*b4d691baSGiannis Adamopoulos InvalidateRect(hWnd, NULL, TRUE);
413*b4d691baSGiannis Adamopoulos break;
414*b4d691baSGiannis Adamopoulos }
415*b4d691baSGiannis Adamopoulos default:
416*b4d691baSGiannis Adamopoulos return DefWindowProc(hWnd, message, wParam, lParam);
417*b4d691baSGiannis Adamopoulos }
418*b4d691baSGiannis Adamopoulos return 0;
419*b4d691baSGiannis Adamopoulos }
420