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.

310 lines
9.2 KiB

  1. #include "stdafx.h"
  2. #include "resource.h"
  3. #include "MainWnd.h"
  4. #include "TreeViewWnd.h"
  5. #include "ListViewWnd.h"
  6. //
  7. // global WndProcs, for handling subclassed windows
  8. //
  9. WNDPROC gTreeViewWndSysWndProc = NULL;
  10. WNDPROC gListViewWndSysWndProc = NULL;
  11. #define _ADDDUMMYITEMS // add dummy items for debugging TreeViewWnd
  12. #define _ADDDUMMYPROPERTIES // add dummy properties for debugging ListViewWnd
  13. int APIENTRY WinMain(HINSTANCE hInstance,
  14. HINSTANCE hPrevInstance,
  15. LPSTR lpCmdLine,
  16. int nCmdShow)
  17. {
  18. INITCOMMONCONTROLSEX InitCtrls;
  19. InitCtrls.dwSize = sizeof(INITCOMMONCONTROLSEX);
  20. InitCtrls.dwICC = ICC_TREEVIEW_CLASSES|ICC_LISTVIEW_CLASSES;
  21. InitCommonControlsEx(&InitCtrls);
  22. TCHAR szWndName[255];
  23. TCHAR szWndClassName[255];
  24. LoadString(hInstance,IDS_APPNAME,szWndName,sizeof(szWndName));
  25. LoadString(hInstance,IDC_APPWNDCLASS,szWndClassName,sizeof(szWndClassName));
  26. CMainWnd MainWnd(NULL);
  27. HWND hWnd = MainWnd.Create(szWndName,
  28. szWndClassName,
  29. WS_OVERLAPPEDWINDOW,
  30. 0,
  31. CW_USEDEFAULT, CW_USEDEFAULT,
  32. CW_USEDEFAULT, CW_USEDEFAULT,
  33. NULL,
  34. LoadMenu( hInstance, MAKEINTRESOURCE(IDC_PROPVIEW_MENU)),
  35. hInstance );
  36. if (!hWnd) {
  37. Trace(TEXT("\nUnable to create main appication window\n"));
  38. return FALSE;
  39. }
  40. ShowWindow(hWnd, SW_SHOW);
  41. UpdateWindow(hWnd);
  42. //
  43. // create TREEVIEW child window
  44. //
  45. LoadString(hInstance,IDS_TREEVIEWNAME,szWndName,sizeof(szWndName));
  46. LoadString(hInstance,IDC_TREEVIEWWNDCLASS,szWndClassName,sizeof(szWndClassName));
  47. //
  48. // calculate the child window's height and width using the parents dimisions.
  49. // note: Child's starting width is 1/3 the parents width.
  50. //
  51. RECT MainWndClientRect;
  52. GetClientRect(hWnd,&MainWndClientRect);
  53. INT iWindowWidth = (MainWndClientRect.right - MainWndClientRect.left)/3;
  54. INT iWindowHeight = (MainWndClientRect.bottom - MainWndClientRect.top);
  55. CTreeViewWnd TreeViewWnd(NULL);
  56. HWND hTreeViewWnd = TreeViewWnd.Create(szWndName,
  57. szWndClassName,
  58. WS_CHILD|WS_VISIBLE|WS_SIZEBOX|WS_TABSTOP|
  59. TVS_HASBUTTONS|TVS_HASLINES |TVS_LINESATROOT|
  60. TVS_EDITLABELS | TVS_SHOWSELALWAYS,
  61. WS_EX_CLIENTEDGE/*|WS_EX_NOPARENTNOTIFY*/,
  62. 0, 0,
  63. iWindowWidth, iWindowHeight,
  64. hWnd,
  65. NULL,
  66. hInstance);
  67. if (!hTreeViewWnd) {
  68. Trace(TEXT("\nUnable to create tree view window\n"));
  69. return FALSE;
  70. }
  71. TreeViewWnd.SetWindowHandle(hTreeViewWnd);
  72. #ifdef _ADDDUMMYITEMS
  73. //
  74. // TODO: Remove this code.
  75. // (inserting items to see if we are working properly)
  76. //
  77. INT ICON_ROOTITEM = -1;
  78. INT ICON_FOLDER = -1;
  79. INT ICON_ITEM = -1;
  80. TV_INSERTSTRUCT tv;
  81. tv.hParent = TVI_ROOT;
  82. tv.hInsertAfter = TVI_LAST;
  83. tv.item.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_TEXT | TVIF_PARAM;
  84. tv.item.hItem = NULL;
  85. tv.item.state = TVIS_EXPANDED;
  86. tv.item.stateMask = TVIS_STATEIMAGEMASK;
  87. tv.item.cchTextMax = 6;
  88. tv.item.cChildren = 0;
  89. tv.item.lParam = 0;
  90. tv.item.pszText = TEXT("Root Item");
  91. //
  92. // Create image list
  93. //
  94. HIMAGELIST hImageList = NULL;
  95. hImageList = CreateImageList(16,16,0,3);
  96. if(hImageList != NULL) {
  97. //
  98. // assign indexes to loaded icons
  99. //
  100. AddIconToImageList(hInstance,IDI_ROOTICON,hImageList,&ICON_ROOTITEM);
  101. AddIconToImageList(hInstance,IDI_FOLDERICON,hImageList,&ICON_FOLDER);
  102. AddIconToImageList(hInstance,IDI_ITEM,hImageList,&ICON_ITEM);
  103. //
  104. // set image list
  105. //
  106. TreeViewWnd.SetImageList(hImageList,TVSIL_NORMAL);
  107. } else {
  108. Trace(TEXT("Image list failed to be created"));
  109. }
  110. //
  111. // Add the Root Item
  112. //
  113. tv.item.iImage = ICON_ROOTITEM;
  114. tv.item.iSelectedImage = ICON_ROOTITEM;
  115. HTREEITEM hTreeItem = NULL;
  116. hTreeItem = TreeViewWnd.InsertItem(&tv);
  117. //
  118. // Add child items
  119. //
  120. tv.item.iImage = ICON_ITEM;
  121. tv.item.iSelectedImage = ICON_ITEM;
  122. tv.hParent = hTreeItem;
  123. tv.item.pszText = TEXT("Child Item 1");
  124. hTreeItem = TreeViewWnd.InsertItem(&tv);
  125. tv.item.pszText = TEXT("Child Item 2");
  126. hTreeItem = TreeViewWnd.InsertItem(&tv);
  127. //
  128. // Add a Folder
  129. //
  130. tv.item.iImage = ICON_FOLDER;
  131. tv.item.iSelectedImage = ICON_FOLDER;
  132. tv.item.pszText = TEXT("Folder Item");
  133. hTreeItem = TreeViewWnd.InsertItem(&tv);
  134. //
  135. // Add child item
  136. //
  137. tv.item.iImage = ICON_ITEM;
  138. tv.item.iSelectedImage = ICON_ITEM;
  139. tv.hParent = hTreeItem;
  140. tv.item.pszText = TEXT("Folder Child Item 1");
  141. hTreeItem = TreeViewWnd.InsertItem(&tv);
  142. #endif
  143. ShowWindow(hTreeViewWnd, SW_SHOW);
  144. UpdateWindow(hTreeViewWnd);
  145. //
  146. // create LISTVIEW child window
  147. //
  148. LoadString(hInstance,IDS_LISTVIEWNAME,szWndName,sizeof(szWndName));
  149. LoadString(hInstance,IDC_LISTVIEWWNDCLASS,szWndClassName,sizeof(szWndClassName));
  150. //
  151. // calculate the child window's width using the ListView's width and Parent's width dimisions.
  152. // note: ListView will be offset to the right in relation to the TreeView window (sibling)
  153. //
  154. INT iTreeViewWidth = iWindowWidth;
  155. INT iXOffset = iTreeViewWidth;
  156. iWindowWidth = (MainWndClientRect.right - MainWndClientRect.left) - iTreeViewWidth;
  157. CListViewWnd ListViewWnd(NULL);
  158. HWND hListViewWnd = ListViewWnd.Create(szWndName,
  159. szWndClassName,
  160. WS_CHILD|WS_VISIBLE|WS_SIZEBOX|WS_TABSTOP|
  161. LVS_REPORT|LVS_EDITLABELS|LVS_SINGLESEL,
  162. WS_EX_CLIENTEDGE|WS_EX_NOPARENTNOTIFY,
  163. iXOffset,0,
  164. iWindowWidth, iWindowHeight,
  165. hWnd,
  166. NULL,
  167. hInstance );
  168. if (!hListViewWnd) {
  169. Trace(TEXT("\nUnable to create list view window\n"));
  170. return FALSE;
  171. }
  172. ListViewWnd.SetWindowHandle(hListViewWnd);
  173. #ifdef _ADDDUMMYPROPERTIES
  174. LVCOLUMN lv;
  175. LV_ITEM lvitem;
  176. INT nNewColumnIndex = 0;
  177. INT PropID = 0;
  178. TCHAR szString[255];
  179. //
  180. // add column headers, from resource
  181. //
  182. LoadString(hInstance,IDS_PROPERTYNAME,szString,sizeof(szString));
  183. lv.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
  184. lv.fmt = LVCFMT_LEFT ;
  185. lv.cx = 100;
  186. lv.pszText = szString;
  187. lv.cchTextMax = 0;
  188. lv.iOrder = nNewColumnIndex;
  189. lv.iSubItem = nNewColumnIndex;
  190. nNewColumnIndex = ListViewWnd.InsertColumn(0,&lv);
  191. nNewColumnIndex++;
  192. LoadString(hInstance,IDS_PROPERTYVALUE,szString,sizeof(szString));
  193. nNewColumnIndex = ListViewWnd.InsertColumn(1,&lv);
  194. nNewColumnIndex++;
  195. LoadString(hInstance,IDS_PROPERTYTYPE,szString,sizeof(szString));
  196. nNewColumnIndex = ListViewWnd.InsertColumn(2,&lv);
  197. nNewColumnIndex++;
  198. LoadString(hInstance,IDS_PROPERTYACCESS,szString,sizeof(szString));
  199. nNewColumnIndex = ListViewWnd.InsertColumn(3,&lv);
  200. //
  201. // add properties
  202. //
  203. lvitem.mask = LVIF_TEXT | LVIF_PARAM; // set PARAM mask, if setting lParam value
  204. lvitem.pszText = szString;
  205. lvitem.iImage = NULL;
  206. lvitem.lParam = PropID;
  207. for(INT nItem = 0; nItem < 100;nItem++) {
  208. lvitem.mask = LVIF_TEXT; // set TEXT mask
  209. lvitem.iItem = nItem;
  210. lvitem.iSubItem = 0; //first column
  211. sprintf(szString,"Property %d",nItem);
  212. ListViewWnd.InsertItem(&lvitem);
  213. lvitem.iSubItem = 1; //second column
  214. sprintf(szString,"%d",nItem+100);
  215. ListViewWnd.SetItem(&lvitem);
  216. lvitem.iSubItem = 2; //third column
  217. lstrcpy(szString,TEXT("VT_I4"));
  218. ListViewWnd.SetItem(&lvitem);
  219. lvitem.iSubItem = 3; //fourth column
  220. lstrcpy(szString,TEXT("READONLY"));
  221. ListViewWnd.SetItem(&lvitem);
  222. }
  223. #endif
  224. ShowWindow(hListViewWnd, SW_SHOW);
  225. UpdateWindow(hListViewWnd);
  226. //
  227. // Load the Accelerator keys
  228. //
  229. HACCEL hAccel = LoadAccelerators( hInstance, (LPCTSTR)IDC_PROPVIEW );
  230. MSG msg;
  231. while (GetMessage(&msg, NULL, 0, 0)) {
  232. if (!TranslateAccelerator( hWnd, hAccel, &msg )) {
  233. TranslateMessage(&msg);
  234. DispatchMessage(&msg);
  235. }
  236. }
  237. return (int)msg.wParam;
  238. }