PageRenderTime 55ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

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