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.

398 lines
11 KiB

  1. /***************************************************************************************************
  2. **
  3. ** MODULE:
  4. **
  5. **
  6. ** DESCRIPTION:
  7. **
  8. **
  9. ** AUTHOR: Daniel Dean.
  10. **
  11. **
  12. **
  13. ** CREATED:
  14. **
  15. **
  16. **
  17. **
  18. ** (C) C O P Y R I G H T D A N I E L D E A N 1 9 9 6.
  19. ***************************************************************************************************/
  20. #include <WINDOWS.H>
  21. #include <dbt.h> // for device change notification defines
  22. #include <hidsdi.h>
  23. #include "CLASS.H"
  24. #include "IOCTL.H"
  25. HANDLE hInst; // Program instance handle
  26. HWND hWndFrame = NULL; // Handle to main window
  27. HWND hWndMDIClient = NULL; // Handle to MDI client
  28. LONG styleDefault = 0; // Default style bits for child windows
  29. /***************************************************************************************************
  30. **
  31. ** HIDFrameWndProc.
  32. **
  33. ** DESCRIPTION: If cases are added for WM_MENUCHAR, WM_NEXTMENU, WM_SETFOCUS,
  34. ** and WM_SIZE, note that these messages should be passed on
  35. ** to DefFrameProc even if we handle them. See the SDK Reference
  36. ** entry for DefFrameProc
  37. **
  38. ** PARAMETERS:
  39. **
  40. ** RETURNS:
  41. **
  42. ***************************************************************************************************/
  43. LPARAM WINAPI HIDFrameWndProc(HWND hWnd, UINT Message, UINT uParam, LPARAM lParam)
  44. {
  45. switch(Message)
  46. {
  47. case WM_CREATE:
  48. {
  49. CLIENTCREATESTRUCT ccs;
  50. // Find window menu where children will be listed
  51. ccs.hWindowMenu = GetSubMenu (GetMenu(hWnd),WINDOWMENU);
  52. ccs.idFirstChild = IDM_WINDOWCHILD;
  53. // Create the MDI client
  54. hWndMDIClient = CreateWindow("mdiclient",
  55. NULL,
  56. WS_CHILD | WS_CLIPCHILDREN,
  57. 0,
  58. 0,
  59. 0,
  60. 0,
  61. hWnd,
  62. 0,
  63. hInst,
  64. (LPSTR)&ccs);
  65. ShowWindow(hWndMDIClient,SW_SHOW);
  66. break;
  67. }
  68. case WM_DEVICECHANGE:
  69. switch( uParam )
  70. {
  71. //
  72. // On removal or insertion of a device, reenumerate the
  73. // attached USB devices
  74. case DBT_DEVICEARRIVAL:
  75. case DBT_DEVICEREMOVECOMPLETE:
  76. CloseAllChildren();
  77. //Sleep(1000);
  78. OpenClassObjects();
  79. return TRUE;
  80. }
  81. break;
  82. case WM_COMMAND:
  83. // Direct all menu selection or accelerator commands to
  84. // the CommandHandler function
  85. CommandHandler(hWnd,uParam);
  86. break;
  87. case WM_CLOSE:
  88. {
  89. DestroyWindow(hWnd);
  90. PostQuitMessage(0);
  91. break;
  92. }
  93. case WM_DESTROY:
  94. PostQuitMessage(0);
  95. break;
  96. default:
  97. // use DefFrameProc() instead of DefWindowProc(), since there
  98. // are things that have to be handled differently because of MDI
  99. return DefFrameProc (hWnd,hWndMDIClient,Message,uParam,lParam);
  100. }
  101. return 0;
  102. }
  103. /***************************************************************************************************
  104. **
  105. ** CloseChildWindow.
  106. **
  107. ** DESCRIPTION:
  108. **
  109. ** PARAMETERS:
  110. **
  111. ** RETURNS: VOID.
  112. **
  113. ***************************************************************************************************/
  114. VOID CloseChildWindow(HWND hWnd)
  115. {
  116. HANDLE hDevice;
  117. OutputDebugString(">>>>HIDMON.EXE: CloseChildWindow()Enter\n");
  118. IOCTLStop(hWnd);
  119. OutputDebugString(">>>>HIDMON.EXE: CloseChildWindow(): CloseHandle()\n");
  120. hDevice=GetDeviceHandle(hWnd);
  121. CloseHandle(hDevice);
  122. SetDeviceHandle(hWnd,NULL);
  123. OutputDebugString(">>>>HIDMON.EXE: CloseChildWindow()Exit\n");
  124. }
  125. /***************************************************************************************************
  126. **
  127. ** HIDMDIChildWndProc.
  128. **
  129. ** DESCRIPTION: If cases are added for WM_CHILDACTIVATE, WM_GETMINMAXINFO,
  130. ** WM_MENUCHAR, WM_MOVE, WM_NEXTMENU, WM_SETFOCUS, WM_SIZE,
  131. ** or WM_SYSCOMMAND, these messages should be passed on
  132. ** to DefMDIChildProc even if we handle them. See the SDK
  133. ** Reference entry for DefMDIChildProc.
  134. **
  135. ** PARAMETERS:
  136. **
  137. ** RETURNS:
  138. **
  139. ***************************************************************************************************/
  140. #define IDT_READTIMER 1000
  141. LPARAM WINAPI HIDMDIChildWndProc(HWND hWnd, UINT Message, UINT uParam, LPARAM lParam)
  142. {
  143. PCHILD_INFO pChildInfo;
  144. switch(Message)
  145. {
  146. case WM_CREATE:
  147. {
  148. HWND hEdit;
  149. HFONT hfFixed;
  150. hEdit = CreateWindow("EDIT", 0, EDIT_WRAP, 0, 0, 0, 0, hWnd, NULL, GetModuleHandle(NULL), NULL);
  151. if(!hEdit)
  152. {
  153. MessageBox(hWnd,"ChildWindowProc(): CreateWindow(EDIT) fialed","Ooops!",MB_OK);
  154. return -1;
  155. }
  156. hfFixed = GetStockObject(DEFAULT_GUI_FONT );//ANSI_FIXED_FONT);
  157. SendMessage(hEdit,WM_SETFONT,(WPARAM)hfFixed,0L);
  158. SetEditWin(hWnd, hEdit);
  159. // TESTING!!!!!
  160. SetTimer(hWnd,IDT_TIMER,5,(TIMERPROC)ReadWatch);
  161. return 0;
  162. }
  163. case WM_COMMAND:
  164. switch(uParam)
  165. {
  166. case IDM_CHANNEL: return IOCTLChannelDesc(hWnd);
  167. case IDM_DEVICE: return IOCTLDeviceDesc(hWnd);
  168. case IDM_READ: return IOCTLRead(hWnd);
  169. case IDM_WRITE: return IOCTLWrite(hWnd);
  170. case IDM_STOP: return IOCTLStop(hWnd);
  171. default: return SUCCESS;
  172. }
  173. case WM_SIZE:
  174. return !MoveWindow(GetEditWin(hWnd), 0, 0, (INT) LOWORD(lParam), (INT) HIWORD(lParam), TRUE);
  175. case WM_RBUTTONUP:
  176. SetFocus(hWnd);
  177. return PopUpMenu(hInst, hWnd, hWnd, lParam, "CHILD_MENU");
  178. case WM_MDIDESTROY:
  179. case WM_DESTROY:
  180. OutputDebugString(">>>>HIDMON.EXE: ChildWndProc WM_DESTROY\n");
  181. //TESTING!!
  182. KillTimer(hWnd,IDT_TIMER);
  183. CloseChildWindow(hWnd);
  184. // Free all the stuff malloc'd for this window
  185. pChildInfo = (PCHILD_INFO) GetDeviceInfo(hWnd);
  186. free( pChildInfo->hidPPData);
  187. GlobalFree( pChildInfo->hidCaps);
  188. GlobalFree( pChildInfo->pValueCaps);
  189. GlobalFree( pChildInfo->pButtonCaps);
  190. GlobalFree( pChildInfo );
  191. return 0;
  192. default:
  193. return DefMDIChildProc (hWnd, Message, uParam, lParam);
  194. }
  195. return SUCCESS;
  196. }
  197. /***************************************************************************************************
  198. **
  199. ** CommandHandler.
  200. **
  201. ** DESCRIPTION:
  202. **
  203. ** PARAMETERS:
  204. **
  205. ** RETURNS:
  206. **
  207. ***************************************************************************************************/
  208. VOID CommandHandler(HWND hWnd, UINT uParam)
  209. {
  210. switch(uParam)
  211. {
  212. case IDM_FILEEXIT:
  213. // Close application
  214. SendMessage(hWnd, WM_CLOSE, 0, 0L);
  215. break;
  216. case IDM_FILEREENUM:
  217. CloseAllChildren();
  218. OpenClassObjects();
  219. break;
  220. case IDM_WINDOWTILE:
  221. // Tile MDI windows
  222. SendMessage(hWndMDIClient, WM_MDITILE, 0, 0L);
  223. break;
  224. case IDM_WINDOWCASCADE:
  225. // Cascade MDI windows
  226. SendMessage(hWndMDIClient, WM_MDICASCADE, 0, 0L);
  227. break;
  228. case IDM_WINDOWICONS:
  229. // Auto - arrange MDI icons
  230. SendMessage(hWndMDIClient, WM_MDIICONARRANGE, 0, 0L);
  231. break;
  232. case IDM_WINDOWCLOSEALL:
  233. CloseAllChildren();
  234. break;
  235. case IDM_DEVICECHANGE:
  236. SendMessage(hWnd,WM_DEVICECHANGE,DBT_DEVICEREMOVECOMPLETE,0);
  237. break;
  238. default:
  239. DefFrameProc(hWnd, hWndMDIClient, WM_COMMAND, uParam, 0L);
  240. }
  241. }
  242. /***************************************************************************************************
  243. **
  244. ** CloseAllChildern.
  245. **
  246. ** DESCRIPTION: Destroys all MDI child windows.
  247. **
  248. ** PARAMETERS:
  249. **
  250. ** RETURNS:
  251. **
  252. ***************************************************************************************************/
  253. VOID CloseAllChildren (VOID)
  254. {
  255. HWND hWnd;
  256. // As long as the MDI client has a child, destroy it
  257. while(hWnd = GetWindow (hWndMDIClient, GW_CHILD))
  258. {
  259. // Skip the icon title windows
  260. while(hWnd && GetWindow (hWnd, GW_OWNER))
  261. hWnd = GetWindow (hWnd, GW_HWNDNEXT);
  262. if(hWnd)
  263. SendMessage(hWndMDIClient, WM_MDIDESTROY, (WPARAM)hWnd, 0L);
  264. else
  265. break;
  266. }
  267. }
  268. /*****************************************************************************
  269. **
  270. **
  271. **
  272. **
  273. **
  274. **
  275. **
  276. **
  277. **
  278. *****************************************************************************/
  279. LRESULT PopUpMenu(HANDLE hInst, HWND hWnd, HWND hMWnd, LPARAM lPoint, LPSTR lpMenu)
  280. {
  281. POINT point;
  282. HMENU hMenu;
  283. HMENU hMenuTP;
  284. hMenu = LoadMenu(hInst, lpMenu);
  285. if(!hMenu) return FAILURE;
  286. point.x = LOWORD(lPoint);
  287. point.y = HIWORD(lPoint);
  288. hMenuTP = GetSubMenu(hMenu, 0);
  289. ClientToScreen(hWnd, (LPPOINT)&point);
  290. TrackPopupMenu(hMenuTP, 0, point.x, point.y, 0, hMWnd, NULL);
  291. DestroyMenu(hMenu);
  292. return SUCCESS;
  293. }
  294. /***************************************************************************************************
  295. **
  296. ** WinMain.
  297. **
  298. ** DESCRIPTION:
  299. **
  300. ** PARAMETERS:
  301. **
  302. ** RETURNS:
  303. **
  304. ***************************************************************************************************/
  305. INT PASCAL WinMain(HANDLE hInstance,
  306. HANDLE hPrevInstance,
  307. LPSTR szCommand,
  308. INT WindowState)
  309. {
  310. MSG Message;
  311. hInst = hInstance;
  312. // If this is the first instance of the app. register window classes
  313. if(!hPrevInstance)
  314. if(!InitializeApplication())
  315. return 0;
  316. // Create the frame and do other initialization
  317. if(!InitializeInstance(szCommand, WindowState))
  318. return 0;
  319. // Enter main message loop
  320. while(GetMessage(&Message, NULL, 0, 0))
  321. // If a keyboard message is for the MDI, let the MDI client
  322. // take care of it. Otherwise, just handle the message as usual
  323. if(!TranslateMDISysAccel(hWndMDIClient, &Message))
  324. {
  325. // Edit windows should get no mouse messages
  326. if(Message.message >= WM_MOUSEFIRST && Message.message <= WM_MOUSELAST)
  327. {
  328. if(Message.message == WM_RBUTTONUP)
  329. Message.hwnd = GetParent(Message.hwnd);
  330. else
  331. continue;
  332. }
  333. TranslateMessage(&Message);
  334. DispatchMessage(&Message);
  335. }
  336. return Message.lParam;
  337. }