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.

356 lines
11 KiB

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