Leaked source code of windows server 2003
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.

563 lines
18 KiB

  1. #include "pch.h"
  2. #include "resource.h"
  3. #include "main.h"
  4. //-------------------------------------------------------------------------//
  5. // impl for all Samples pages
  6. //-------------------------------------------------------------------------//
  7. INT_PTR CALLBACK Shared_DlgProc( HWND hwndPage, UINT, WPARAM , LPARAM );
  8. INT_PTR CALLBACK Pickers_DlgProc( HWND hwndPage, UINT, WPARAM , LPARAM );
  9. INT_PTR CALLBACK Movers_DlgProc( HWND hwndPage, UINT, WPARAM , LPARAM );
  10. INT_PTR CALLBACK Lists_DlgProc( HWND hwndPage, UINT, WPARAM , LPARAM );
  11. INT_PTR CALLBACK ListView_DlgProc( HWND hwndPage, UINT, WPARAM , LPARAM );
  12. INT_PTR CALLBACK TreeView_DlgProc( HWND hwndPage, UINT, WPARAM , LPARAM );
  13. INT_PTR CALLBACK Bars_DlgProc( HWND hwndPage, UINT, WPARAM , LPARAM );
  14. void Pickers_Init(HWND hwndPage);
  15. void Movers_Init(HWND hwndPage);
  16. void Lists_Init(HWND hwndPage);
  17. void ListView_Init(HWND hwndPage, int iControlId);
  18. void TreeView_Init(HWND hwndPage, int iControlId);
  19. //---- init routines for "bars" dialog ----
  20. void Header_Init(HWND hwndPage, int iControlId);
  21. void Status_Init(HWND hwndPage, int iControlId);
  22. void Toolbar_Init(HWND hwndPage, int iControlId, int iMaxButtons);
  23. void Rebar_Init(HWND hwndPage, int iControlId);
  24. //-------------------------------------------------------------------------//
  25. // shared sample data
  26. static WCHAR *Names[] = {L"One", L"Two", L"Three", L"Four", L"Five", L"Six",
  27. L"Seven", L"Eight", L"Nine", L"Ten", L"Eleven", L"Twelve",
  28. L"Thirteen", L"Fourteen", L"Fifteen", L"Sixteen"};
  29. static WCHAR *Buttons[] = {L"New", L"Open", L"Save", L"Cut", L"Copy", L"Delete",
  30. L"Undo", L"Redo", L"Print", L"Help\0"};
  31. static int ButtonIndexes[] = {STD_FILENEW, STD_FILEOPEN, STD_FILESAVE,
  32. STD_CUT, STD_COPY, STD_DELETE, STD_UNDO, STD_REDOW, STD_PRINT, STD_HELP};
  33. static WCHAR *Columns[] = {L"Name", L"Phone", L"City", L"State"};
  34. static WCHAR *Col1Items[] = {L"Chris", L"Lou", L"Richard", L"Mark", L"Roland", L"Paul",
  35. L"Scott", L"Aaron", L"Greg", L"Ken"};
  36. static WCHAR *Col2Items[] = {L"555-1212", L"567-3434", L"656-4432", L"343-7788", L"706-0225", L"828-3043",
  37. L"706-4433", L"882-8080", L"334-3434", L"333-5430"};
  38. static WCHAR *Col3Items[] = {L"Seattle", L"Redmond", L"Bellevue", L"Seattle", L"Woodinville", L"Kirkland",
  39. L"Kirkland", L"Woodinville", L"Redmond", L"Redmond"};
  40. //-------------------------------------------------------------------------//
  41. INT_PTR CALLBACK Shared_DlgProc( HWND hwndPage, UINT uMsg, WPARAM wParam, LPARAM lParam )
  42. {
  43. BOOL bHandled = TRUE;
  44. LRESULT lRet = 0L;
  45. switch( uMsg )
  46. {
  47. case WM_INITDIALOG:
  48. //Log(LOG_TMCHANGE, L"Creating hwnd=0x%x", hwndPage);
  49. break;
  50. case WM_DESTROY:
  51. break;
  52. default:
  53. bHandled = FALSE;
  54. break;
  55. }
  56. return bHandled;
  57. }
  58. //-------------------------------------------------------------------------//
  59. INT_PTR CALLBACK Pickers_DlgProc( HWND hwndPage, UINT uMsg, WPARAM wParam, LPARAM lParam )
  60. {
  61. BOOL bHandled = TRUE;
  62. LRESULT lRet = 0L;
  63. switch( uMsg )
  64. {
  65. case WM_INITDIALOG:
  66. Pickers_Init(hwndPage);
  67. break;
  68. case WM_DESTROY:
  69. break;
  70. default:
  71. bHandled = FALSE;
  72. break;
  73. }
  74. return bHandled;
  75. }
  76. //-------------------------------------------------------------------------//
  77. INT_PTR CALLBACK Movers_DlgProc( HWND hwndPage, UINT uMsg, WPARAM wParam, LPARAM lParam )
  78. {
  79. BOOL bHandled = TRUE;
  80. LRESULT lRet = 0L;
  81. switch( uMsg )
  82. {
  83. case WM_INITDIALOG:
  84. Movers_Init(hwndPage);
  85. break;
  86. case WM_DESTROY:
  87. break;
  88. default:
  89. bHandled = FALSE;
  90. break;
  91. }
  92. return bHandled;
  93. }
  94. //-------------------------------------------------------------------------//
  95. INT_PTR CALLBACK Lists_DlgProc( HWND hwndPage, UINT uMsg, WPARAM wParam, LPARAM lParam )
  96. {
  97. BOOL bHandled = TRUE;
  98. LRESULT lRet = 0L;
  99. switch( uMsg )
  100. {
  101. case WM_INITDIALOG:
  102. Lists_Init(hwndPage);
  103. break;
  104. case WM_DESTROY:
  105. break;
  106. default:
  107. bHandled = FALSE;
  108. break;
  109. }
  110. return bHandled;
  111. }
  112. //-------------------------------------------------------------------------//
  113. INT_PTR CALLBACK ListView_DlgProc( HWND hwndPage, UINT uMsg, WPARAM wParam, LPARAM lParam )
  114. {
  115. BOOL bHandled = TRUE;
  116. LRESULT lRet = 0L;
  117. switch( uMsg )
  118. {
  119. case WM_INITDIALOG:
  120. ListView_Init(hwndPage, IDC_LIST1);
  121. ListView_Init(hwndPage, IDC_LIST2);
  122. break;
  123. case WM_DESTROY:
  124. break;
  125. default:
  126. bHandled = FALSE;
  127. break;
  128. }
  129. return bHandled;
  130. }
  131. //-------------------------------------------------------------------------//
  132. INT_PTR CALLBACK TreeView_DlgProc( HWND hwndPage, UINT uMsg, WPARAM wParam, LPARAM lParam )
  133. {
  134. BOOL bHandled = TRUE;
  135. LRESULT lRet = 0L;
  136. switch( uMsg )
  137. {
  138. case WM_INITDIALOG:
  139. TreeView_Init(hwndPage, IDC_TREE1);
  140. TreeView_Init(hwndPage, IDC_TREE2);
  141. break;
  142. case WM_DESTROY:
  143. break;
  144. default:
  145. bHandled = FALSE;
  146. break;
  147. }
  148. return bHandled;
  149. }
  150. //-------------------------------------------------------------------------//
  151. INT_PTR CALLBACK Bars_DlgProc( HWND hwndPage, UINT uMsg, WPARAM wParam, LPARAM lParam )
  152. {
  153. BOOL bHandled = TRUE;
  154. LRESULT lRet = 0L;
  155. switch( uMsg )
  156. {
  157. case WM_INITDIALOG:
  158. Header_Init(hwndPage, IDC_HEADER1);
  159. Status_Init(hwndPage, IDC_STATUS1);
  160. // Toolbar_Init(hwndPage, IDC_TOOLBAR1);
  161. Rebar_Init(hwndPage, IDC_REBAR1);
  162. break;
  163. case WM_DESTROY:
  164. break;
  165. default:
  166. bHandled = FALSE;
  167. break;
  168. }
  169. return bHandled;
  170. }
  171. //-------------------------------------------------------------------------//
  172. void Pickers_Init(HWND hwndPage)
  173. {
  174. HWND hwnd1 = GetDlgItem(hwndPage, IDC_TAB1);
  175. HWND hwnd2 = GetDlgItem(hwndPage, IDC_TAB2);
  176. TCITEM item;
  177. item.mask = TCIF_TEXT;
  178. for (int i=0; i < 4; i++)
  179. {
  180. item.pszText = Names[i];
  181. SendMessage(hwnd1, TCM_INSERTITEM, i, (LPARAM)&item);
  182. SendMessage(hwnd2, TCM_INSERTITEM, i, (LPARAM)&item);
  183. }
  184. }
  185. //-------------------------------------------------------------------------//
  186. void Movers_Init(HWND hwndPage)
  187. {
  188. HWND hwnd1 = GetDlgItem(hwndPage, IDC_PROGRESS1);
  189. HWND hwnd2 = GetDlgItem(hwndPage, IDC_PROGRESS2);
  190. SendMessage(hwnd1, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
  191. SendMessage(hwnd2, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
  192. SendMessage(hwnd1, PBM_SETPOS, 33, 0);
  193. SendMessage(hwnd2, PBM_SETPOS, 33, 0);
  194. }
  195. //-------------------------------------------------------------------------//
  196. void Lists_Init(HWND hwndPage)
  197. {
  198. HWND hwnds[7];
  199. hwnds[0] = GetDlgItem(hwndPage, IDC_LIST1);
  200. hwnds[1] = GetDlgItem(hwndPage, IDC_COMBO1);
  201. hwnds[2] = GetDlgItem(hwndPage, IDC_COMBO2);
  202. hwnds[3] = GetDlgItem(hwndPage, IDC_COMBO3);
  203. hwnds[4] = GetDlgItem(hwndPage, IDC_COMBOBOXEX1);
  204. hwnds[5] = GetDlgItem(hwndPage, IDC_COMBOBOXEX2);
  205. hwnds[6] = GetDlgItem(hwndPage, IDC_COMBOBOXEX3);
  206. //---- listbox ----
  207. SendMessage(hwnds[0], LB_RESETCONTENT, 0, 0);
  208. for (int j=0; j < ARRAYSIZE(Names); j++)
  209. SendMessage(hwnds[0], LB_ADDSTRING, 0, (LPARAM)Names[j]);
  210. SendMessage(hwnds[0], LB_SETCURSEL, 0, 0);
  211. //---- comboboxes ----
  212. for (int i=1; i < 4; i++)
  213. {
  214. SendMessage(hwnds[i], CB_RESETCONTENT, 0, 0);
  215. for (int j=0; j < ARRAYSIZE(Names); j++)
  216. SendMessage(hwnds[i], CB_ADDSTRING, 0, (LPARAM)Names[j]);
  217. SendMessage(hwnds[i], CB_SETCURSEL, 0, 0);
  218. }
  219. //---- combo EX boxes ----
  220. COMBOBOXEXITEM exitem;
  221. exitem.mask = CBEIF_TEXT ;
  222. for (i=4; i < 7; i++)
  223. {
  224. SendMessage(hwnds[i], CB_RESETCONTENT, 0, 0);
  225. for (int j=0; j < ARRAYSIZE(Names); j++)
  226. {
  227. exitem.iItem = j;
  228. exitem.pszText = Names[j];
  229. SendMessage(hwnds[i], CBEM_INSERTITEM, 0, (LPARAM)&exitem);
  230. }
  231. SendMessage(hwnds[i], CB_SETCURSEL, 0, 0);
  232. }
  233. }
  234. //-------------------------------------------------------------------------//
  235. void ListView_Init(HWND hwndPage, int iControlId)
  236. {
  237. HWND hwnd = GetDlgItem(hwndPage, iControlId);
  238. if (! hwnd)
  239. return;
  240. //---- initialize the colums ----
  241. LVCOLUMN lvc;
  242. memset(&lvc, 0, sizeof(lvc));
  243. lvc.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_FMT | LVCF_WIDTH;
  244. lvc.fmt = LVCFMT_LEFT;
  245. lvc.cx = 100;
  246. // Add the columns.
  247. for (int c=0; c < ARRAYSIZE(Columns); c++)
  248. {
  249. lvc.iSubItem = c;
  250. lvc.pszText = Columns[c];
  251. SendMessage(hwnd, LVM_INSERTCOLUMN, c, (LPARAM)&lvc);
  252. }
  253. //---- initialize the items ----
  254. LVITEM item;
  255. memset(&item, 0, sizeof(item));
  256. item.mask = LVIF_TEXT;
  257. //---- add the items ----
  258. for (int i=0; i < ARRAYSIZE(Col1Items); i++)
  259. {
  260. item.pszText = Col1Items[i];
  261. item.iItem = i;
  262. item.iSubItem = 0;
  263. SendMessage(hwnd, LVM_INSERTITEM, 0, (LPARAM)&item);
  264. item.iSubItem = 1;
  265. item.pszText = Col2Items[i];
  266. SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
  267. item.iSubItem = 2;
  268. item.pszText = Col3Items[i];
  269. SendMessage(hwnd, LVM_SETITEM, 0, (LPARAM)&item);
  270. }
  271. }
  272. //-------------------------------------------------------------------------//
  273. void TreeView_Init(HWND hwndPage, int iControlId)
  274. {
  275. HWND hwnd = GetDlgItem(hwndPage, iControlId);
  276. if (! hwnd)
  277. return;
  278. //---- initialize the item ----
  279. TVINSERTSTRUCT tvs;
  280. memset(&tvs, 0, sizeof(tvs));
  281. tvs.itemex.mask = TVIF_TEXT;
  282. tvs.hInsertAfter = TVI_LAST;
  283. tvs.itemex.pszText = L"Root";
  284. HTREEITEM hRoot = (HTREEITEM) SendMessage(hwnd, TVM_INSERTITEM, 0, (LPARAM)&tvs);
  285. //---- add the items ----
  286. for (int i=0; i < ARRAYSIZE(Col1Items); i++)
  287. {
  288. tvs.itemex.pszText = Col1Items[i];
  289. tvs.hParent = hRoot;
  290. HTREEITEM hItem = (HTREEITEM) SendMessage(hwnd, TVM_INSERTITEM, 0, (LPARAM)&tvs);
  291. if (hItem)
  292. {
  293. TVINSERTSTRUCT tvchild;
  294. memset(&tvchild, 0, sizeof(tvchild));
  295. tvchild.itemex.mask = TVIF_TEXT;
  296. tvchild.hInsertAfter = TVI_LAST;
  297. tvchild.hParent = hItem;
  298. tvchild.itemex.pszText = Col2Items[i];
  299. SendMessage(hwnd, TVM_INSERTITEM, 0, (LPARAM)&tvchild);
  300. tvchild.itemex.pszText = Col3Items[i];
  301. SendMessage(hwnd, TVM_INSERTITEM, 0, (LPARAM)&tvchild);
  302. }
  303. }
  304. }
  305. //-------------------------------------------------------------------------//
  306. void Header_Init(HWND hwndPage, int iControlId)
  307. {
  308. HWND hwnd = GetDlgItem(hwndPage, iControlId);
  309. if (! hwnd)
  310. return;
  311. //---- initialize the item ----
  312. HDITEM item;
  313. memset(&item, 0, sizeof(item));
  314. item.mask = HDI_WIDTH | HDI_TEXT;
  315. item.cxy = 60;
  316. //---- add the items ----
  317. for (int i=0; i < ARRAYSIZE(Columns); i++)
  318. {
  319. item.pszText = Columns[i];
  320. HTREEITEM hItem = (HTREEITEM) SendMessage(hwnd, HDM_INSERTITEM, i, (LPARAM)&item);
  321. }
  322. }
  323. //-------------------------------------------------------------------------//
  324. void Status_Init(HWND hwndPage, int iControlId)
  325. {
  326. HWND hwnd = GetDlgItem(hwndPage, iControlId);
  327. if (! hwnd)
  328. return;
  329. //---- setup the different sections ----
  330. int Widths[] = {200, 400, 600};
  331. SendMessage(hwnd, SB_SETPARTS, ARRAYSIZE(Widths), (LPARAM)Widths);
  332. //---- write some text ----
  333. SendMessage(hwnd, SB_SETTEXT, 0, (LPARAM)L"First Section");
  334. SendMessage(hwnd, SB_SETTEXT, 1, (LPARAM)L"Second Section");
  335. SendMessage(hwnd, SB_SETTEXT, 2, (LPARAM)L"Third Section");
  336. }
  337. //-------------------------------------------------------------------------//
  338. void Toolbar_Init(HWND hwndPage, int iControlId, int iMaxButtons)
  339. {
  340. HWND hwnd = GetDlgItem(hwndPage, iControlId);
  341. if (! hwnd)
  342. return;
  343. //---- send require toolbar init msg ----
  344. SendMessage(hwnd, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
  345. //---- setup the bitmap images for buttons ----
  346. TBADDBITMAP abm = {HINST_COMMCTRL, IDB_STD_LARGE_COLOR};
  347. SendMessage(hwnd, TB_ADDBITMAP, 15, (LPARAM)&abm);
  348. TBBUTTON button;
  349. memset(&button, 0, sizeof(button));
  350. button.fsState = TBSTATE_ENABLED;
  351. //int index = (int)SendMessage(hwnd, TB_ADDSTRING, NULL, (LPARAM)Buttons);
  352. int cnt = (int)min(iMaxButtons, ARRAYSIZE(Buttons));
  353. for (int i=0; i < cnt; i++)
  354. {
  355. button.fsStyle = TBSTYLE_BUTTON;
  356. button.iBitmap = ButtonIndexes[i];
  357. button.idCommand = i;
  358. button.iString = 0; // index + i;
  359. SendMessage(hwnd, TB_ADDBUTTONS, 1, LPARAM(&button));
  360. if ((i == 2) || (i == 5) || (i == 7) || (i == 9))
  361. {
  362. button.fsStyle = BTNS_SEP;
  363. SendMessage(hwnd, TB_ADDBUTTONS, 1, LPARAM(&button));
  364. }
  365. }
  366. SendMessage(hwnd, TB_AUTOSIZE, 0, 0);
  367. ShowWindow(hwnd, SW_SHOW);
  368. }
  369. //-------------------------------------------------------------------------//
  370. void Rebar_Init(HWND hwndPage, int iControlId)
  371. {
  372. HWND hwndRB = GetDlgItem(hwndPage, iControlId);
  373. if (! hwndRB)
  374. return;
  375. //---- initialize the rebar ----
  376. REBARINFO rbi;
  377. rbi.cbSize = sizeof(rbi);
  378. rbi.fMask = 0;
  379. rbi.himl = (HIMAGELIST)NULL;
  380. SendMessage(hwndRB, RB_SETBARINFO, 0, (LPARAM)&rbi);
  381. //---- initialize the band ----
  382. REBARBANDINFO rbBand;
  383. rbBand.cbSize = sizeof(REBARBANDINFO);
  384. rbBand.fMask = RBBIM_TEXT | RBBIM_STYLE | RBBIM_CHILD | RBBIM_CHILDSIZE | RBBIM_SIZE;
  385. rbBand.fStyle = RBBS_GRIPPERALWAYS | RBBS_BREAK;
  386. // rbBand.hbmBack= LoadBitmap(g_hInst, MAKEINTRESOURCE(IDB_BACKGROUND));
  387. RECT rc;
  388. HWND hwndCB, hwndTB;
  389. // Create the combo box control to be added.
  390. hwndCB = CreateWindowEx(0, L"Combobox", L"Combo Text", WS_VISIBLE | WS_CHILD | WS_BORDER,
  391. 0, 0, 100, 30, hwndRB, (HMENU)51, g_hInst, 0);
  392. // Set values unique to the band with the combo box.
  393. GetWindowRect(hwndCB, &rc);
  394. rbBand.lpText = L"Combo Box";
  395. rbBand.hwndChild = hwndCB;
  396. rbBand.cxMinChild = 20;
  397. rbBand.cyMinChild = HEIGHT(rc);
  398. rbBand.cx = 120; // WIDTH(rc) + 20;
  399. // Add the band that has the combo box.
  400. LRESULT val = SendMessage(hwndRB, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand);
  401. #if 1
  402. // Create the toolbar control to be added.
  403. hwndTB = CreateWindowEx(0, L"SysToolBar32", L"", WS_VISIBLE | WS_CHILD | WS_BORDER,
  404. 0, 0, 500, 30, hwndRB, (HMENU)52, g_hInst, 0);
  405. Toolbar_Init(hwndRB, 52, 3);
  406. // Set values unique to the band with the toolbar.
  407. rbBand.lpText = L"Tool Bar";
  408. rbBand.hwndChild = hwndTB;
  409. rbBand.cxMinChild = 20;
  410. DWORD dwBtnSize = (DWORD) SendMessage(hwndTB, TB_GETBUTTONSIZE, 0,0);
  411. rbBand.cyMinChild = HIWORD(dwBtnSize);
  412. GetWindowRect(hwndTB, &rc);
  413. rbBand.cx = 450; // WIDTH(rc) + 20;
  414. // Add the band that has the toolbar.
  415. val = SendMessage(hwndRB, RB_INSERTBAND, (WPARAM)-1, (LPARAM)&rbBand);
  416. #endif
  417. }
  418. //-------------------------------------------------------------------------//
  419. HWND CALLBACK StaticsPage_CreateInstance( HWND hwndParent )
  420. {
  421. return CreateDialog( g_hInst, MAKEINTRESOURCE(IDD_STATICS),
  422. hwndParent, Shared_DlgProc );
  423. }
  424. //---------------------------------------------------------------------------
  425. HWND CALLBACK ButtonsPage_CreateInstance( HWND hwndParent )
  426. {
  427. return CreateDialog( g_hInst, MAKEINTRESOURCE(IDD_BUTTONS),
  428. hwndParent, Shared_DlgProc );
  429. }
  430. //-------------------------------------------------------------------------//
  431. HWND CALLBACK EditPage_CreateInstance( HWND hwndParent )
  432. {
  433. return CreateDialog( g_hInst, MAKEINTRESOURCE(IDD_EDIT),
  434. hwndParent, Shared_DlgProc );
  435. }
  436. //-------------------------------------------------------------------------//
  437. HWND CALLBACK TreeViewPage_CreateInstance( HWND hwndParent )
  438. {
  439. return CreateDialog( g_hInst, MAKEINTRESOURCE(IDD_TREEVIEW),
  440. hwndParent, TreeView_DlgProc );
  441. }
  442. //-------------------------------------------------------------------------//
  443. HWND CALLBACK ListViewPage_CreateInstance( HWND hwndParent )
  444. {
  445. return CreateDialog( g_hInst, MAKEINTRESOURCE(IDD_LISTVIEW),
  446. hwndParent, ListView_DlgProc );
  447. }
  448. //-------------------------------------------------------------------------//
  449. HWND CALLBACK PickersPage_CreateInstance( HWND hwndParent )
  450. {
  451. return CreateDialog( g_hInst, MAKEINTRESOURCE(IDD_PICKERS),
  452. hwndParent, Pickers_DlgProc );
  453. }
  454. //-------------------------------------------------------------------------//
  455. HWND CALLBACK MoversPage_CreateInstance( HWND hwndParent )
  456. {
  457. return CreateDialog( g_hInst, MAKEINTRESOURCE(IDD_MOVERS),
  458. hwndParent, Movers_DlgProc );
  459. }
  460. //-------------------------------------------------------------------------//
  461. HWND CALLBACK ListsPage_CreateInstance( HWND hwndParent )
  462. {
  463. return CreateDialog( g_hInst, MAKEINTRESOURCE(IDD_LISTS),
  464. hwndParent, Lists_DlgProc );
  465. }
  466. //---------------------------------------------------------------------------
  467. HWND CALLBACK BarsPage_CreateInstance( HWND hwndParent )
  468. {
  469. return CreateDialog( g_hInst, MAKEINTRESOURCE(IDD_BARS),
  470. hwndParent, Bars_DlgProc );
  471. }
  472. //---------------------------------------------------------------------------