Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

318 lines
10 KiB

  1. //------------------------------------------------------------------------
  2. //
  3. // File: shell\themes\test\ctlperf\samples.cpp
  4. //
  5. // Contents: Sample control initialization routines, taken from ThemeSel by RFernand.
  6. // Add new control initialization data here.
  7. //
  8. // Classes: None
  9. //
  10. //------------------------------------------------------------------------
  11. #include "stdafx.h"
  12. #include "samples.h"
  13. //** shared sample data
  14. static WCHAR *Names[] = {L"One", L"Two", L"Three", L"Four", L"Five", L"Six",
  15. L"Seven", L"Eight", L"Nine", L"Ten", L"Eleven", L"Twelve",
  16. L"Thirteen", L"Fourteen", L"Fifteen", L"Sixteen"};
  17. static WCHAR *Buttons[] = {L"New", L"Open", L"Save", L"Cut", L"Copy", L"Delete",
  18. L"Undo", L"Redo", L"Print", L"Help\0"};
  19. static int ButtonIndexes[] = {STD_FILENEW, STD_FILEOPEN, STD_FILESAVE,
  20. STD_CUT, STD_COPY, STD_DELETE, STD_UNDO, STD_REDOW, STD_PRINT, STD_HELP};
  21. static WCHAR *Columns[] = {L"Name", L"Phone", L"City", L"State"};
  22. static WCHAR *Col1Items[] = {L"Chris", L"Lou", L"Richard", L"Mark", L"Roland", L"Paul",
  23. L"Scott", L"Aaron", L"Greg", L"Ken"};
  24. static WCHAR *Col2Items[] = {L"555-1212", L"567-3434", L"656-4432", L"343-7788", L"706-0225", L"828-3043",
  25. L"706-4433", L"882-8080", L"334-3434", L"333-5430"};
  26. static WCHAR *Col3Items[] = {L"Seattle", L"Redmond", L"Bellevue", L"Seattle", L"Woodinville", L"Kirkland",
  27. L"Kirkland", L"Woodinville", L"Redmond", L"Redmond"};
  28. //-------------------------------------------------------------------------//
  29. // Tab control
  30. //-------------------------------------------------------------------------//
  31. void Pickers_Init(HWND hWndCtl)
  32. {
  33. TCITEM item;
  34. item.mask = TCIF_TEXT;
  35. for (int i=0; i < 4; i++)
  36. {
  37. item.pszText = Names[i];
  38. SendMessage(hWndCtl, TCM_INSERTITEM, i, (LPARAM)&item);
  39. }
  40. }
  41. //-------------------------------------------------------------------------//
  42. // Progress bar
  43. //-------------------------------------------------------------------------//
  44. void Movers_Init(HWND hWndCtl)
  45. {
  46. SendMessage(hWndCtl, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
  47. SendMessage(hWndCtl, PBM_SETPOS, 50, 0);
  48. }
  49. //-------------------------------------------------------------------------//
  50. // Listbox
  51. //-------------------------------------------------------------------------//
  52. void Lists_Init(HWND hWndCtl)
  53. {
  54. SendMessage(hWndCtl, LB_RESETCONTENT, 0, 0);
  55. for (int j=0; j < _countof(Names); j++)
  56. SendMessage(hWndCtl, LB_ADDSTRING, 0, (LPARAM)Names[j]);
  57. SendMessage(hWndCtl, LB_SETCURSEL, 0, 0);
  58. }
  59. //-------------------------------------------------------------------------//
  60. // Combo box
  61. //-------------------------------------------------------------------------//
  62. void Combo_Init(HWND hWndCtl)
  63. {
  64. SendMessage(hWndCtl, CB_RESETCONTENT, 0, 0);
  65. for (int j=0; j < _countof(Names); j++)
  66. SendMessage(hWndCtl, CB_ADDSTRING, 0, (LPARAM)Names[j]);
  67. SendMessage(hWndCtl, CB_SETCURSEL, 0, 0);
  68. }
  69. //-------------------------------------------------------------------------//
  70. // ComboBoxEx
  71. //-------------------------------------------------------------------------//
  72. void ComboEx_Init(HWND hWndCtl)
  73. {
  74. COMBOBOXEXITEM exitem;
  75. exitem.mask = CBEIF_TEXT ;
  76. SendMessage(hWndCtl, CB_RESETCONTENT, 0, 0);
  77. for (int j=0; j < _countof(Names); j++)
  78. {
  79. exitem.iItem = j;
  80. exitem.pszText = Names[j];
  81. SendMessage(hWndCtl, CBEM_INSERTITEM, 0, (LPARAM)&exitem);
  82. }
  83. SendMessage(hWndCtl, CB_SETCURSEL, 0, 0);
  84. }
  85. //-------------------------------------------------------------------------//
  86. // ListView
  87. //-------------------------------------------------------------------------//
  88. void ListView_Init(HWND hWndCtl)
  89. {
  90. //---- initialize the colums ----
  91. LVCOLUMN lvc;
  92. memset(&lvc, 0, sizeof(lvc));
  93. lvc.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_FMT | LVCF_WIDTH;
  94. lvc.fmt = LVCFMT_LEFT;
  95. lvc.cx = 100;
  96. // Add the columns.
  97. for (int c=0; c < _countof(Columns); c++)
  98. {
  99. lvc.iSubItem = c;
  100. lvc.pszText = Columns[c];
  101. SendMessage(hWndCtl, LVM_INSERTCOLUMN, c, (LPARAM)&lvc);
  102. }
  103. //---- initialize the items ----
  104. LVITEM item;
  105. memset(&item, 0, sizeof(item));
  106. item.mask = LVIF_TEXT;
  107. //---- add the items ----
  108. for (int i=0; i < _countof(Col1Items); i++)
  109. {
  110. item.pszText = Col1Items[i];
  111. item.iItem = i;
  112. item.iSubItem = 0;
  113. SendMessage(hWndCtl, LVM_INSERTITEM, 0, (LPARAM)&item);
  114. item.iSubItem = 1;
  115. item.pszText = Col2Items[i];
  116. SendMessage(hWndCtl, LVM_SETITEM, 0, (LPARAM)&item);
  117. item.iSubItem = 2;
  118. item.pszText = Col3Items[i];
  119. SendMessage(hWndCtl, LVM_SETITEM, 0, (LPARAM)&item);
  120. }
  121. }
  122. //-------------------------------------------------------------------------//
  123. // Treeview
  124. //-------------------------------------------------------------------------//
  125. void TreeView_Init(HWND hWndCtl)
  126. {
  127. //---- initialize the item ----
  128. TVINSERTSTRUCT tvs;
  129. memset(&tvs, 0, sizeof(tvs));
  130. tvs.itemex.mask = TVIF_TEXT;
  131. tvs.hInsertAfter = TVI_LAST;
  132. tvs.itemex.pszText = L"Root";
  133. HTREEITEM hRoot = (HTREEITEM) SendMessage(hWndCtl, TVM_INSERTITEM, 0, (LPARAM)&tvs);
  134. //---- add the items ----
  135. for (int i=0; i < _countof(Col1Items); i++)
  136. {
  137. tvs.itemex.pszText = Col1Items[i];
  138. tvs.hParent = hRoot;
  139. HTREEITEM hItem = (HTREEITEM) SendMessage(hWndCtl, TVM_INSERTITEM, 0, (LPARAM)&tvs);
  140. if (hItem)
  141. {
  142. TVINSERTSTRUCT tvchild;
  143. memset(&tvchild, 0, sizeof(tvchild));
  144. tvchild.itemex.mask = TVIF_TEXT;
  145. tvchild.hInsertAfter = TVI_LAST;
  146. tvchild.hParent = hItem;
  147. tvchild.itemex.pszText = Col2Items[i];
  148. SendMessage(hWndCtl, TVM_INSERTITEM, 0, (LPARAM)&tvchild);
  149. tvchild.itemex.pszText = Col3Items[i];
  150. SendMessage(hWndCtl, TVM_INSERTITEM, 0, (LPARAM)&tvchild);
  151. }
  152. }
  153. }
  154. //-------------------------------------------------------------------------//
  155. // Header
  156. //-------------------------------------------------------------------------//
  157. void Header_Init(HWND hWndCtl)
  158. {
  159. //---- initialize the item ----
  160. HDITEM item;
  161. memset(&item, 0, sizeof(item));
  162. item.mask = HDI_WIDTH | HDI_TEXT;
  163. item.cxy = 60;
  164. //---- add the items ----
  165. for (int i=0; i < _countof(Columns); i++)
  166. {
  167. item.pszText = Columns[i];
  168. HTREEITEM hItem = (HTREEITEM) SendMessage(hWndCtl, HDM_INSERTITEM, i, (LPARAM)&item);
  169. }
  170. }
  171. //-------------------------------------------------------------------------//
  172. // Status bar
  173. //-------------------------------------------------------------------------//
  174. void Status_Init(HWND hWndCtl)
  175. {
  176. //---- setup the different sections ----
  177. int Widths[] = {200, 400, 600};
  178. SendMessage(hWndCtl, SB_SETPARTS, _countof(Widths), (LPARAM)Widths);
  179. //---- write some text ----
  180. SendMessage(hWndCtl, SB_SETTEXT, 0, (LPARAM)L"First Section");
  181. SendMessage(hWndCtl, SB_SETTEXT, 1, (LPARAM)L"Second Section");
  182. SendMessage(hWndCtl, SB_SETTEXT, 2, (LPARAM)L"Third Section");
  183. }
  184. //-------------------------------------------------------------------------//
  185. // Toolbar
  186. //-------------------------------------------------------------------------//
  187. void Toolbar_Init(HWND hWndCtl)
  188. {
  189. //---- send require toolbar init msg ----
  190. SendMessage(hWndCtl, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
  191. //---- setup the bitmap images for buttons ----
  192. TBADDBITMAP abm = {HINST_COMMCTRL, IDB_STD_LARGE_COLOR};
  193. SendMessage(hWndCtl, TB_ADDBITMAP, 15, (LPARAM)&abm);
  194. TBBUTTON button;
  195. memset(&button, 0, sizeof(button));
  196. button.fsState = TBSTATE_ENABLED;
  197. //int index = (int)SendMessage(hwnd, TB_ADDSTRING, NULL, (LPARAM)Buttons);
  198. int cnt = min(10, _countof(Buttons));
  199. for (int i=0; i < cnt; i++)
  200. {
  201. button.fsStyle = TBSTYLE_BUTTON;
  202. button.iBitmap = ButtonIndexes[i];
  203. button.idCommand = i;
  204. button.iString = 0; // index + i;
  205. SendMessage(hWndCtl, TB_ADDBUTTONS, 1, LPARAM(&button));
  206. if ((i == 2) || (i == 5) || (i == 7) || (i == 9))
  207. {
  208. button.fsStyle = BTNS_SEP;
  209. SendMessage(hWndCtl, TB_ADDBUTTONS, 1, LPARAM(&button));
  210. }
  211. }
  212. SendMessage(hWndCtl, TB_AUTOSIZE, 0, 0);
  213. ShowWindow(hWndCtl, SW_SHOW);
  214. }
  215. //-------------------------------------------------------------------------//
  216. // Rebar
  217. //-------------------------------------------------------------------------//
  218. void Rebar_Init(HWND hWndCtl)
  219. {
  220. //---- initialize the rebar ----
  221. REBARINFO rbi;
  222. rbi.cbSize = sizeof(rbi);
  223. rbi.fMask = 0;
  224. rbi.himl = (HIMAGELIST)NULL;
  225. SendMessage(hWndCtl, RB_SETBARINFO, 0, (LPARAM)&rbi);
  226. //---- initialize the band ----
  227. REBARBANDINFO rbBand;
  228. rbBand.cbSize = sizeof(REBARBANDINFO);
  229. rbBand.fMask = RBBIM_TEXT | RBBIM_STYLE | RBBIM_CHILD | RBBIM_CHILDSIZE | RBBIM_SIZE;
  230. rbBand.fStyle = RBBS_GRIPPERALWAYS | RBBS_BREAK;
  231. // rbBand.hbmBack= LoadBitmap(g_hInst, MAKEINTRESOURCE(IDB_BACKGROUND));
  232. RECT rc;
  233. HWND hwndCB, hwndTB;
  234. // Create the combo box control to be added.
  235. hwndCB = CreateWindowEx(0, L"Combobox", L"Combo Text", WS_VISIBLE | WS_CHILD | WS_BORDER,
  236. 0, 0, 100, 30, hWndCtl, (HMENU)51, _Module.GetModuleInstance(), 0);
  237. // Set values unique to the band with the combo box.
  238. GetWindowRect(hwndCB, &rc);
  239. rbBand.lpText = L"Combo Box";
  240. rbBand.hwndChild = hwndCB;
  241. rbBand.cxMinChild = 20;
  242. rbBand.cyMinChild = rc.bottom - rc.top;
  243. rbBand.cx = 120; // WIDTH(rc) + 20;
  244. // Add the band that has the combo box.
  245. LRESULT val = SendMessage(hWndCtl, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand);
  246. #if 1
  247. // Create the toolbar control to be added.
  248. hwndTB = CreateWindowEx(0, L"SysToolBar32", L"", WS_VISIBLE | WS_CHILD | WS_BORDER,
  249. 0, 0, 500, 30, hWndCtl, (HMENU)52, _Module.GetModuleInstance(), 0);
  250. Toolbar_Init(hwndTB);
  251. // Set values unique to the band with the toolbar.
  252. rbBand.lpText = L"Tool Bar";
  253. rbBand.hwndChild = hwndTB;
  254. rbBand.cxMinChild = 20;
  255. DWORD dwBtnSize = (DWORD) SendMessage(hwndTB, TB_GETBUTTONSIZE, 0,0);
  256. rbBand.cyMinChild = HIWORD(dwBtnSize);
  257. GetWindowRect(hwndTB, &rc);
  258. rbBand.cx = 450; // WIDTH(rc) + 20;
  259. // Add the band that has the toolbar.
  260. val = SendMessage(hWndCtl, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand);
  261. #endif
  262. }