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.

365 lines
10 KiB

  1. /*
  2. * POSCPL.C
  3. *
  4. * Point-of-Sale Control Panel Applet
  5. *
  6. * Author: Ervin Peretz
  7. *
  8. * (c) 2001 Microsoft Corporation
  9. */
  10. #include <windows.h>
  11. #include <windowsx.h>
  12. #include <commctrl.h>
  13. #include <cpl.h>
  14. #include <setupapi.h>
  15. #include <hidsdi.h>
  16. #include "internal.h"
  17. #include "res.h"
  18. #include "debug.h"
  19. HANDLE g_hInst = NULL;
  20. BOOL WINAPI LibMain(HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
  21. {
  22. switch (dwReason){
  23. case DLL_PROCESS_ATTACH:
  24. g_hInst = hDll;
  25. DisableThreadLibraryCalls(hDll);
  26. InitializeListHead(&allPOSDevicesList);
  27. break;
  28. case DLL_PROCESS_DETACH:
  29. case DLL_THREAD_DETACH:
  30. case DLL_THREAD_ATTACH:
  31. default:
  32. break;
  33. }
  34. return TRUE;
  35. }
  36. LONG CPlApplet(HWND hwndCPl, UINT uMsg, LPARAM lParam1, LPARAM lParam2)
  37. {
  38. LONG result = 0L;
  39. switch (uMsg){
  40. case CPL_INIT:
  41. result = 1;
  42. break;
  43. case CPL_GETCOUNT:
  44. result = 1;
  45. break;
  46. case CPL_INQUIRE:
  47. {
  48. LPCPLINFO pcplinfo = (LPCPLINFO)lParam2;
  49. switch (lParam1){
  50. case 0:
  51. pcplinfo->idIcon = IDI_POSCPL_ICON;
  52. pcplinfo->idName = IDS_CAPTION;
  53. pcplinfo->idInfo = IDS_DESCRIPTION;
  54. break;
  55. case 1: // BUGBUG
  56. pcplinfo->idIcon = IDI_POSCPL_ICON;
  57. pcplinfo->idName = IDS_CAPTION;
  58. pcplinfo->idInfo = IDS_DESCRIPTION;
  59. break;
  60. }
  61. pcplinfo->lData = 0L;
  62. }
  63. result = 1;
  64. break;
  65. case CPL_SELECT:
  66. result = 0; // BUGBUG ?
  67. break;
  68. case CPL_DBLCLK:
  69. /*
  70. * The CPL was selected by the user.
  71. * Show our main dialog.
  72. */
  73. switch (lParam1){
  74. case 0:
  75. OpenAllHIDPOSDevices();
  76. LaunchPOSDialog(hwndCPl);
  77. break;
  78. }
  79. break;
  80. case CPL_STOP:
  81. result = 1; // BUGBUG ?
  82. break;
  83. case CPL_EXIT:
  84. result = 1;
  85. break;
  86. case CPL_NEWINQUIRE:
  87. {
  88. LPNEWCPLINFO pnewcplinfo = (LPNEWCPLINFO)lParam2;
  89. switch (lParam1){
  90. case 0:
  91. pnewcplinfo->hIcon = LoadIcon(g_hInst, MAKEINTRESOURCE(IDI_POSCPL_ICON));
  92. // BUGBUG LoadString(g_hInst, IDS_xxx, pnewcplinfo->szName, sizeof(pnewcplinfo->szName));
  93. // BUGBUG LoadString(g_hInst, IDS_xxx, pnewcplinfo->szInfo, sizeof(pnewcplinfo->szInfo));
  94. break;
  95. }
  96. pnewcplinfo->dwHelpContext = 0;
  97. pnewcplinfo->dwSize = sizeof(NEWCPLINFO);
  98. pnewcplinfo->lData = 0L;
  99. pnewcplinfo->szHelpFile[0] = 0;
  100. }
  101. result = 1;
  102. break;
  103. default:
  104. result = 0;
  105. break;
  106. }
  107. return result;
  108. }
  109. VOID LaunchPOSDialog(HWND hwndCPl)
  110. {
  111. PROPSHEETPAGE *propSheetPages;
  112. ULONG numPropSheetPages;
  113. /*
  114. * Make sure we allocate at least one propsheetpage,
  115. * even if there are no devices.
  116. */
  117. numPropSheetPages = (numDeviceInstances == 0) ? 1 : numDeviceInstances;
  118. propSheetPages = GlobalAlloc( GMEM_FIXED|GMEM_ZEROINIT,
  119. numPropSheetPages*sizeof(PROPSHEETPAGE));
  120. if (propSheetPages){
  121. PROPSHEETHEADER propSheetHeader = {0};
  122. if (numDeviceInstances == 0){
  123. /*
  124. * If there are no POS devices,
  125. * then put up a single tab saying so.
  126. */
  127. propSheetPages[0].dwSize = sizeof(PROPSHEETPAGE);
  128. propSheetPages[0].dwFlags = PSP_DEFAULT;
  129. propSheetPages[0].hInstance = g_hInst;
  130. propSheetPages[0].pszTemplate = MAKEINTRESOURCE(IDD_NO_DEVICES_DLG);
  131. propSheetPages[0].pszIcon = NULL; // PSP_USEICONID not set in dwFlags
  132. propSheetPages[0].pszTitle = MAKEINTRESOURCE("BUGBUG"); // PSP_USETITLE not set in dwFlags
  133. propSheetPages[0].pfnDlgProc = NullPOSDlgProc;
  134. propSheetPages[0].lParam = (LPARAM)NULL;
  135. propSheetPages[0].pfnCallback = NULL;
  136. propSheetPages[0].pcRefParent = NULL;
  137. }
  138. else {
  139. LIST_ENTRY *listEntry;
  140. ULONG i;
  141. /*
  142. * Create the array of property sheet handles
  143. */
  144. i = 0;
  145. listEntry = &allPOSDevicesList;
  146. while ((listEntry = listEntry->Flink) != &allPOSDevicesList){
  147. posDevice *posDev;
  148. posDev = CONTAINING_RECORD(listEntry, posDevice, listEntry);
  149. ASSERT(i < numDeviceInstances);
  150. propSheetPages[i].dwSize = sizeof(PROPSHEETPAGE);
  151. propSheetPages[i].dwFlags = PSP_DEFAULT;
  152. propSheetPages[i].hInstance = g_hInst;
  153. propSheetPages[i].pszTemplate = MAKEINTRESOURCE(posDev->dialogId);
  154. propSheetPages[i].pszIcon = NULL; // PSP_USEICONID not set in dwFlags
  155. propSheetPages[i].pszTitle = MAKEINTRESOURCE("BUGBUG"); // PSP_USETITLE not set in dwFlags
  156. propSheetPages[i].pfnDlgProc = POSDlgProc;
  157. propSheetPages[i].lParam = (LPARAM)posDev; // BUGBUG ? - context ?
  158. propSheetPages[i].pfnCallback = NULL;
  159. propSheetPages[i].pcRefParent = NULL;
  160. i++;
  161. }
  162. }
  163. /*
  164. * Initialize the property sheet header
  165. */
  166. propSheetHeader.dwSize = sizeof(PROPSHEETHEADER);
  167. propSheetHeader.dwFlags = PSH_PROPTITLE | PSH_PROPSHEETPAGE;
  168. propSheetHeader.hwndParent = hwndCPl;
  169. propSheetHeader.hInstance = g_hInst;
  170. propSheetHeader.pszIcon = NULL;
  171. propSheetHeader.pszCaption = MAKEINTRESOURCE(IDS_DIALOG_TITLE);
  172. propSheetHeader.ppsp = propSheetPages;
  173. propSheetHeader.nPages = numPropSheetPages;
  174. /*
  175. * Launch the property sheet tabbed dialog
  176. */
  177. PropertySheet(&propSheetHeader);
  178. GlobalFree(propSheetPages);
  179. }
  180. else {
  181. ASSERT(propSheetPages);
  182. }
  183. }
  184. INT_PTR APIENTRY POSDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  185. {
  186. BOOL result = TRUE;
  187. switch (uMsg){
  188. case WM_INITDIALOG:
  189. {
  190. /*
  191. * On the WM_INITDIALOG only, lParam points to
  192. * our propSheetPage, which contains our posDevice
  193. * context (in the 'lParam' field). This is our
  194. * only chance to associate the posDevice context
  195. * with the actual dialog for future calls.
  196. */
  197. PROPSHEETPAGE *propSheetPage = (PROPSHEETPAGE *)lParam;
  198. posDevice *posDev = (posDevice *)propSheetPage->lParam;
  199. ASSERT(posDev->sig == POSCPL_SIG);
  200. posDev->hDlg = hDlg;
  201. LaunchDeviceInstanceThread(posDev);
  202. }
  203. break;
  204. case WM_NOTIFY:
  205. switch (((NMHDR FAR*)lParam)->code){
  206. case PSN_APPLY:
  207. SetWindowLongPtr (hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
  208. break;
  209. default:
  210. result = FALSE;
  211. break;
  212. }
  213. break;
  214. case WM_COMMAND:
  215. switch (LOWORD(wParam)){
  216. case IDC_SELECT_DEVICETYPE:
  217. break;
  218. case IDC_CASHDRAWER_STATE:
  219. break;
  220. case IDC_CASHDRAWER_STATETEXT:
  221. break;
  222. case IDC_CASHDRAWER_OPEN:
  223. {
  224. posDevice *posDev;
  225. posDev = GetDeviceByHDlg(hDlg);
  226. if (posDev){
  227. SetCashDrawerState(posDev, DRAWER_STATE_OPEN);
  228. }
  229. else {
  230. DBGERR(L"GetDeviceByHDlg failed", 0);
  231. }
  232. }
  233. break;
  234. case IDC_MSR_TEXT:
  235. break;
  236. case IDC_STATIC1:
  237. case IDC_STATIC2:
  238. break;
  239. }
  240. break;
  241. case WM_DESTROY:
  242. {
  243. LIST_ENTRY *listEntry = &allPOSDevicesList;
  244. while ((listEntry = listEntry->Flink) != &allPOSDevicesList){
  245. posDevice *posDev = CONTAINING_RECORD(listEntry, posDevice, listEntry);
  246. if (posDev->hThread){
  247. #if 0
  248. // BUGBUG FINISH - kill the thread
  249. WaitForSingleObject(posDev->hThread, INFINITE);
  250. CloseHandle(posDev->hThread);
  251. #endif
  252. }
  253. }
  254. }
  255. break;
  256. case WM_HELP:
  257. break;
  258. case WM_CONTEXTMENU:
  259. break;
  260. default:
  261. result = FALSE;
  262. break;
  263. }
  264. return (INT_PTR)result;
  265. }
  266. /*
  267. * NullPOSDlgProc
  268. *
  269. * This is the dialog proc when we have no POS devices to display.
  270. */
  271. INT_PTR APIENTRY NullPOSDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  272. {
  273. BOOL result = TRUE;
  274. switch (uMsg){
  275. case WM_NOTIFY:
  276. switch (((NMHDR FAR*)lParam)->code){
  277. case PSN_APPLY:
  278. SetWindowLongPtr (hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
  279. break;
  280. default:
  281. result = FALSE;
  282. break;
  283. }
  284. break;
  285. default:
  286. result = FALSE;
  287. break;
  288. }
  289. return (INT_PTR)result;
  290. }