2 * ReactOS Standard Dialog Application Template
6 * Copyright (C) 2002 Robert Dickenson <robd@reactos.org>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #define WIN32_LEAN_AND_MEAN
35 #define BUFFER_LEN MAX_PATH
37 extern HINSTANCE hInst
;
43 ////////////////////////////////////////////////////////////////////////////////
45 static TCHAR
* items
[] = {
52 static void InitListCtrl(HWND hDlg
)
57 HWND hListBox
= GetDlgItem(hDlg
, IDC_LIST1
);
59 _tcscpy(szBuffer
, _T("foobar item"));
60 SendMessage(hListBox
, LB_ADDSTRING
, 0, (LPARAM
)szBuffer
);
62 for (i
= 0; i
< sizeof(items
)/sizeof(items
[0]); i
++) {
63 _tcscpy(szBuffer
, items
[i
]);
64 SendMessage(hListBox
, LB_ADDSTRING
, 0, (LPARAM
)szBuffer
);
68 SendMessage(hListBox
, LB_SETCURSEL
, 0, 0);
71 static void OnDrawItem(HWND hWnd
, LPARAM lParam
)
74 TCHAR tchBuffer
[BUFFER_LEN
];
79 LPDRAWITEMSTRUCT lpdis
;
82 lpdis
= (LPDRAWITEMSTRUCT
)lParam
;
83 // If there are no list box items, skip this message.
84 if (lpdis
->itemID
!= -1) {
85 // Draw the bitmap and text for the list box item. Draw a rectangle around the bitmap if it is selected.
86 switch (lpdis
->itemAction
) {
89 // Display the bitmap associated with the item.
90 hbmpPicture
= (HBITMAP
)SendMessage(lpdis
->hwndItem
, LB_GETITEMDATA
, lpdis
->itemID
, (LPARAM
)0);
91 hdcMem
= CreateCompatibleDC(lpdis
->hDC
);
92 hbmpOld
= SelectObject(hdcMem
, hbmpPicture
);
94 lpdis
->rcItem
.left
, lpdis
->rcItem
.top
,
95 lpdis
->rcItem
.right
- lpdis
->rcItem
.left
,
96 lpdis
->rcItem
.bottom
- lpdis
->rcItem
.top
,
97 hdcMem
, 0, 0, SRCCOPY
);
98 // Display the text associated with the item.
99 SendMessage(lpdis
->hwndItem
, LB_GETTEXT
, lpdis
->itemID
, (LPARAM
)tchBuffer
);
100 GetTextMetrics(lpdis
->hDC
, &tm
);
101 y
= (lpdis
->rcItem
.bottom
+ lpdis
->rcItem
.top
- tm
.tmHeight
) / 2;
102 TextOut(lpdis
->hDC
, XBITMAP
+ 6, y
, tchBuffer
, _tcslen(tchBuffer
));
103 SelectObject(hdcMem
, hbmpOld
);
105 // Is the item selected?
106 if (lpdis
->itemState
& ODS_SELECTED
) {
107 // Set RECT coordinates to surround only the bitmap.
108 rcBitmap
.left
= lpdis
->rcItem
.left
;
109 rcBitmap
.top
= lpdis
->rcItem
.top
;
110 rcBitmap
.right
= lpdis
->rcItem
.left
+ XBITMAP
;
111 rcBitmap
.bottom
= lpdis
->rcItem
.top
+ YBITMAP
;
112 // Draw a rectangle around bitmap to indicate the selection.
113 DrawFocusRect(lpdis
->hDC
, &rcBitmap
);
117 // Do not process focus changes. The focus caret (outline rectangle)
118 // indicates the selection. The IDOK button indicates the final selection.
125 void OnSetFont(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
130 GetWindowRect(hWnd
, &rc
);
132 wp
.cx
= rc
.right
- rc
.left
;
133 wp
.cy
= rc
.bottom
- rc
.top
;
134 wp
.flags
= SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOOWNERZORDER
| SWP_NOZORDER
;
135 SendMessage(hWnd
, WM_WINDOWPOSCHANGED
, 0, (LPARAM
)&wp
);
138 void OnMeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct
)
143 hFont
= GetStockObject(SYSTEM_FONT
);
144 GetObject(hFont
, sizeof(LOGFONT
), &lf
);
146 lpMeasureItemStruct
->itemHeight
= -lf
.lfHeight
;
148 lpMeasureItemStruct
->itemHeight
= lf
.lfHeight
;
151 LRESULT CALLBACK
PageWndProc1(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
158 OnSetFont(hDlg
, wParam
, lParam
);
161 OnMeasureItem((LPMEASUREITEMSTRUCT
)lParam
);
164 OnDrawItem(hDlg
, lParam
);
167 switch (LOWORD(wParam
)) {
177 ////////////////////////////////////////////////////////////////////////////////