PageRenderTime 20ms CodeModel.GetById 9ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 1ms

/Visual Studio 2008/CppWindowsCommonControls/ReadMe.txt

#
Plain Text | 403 lines | 274 code | 129 blank | 0 comment | 0 complexity | 6d3b25d218388ad873924f27403dfa99 MD5 | raw file
  1========================================================================
  2    WIN32 APPLICATION : CppWindowsCommonControls Project Overview
  3========================================================================
  4
  5/////////////////////////////////////////////////////////////////////////////
  6Use:
  7
  8CppWindowsCommonControls contains simple examples of how to create common  
  9controls defined in comctl32.dll. The controls include Animation, ComboBoxEx, 
 10Updown, Header, MonthCal, DateTimePick, ListView, TreeView, Tab, Tooltip, IP 
 11Address, Statusbar, Progress Bar, Toolbar, Trackbar, and SysLink.
 12
 13
 14/////////////////////////////////////////////////////////////////////////////
 15Creation:
 16
 17First, build up the dialogs for use in this example according to the 
 18CppWindowsDialog example. Then link the application to comctl32.lib in the 
 19project's property page / Linker / Input / Additional Dependencies. Because 
 20the sample needs to work on Windows XP and Windows 2003 apart from Windows 
 21Vista, change the default target version to _WIN32_WINNT_WINXP in the 
 22targetver.h.
 23
 24	#ifndef WINVER
 25	#define WINVER _WIN32_WINNT_WINXP		// Originally 0x0600
 26	#endif
 27
 28	#ifndef _WIN32_WINNT
 29	#define _WIN32_WINNT _WIN32_WINNT_WINXP	// Originally 0x0600
 30	#endif 
 31
 32A. Animation Control
 33
 34Step1. Add the AVI resource IDR_UPLOAD_AVI according to the KB article:
 35
 36How to create a resource .dll file that contains an AVI file 
 37http://support.microsoft.com/kb/178199
 38
 39Step2. In OnInitAnimationDialog, load and register animation control class.
 40
 41	INITCOMMONCONTROLSEX iccx;
 42	iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
 43	iccx.dwICC = ICC_ANIMATE_CLASS;
 44	if (!InitCommonControlsEx(&iccx))
 45		return FALSE;
 46
 47Step3. Create the animation control.
 48
 49	RECT rc = { 20, 20, 280, 60 };
 50	HWND hAnimate = CreateWindowEx(0, ANIMATE_CLASS, 0, 
 51		ACS_TIMER | ACS_AUTOPLAY | ACS_TRANSPARENT | WS_CHILD | WS_VISIBLE, 
 52		rc.left, rc.top, rc.right, rc.bottom, 
 53		hWnd, (HMENU)IDC_ANIMATION, hInst, 0);
 54
 55Step4. Open and play the AVI clip in the animation control.
 56
 57	SendMessage(hAnimate, ACM_OPEN, (WPARAM)0, 
 58		(LPARAM)MAKEINTRESOURCE(IDR_UPLOAD_AVI));
 59	SendMessage(hAnimate, ACM_PLAY, (WPARAM)-1, 
 60		MAKELONG(/*from frame*/0, /*to frame*/-1));
 61
 62B. ComboBoxEx Control
 63
 64Step1. In OnInitComboBoxExDialog, load and register ComboBoxEx control class.
 65
 66	INITCOMMONCONTROLSEX iccx;
 67	iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
 68	iccx.dwICC = ICC_USEREX_CLASSES;
 69	if (!InitCommonControlsEx(&iccx))
 70		return FALSE;
 71
 72Step2. Create the ComboBoxEx control.
 73
 74	RECT rc = { 20, 20, 280, 100 };
 75	HWND hComboEx = CreateWindowEx(0, WC_COMBOBOXEX, 0, 
 76		CBS_DROPDOWN | WS_CHILD | WS_VISIBLE, 
 77		rc.left, rc.top, rc.right, rc.bottom, 
 78		hWnd, (HMENU)IDC_COMBOBOXEX, hInst, 0);
 79
 80Step3. Create an image list and associate the image list with the ComboBoxEx 
 81control. (ImageList_Create, CBEM_SETIMAGELIST)
 82
 83Step4. Add some items with image to the ComboBoxEx common control. 
 84(COMBOBOXEXITEM, CBEM_INSERTITEM)
 85
 86Step5. Destroy the image list on close. (ImageList_Destroy)
 87
 88C. Up-Down Control
 89
 90Step1. In OnInitUpdownDialog, load and register Updown control class.
 91
 92	INITCOMMONCONTROLSEX iccx;
 93	iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
 94	iccx.dwICC = ICC_UPDOWN_CLASS;
 95	if (!InitCommonControlsEx(&iccx))
 96		return FALSE;
 97
 98Step2. Create an Updown control and an Edit control. (CreateWindowEx)
 99
100Step3. Attach the Updown control to its 'buddy' edit control. (UDM_SETBUDDY)
101
102D. Header Control
103
104Step1. In OnInitHeaderDialog, load and register Header control class.
105
106	INITCOMMONCONTROLSEX iccx;
107	iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
108	iccx.dwICC = ICC_WIN95_CLASSES;
109	if (!InitCommonControlsEx(&iccx))
110		return FALSE;
111
112Step2. Create an Header control. (CreateWindowEx)
113
114Step3. Resize the header control to fit the client rectangle. 
115(HDM_LAYOUT, HDLAYOUT, SetWindowPos)
116
117Step4. Add Header items (HDITEM, HDM_INSERTITEM)
118
119Step5. In OnHeaderSize of the window, resize the Header control accordingly.
120(HDM_LAYOUT, HDLAYOUT, SetWindowPos)
121
122E. Month Calendar Control
123
124Step1. In OnInitMonthCalDialog, load and register MonthCal control class.
125
126	INITCOMMONCONTROLSEX iccx;
127	iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
128	iccx.dwICC = ICC_DATE_CLASSES;
129	if (!InitCommonControlsEx(&iccx))
130		return FALSE;
131
132Step2. Create a Month Calendar control. (CreateWindowEx)
133
134F. Date and Time Picker Control
135
136Step1. In OnInitDateTimePickDialog, load and register DateTimePick control class.
137
138	INITCOMMONCONTROLSEX iccx;
139	iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
140	iccx.dwICC = ICC_DATE_CLASSES;
141	if (!InitCommonControlsEx(&iccx))
142		return FALSE;
143
144Step2. Create a DateTimePick control. (CreateWindowEx)
145
146G. List View Control
147
148Step1. In OnInitListviewDialog, load and register Listview control class.
149
150	INITCOMMONCONTROLSEX iccx;
151	iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
152	iccx.dwICC = ICC_LISTVIEW_CLASSES;
153	if (!InitCommonControlsEx(&iccx))
154		return FALSE;
155
156Step2. Create a Listview control. (CreateWindowEx)
157
158Step3. Set up and attach image lists to list view common control. 
159(ImageList_Create, ImageList_AddIcon, ListView_SetImageList)
160
161Step4. Add items to the the list view common control. 
162(LVITEM, LVM_INSERTITEM)
163
164Step5. In OnListviewSize of the window, resize and re-arrange the Listview 
165control to fit the client rectangle. (MoveWindow, LVM_ARRANGE)
166
167Step6. In OnListviewClose, free up the image list resources. 
168(ImageList_Destroy)
169
170H. Tree View Control
171
172Step1. OnInitTreeviewDialog, load and register Treeview control class.
173
174	INITCOMMONCONTROLSEX iccx;
175	iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
176	iccx.dwICC = ICC_TREEVIEW_CLASSES;
177	if (!InitCommonControlsEx(&iccx))
178		return FALSE;
179
180Step2. Create a Treeview control. (CreateWindowEx)
181
182Step3. Set up and attach image lists to tree view common control. 
183(ImageList_Create, ImageList_AddIcon, TreeView_SetImageList)
184
185Step4. Add items to the tree view common control. 
186(TVITEM, TVINSERTSTRUCT, TVM_INSERTITEM)
187
188Step5. In OnTreeviewSize of the window, resize the Treeview control to fit 
189the client rectangle. (MoveWindow)
190
191Step6. In OnTreeviewClose, free up the image list resources. 
192(TreeView_GetImageList, ImageList_Destroy)
193
194I. Tab Control
195
196Step1. In OnInitTabControlDialog, load and register Tab control class.
197
198	INITCOMMONCONTROLSEX iccx;
199	iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
200	iccx.dwICC = ICC_TAB_CLASSES;
201	if (!InitCommonControlsEx(&iccx))
202		return FALSE;
203
204Step2. Create a Tab control. (CreateWindowEx)
205
206Step3. Add items to the tab common control. (TCITEM, TCM_INSERTITEM)
207
208Step4. In OnTabSize of the window, resize the Tab control to fit the client 
209rectangle. (MoveWindow)
210
211J. Tooltip Control
212
213Step1. In OnInitTooltipDialog, load and register Tooltip control class.
214
215	INITCOMMONCONTROLSEX iccx;
216	iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
217	iccx.dwICC = ICC_WIN95_CLASSES;
218	if (!InitCommonControlsEx(&iccx))
219		return FALSE;
220
221Step2. Create a button control and a tooltip control. Note that a tooltip 
222control should not have the WS_CHILD style, nor should it have an id, 
223otherwise its behavior will be adversely affected, eg. tooltips displayed in 
224wrong place or not at all. (CreateWindowEx)
225
226Step3. Associate the tooltip with the button control. (TOOLINFO, TTM_ADDTOOL)
227
228K. IP Address Control
229
230Step1. In OnInitIPAddressDialog, load and register IPAddress control class.
231
232	INITCOMMONCONTROLSEX iccx;
233	iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
234	iccx.dwICC = ICC_INTERNET_CLASSES;
235	if (!InitCommonControlsEx(&iccx))
236		return FALSE;
237
238Step2. Create the IPAddress control. (CreateWindowEx)
239
240L. Status Bar Control
241
242Step1. In OnInitStatusbarDialog, load and register StatusBar control class.
243
244	INITCOMMONCONTROLSEX iccx;
245	iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
246	iccx.dwICC = ICC_BAR_CLASSES;
247	if (!InitCommonControlsEx(&iccx))
248		return FALSE;
249
250Step2. Create the status bar control. (CreateWindowEx)
251
252Step3. Establish the number of partitions or 'parts' the status bar will 
253have, their actual dimensions will be set in the parent window's WM_SIZE 
254handler. (SB_SETPARTS)
255
256Step4. Put some texts into each part of the status bar and setup each part.
257(SB_SETTEXT)
258
259Step5. In OnStatusbarSize, partition the statusbar to keep the ratio of the 
260sizes of its parts constant. Resize statusbar so it's always same width as 
261parent's client area. (SB_SETPARTS, WM_SIZE)
262
263M. Progress Bar Control
264
265Step1. In OnInitProgressDialog, load and register Progress Bar control class.
266
267	INITCOMMONCONTROLSEX iccx;
268	iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
269	iccx.dwICC = ICC_PROGRESS_CLASS;
270	if (!InitCommonControlsEx(&iccx))
271		return FALSE;
272
273Step2. Create the progress bar control. (CreateWindowEx)
274
275Step3. Set the progress bar position. (PBM_SETPOS)
276
277N. Toolbar Control
278
279Step1. In OnInitToolbarDialog, load and register Toolbar control class.
280
281	INITCOMMONCONTROLSEX iccx;
282	iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
283	iccx.dwICC = ICC_BAR_CLASSES;
284	if (!InitCommonControlsEx(&iccx))
285		return FALSE;
286
287Step2. Create the toolbar control. (CreateWindowEx)
288
289Step3. Setup and add buttons to Toolbar. 
290
291  3.1 Send the TB_BUTTONSTRUCTSIZE to the toolbar control. If an application 
292  uses the CreateWindowEx function to create the toolbar, the application 
293  must send this message to the toolbar before sending the TB_ADDBITMAP or 
294  TB_ADDBUTTONS message. The CreateToolbarEx function automatically sends 
295  TB_BUTTONSTRUCTSIZE, and the size of the TBBUTTON structure is a parameter 
296  of the function.
297  
298  3.2 Add images (TBADDBITMAP, TB_ADDBITMAP)
299  
300  3.3 Add buttons (TBBUTTON, TB_ADDBUTTONS)
301  
302Step4. Tell the toolbar to resize itself, and show it. (TB_AUTOSIZE)
303
304O. Trackbar control
305
306Step1. In OnInitTrackbarDialog, load and register Trackbar control class. 
307
308	INITCOMMONCONTROLSEX iccx;
309	iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
310	iccx.dwICC = ICC_WIN95_CLASSES; // Or ICC_PROGRESS_CLASS
311	if (!InitCommonControlsEx(&iccx))
312		return FALSE;
313
314Step2. Create the Trackbar control. (CreateWindowEx)
315
316Step3. Set Trackbar range. (TBM_SETRANGE)
317
318P. SysLink Control
319
320Step1. In OnInitSysLinkDialog, load and register SysLink control class.
321
322	INITCOMMONCONTROLSEX iccx;
323	iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
324	iccx.dwICC = ICC_LINK_CLASS;
325	if (!InitCommonControlsEx(&iccx))
326		return FALSE; 
327
328Step2. Create the SysLink control. The SysLink control supports the anchor 
329tag(<a>) along with the attributes HREF and ID. (CreateWindowEx) For example,
330
331	HWND hLink = CreateWindowEx(0, WC_LINK, 
332		_T("All-In-One Code Framework\n") \
333		_T("<A HREF=\"http://cfx.codeplex.com\">Home</A> ") \
334		_T("and <A ID=\"idBlog\">Blog</A>"), 
335        WS_VISIBLE | WS_CHILD | WS_TABSTOP, 
336		rc.left, rc.top, rc.right, rc.bottom, 
337        hWnd, (HMENU)IDC_SYSLINK, hInst, NULL);
338
339Step3. In OnSysLinkNotify, capture the notifications associated with SysLink 
340controls: NM_CLICK (syslink) and (for links that can be activated by the 
341Enter key) NM_RETURN. If the link is a HREF, get its url from 
342NMLINK.LITEM.szUrl, otherwise, get the ID from NMLINK.LITEM.szID.
343
344
345/////////////////////////////////////////////////////////////////////////////
346References:
347
348MSDN: About Window Classes 
349http://msdn.microsoft.com/en-us/library/ms633574.aspx
350
351Creating Common Controls
352http://winapi.foosyerdoos.org.uk/info/common_cntrls.php
353
354MSDN: Animation Control
355http://msdn.microsoft.com/en-us/library/bb761881.aspx
356
357MSDN: ComboBoxEx Control Reference
358http://msdn.microsoft.com/en-us/library/bb775740.aspx
359
360MSDN: Up-Down Control
361http://msdn.microsoft.com/en-us/library/bb759880.aspx
362
363MSDN: Header Control
364http://msdn.microsoft.com/en-us/library/bb775239.aspx
365
366MSDN: Month Calendar Control Reference
367http://msdn.microsoft.com/en-us/library/bb760917.aspx
368
369MSDN: Date and Time Picker
370http://msdn.microsoft.com/en-us/library/bb761727.aspx
371
372MSDN: List View
373http://msdn.microsoft.com/en-us/library/bb774737.aspx
374
375MSDN: Tree View
376http://msdn.microsoft.com/en-us/library/bb759988.aspx
377
378MSDN: Tab
379http://msdn.microsoft.com/en-us/library/bb760548.aspx
380
381MSDN: ToolTip
382http://msdn.microsoft.com/en-us/library/bb760246.aspx
383
384MSDN: IP Address Control
385http://msdn.microsoft.com/en-us/library/bb761374.aspx
386
387MSDN: Status Bar
388http://msdn.microsoft.com/en-us/library/bb760726.aspx
389
390MSDN: Progress Bar
391http://msdn.microsoft.com/en-us/library/bb760818.aspx
392
393MSDN: Toolbar
394http://msdn.microsoft.com/en-us/library/bb760435.aspx
395
396MSDN: Trackbar
397http://msdn.microsoft.com/en-us/library/bb760145.aspx
398
399MSDN: SysLink
400http://msdn.microsoft.com/en-us/library/bb760704.aspx
401
402
403/////////////////////////////////////////////////////////////////////////////