Counter Strike : Global Offensive Source Code
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.

949 lines
26 KiB

  1. /* ------------------------------- mgrtest.c -------------------------------- */
  2. #include <windows.h>
  3. //#include <winuser.h>
  4. #include <string.h>
  5. #include <wintab.h>
  6. #include "mgrdlg.h"
  7. #include "resource.h"
  8. #include "msgpack.h"
  9. #include "mgrtest.h"
  10. HANDLE hInst;
  11. /* application globals */
  12. HMGR hMgr = NULL;
  13. UINT ObtCat;
  14. UINT ObtSize;
  15. BOOL *ObtBuf;
  16. HMENU hObtMenu = NULL;
  17. UINT NDevices;
  18. HMODULE hWintab = NULL;
  19. /* If the exe imports WTMgrDefContextEx(), then we won't be able to run with
  20. older Wintab.dll/Wintab32.dll's which are don't support Wintab Spec 1.1.
  21. Instead, we'll try to GetProcAddress it ourselves. On failure, just disable
  22. features that depend on it. */
  23. HCTX (API * pWTMgrDefContextEx)(HMGR, UINT, BOOL);
  24. extern BOOL FAR PASCAL ButtonDlgProc(HWND, UINT, WPARAM, LPARAM);
  25. void set_default_BtnMask( HWND hWnd, HMGR hMgr, int fSys ); /* BtnMask.c */
  26. void set_default_CsrMask( HWND hWnd, HMGR hMgr, int fSys ); /* Csrmask.c */
  27. void set_xBtnMap( HWND hWnd, HMGR hMgr ); /* btnMap.c */
  28. /*------------------------------------------------------------------------------
  29. encapsulate non-portable items:
  30. wintab string name
  31. LoadLibrary behavior
  32. Unicode/ANSI function name suffixes
  33. ------------------------------------------------------------------------------*/
  34. #ifdef WIN32
  35. /* no Unicode support yet. */
  36. #define CHARSET "A"
  37. char szWintab[] = "Wintab32";
  38. #define LoadLibraryWorked(h) (h)
  39. #else
  40. #define CHARSET
  41. char szWintab[] = "Wintab";
  42. #define LoadLibraryWorked(h) (h >= HINSTANCE_ERROR)
  43. #endif
  44. /* -------------------------------------------------------------------------- */
  45. /* portable wrappers for non-portable functions. */
  46. /* -------------------------------------------------------------------------- */
  47. BOOL ConfigReplace(HMGR h, BOOL f, LPSTR m, LPSTR p)
  48. {
  49. typedef BOOL (API *CRX)(HMGR, int, LPSTR, LPSTR);
  50. typedef BOOL (API *CR)(HMGR, int, WTCONFIGPROC);
  51. static CR cr = NULL;
  52. static CRX crx = NULL;
  53. /* if not got wintab handle... */
  54. if (!hWintab)
  55. /* get wintab handle. */
  56. hWintab = LoadLibrary(szWintab);
  57. /* failsafe. */
  58. if (!LoadLibraryWorked(hWintab))
  59. return FALSE;
  60. /* if not got a proc... */
  61. if (!crx && !cr) {
  62. /* try for portable version. */
  63. crx = (CRX)GetProcAddress(hWintab, "WTMgrConfigReplaceEx" CHARSET);
  64. /* if no portable version... */
  65. if (!crx)
  66. /* try for non-portable version. */
  67. cr = (CR)GetProcAddress(hWintab, "WTMgrConfigReplace");
  68. }
  69. /* failsafe. */
  70. if (!crx && !cr)
  71. return FALSE;
  72. /* if portable version... */
  73. if (crx) {
  74. /* call it. */
  75. return crx(h, f, m, p);
  76. }
  77. else {
  78. /* convert arguments to call non-portable version. */
  79. static HMODULE curh = NULL;
  80. /* if args and state legal for installing... */
  81. if (f && m && p && !curh) {
  82. /* try to get the library. */
  83. curh = LoadLibrary(m);
  84. /* if got library... */
  85. if (LoadLibraryWorked(curh)) {
  86. WTCONFIGPROC fp;
  87. /* try to get the proc. */
  88. fp = (WTCONFIGPROC)GetProcAddress(curh, p);
  89. /* if got the proc... */
  90. if (fp) {
  91. /* call the non-portable function to install. */
  92. f = cr(h, f, fp);
  93. /* if install failed... */
  94. if (!f) {
  95. /* free library and reset our state. */
  96. FreeLibrary(curh);
  97. curh = NULL;
  98. }
  99. return f;
  100. }
  101. else {
  102. /* no proc in the library -- free it and fail. */
  103. FreeLibrary(curh);
  104. return FALSE;
  105. }
  106. }
  107. else {
  108. /* couldn't load library -- fail. */
  109. return FALSE;
  110. }
  111. }
  112. else if (!f && curh) {
  113. /* args and state legal for removing -- try remove. */
  114. f = cr(h, f, NULL);
  115. /* if removal succeeded... */
  116. if (f) {
  117. /* free library and reset our state. */
  118. FreeLibrary(curh);
  119. curh = NULL;
  120. }
  121. return f;
  122. }
  123. else {
  124. /* args or state illegal. */
  125. return FALSE;
  126. }
  127. }
  128. }
  129. /* -------------------------------------------------------------------------- */
  130. /* -------------------------------------------------------------------------- */
  131. UINT ScanExts(UINT wTag)
  132. {
  133. UINT i;
  134. UINT wScanTag;
  135. /* scan for wTag's info category. */
  136. for (i = 0; WTInfo(WTI_EXTENSIONS + i, EXT_TAG, &wScanTag); i++) {
  137. if (wTag == wScanTag) {
  138. /* return category offset from WTI_EXTENSIONS. */
  139. return i;
  140. }
  141. }
  142. /* return error code. */
  143. return 0xFFFF;
  144. }
  145. /* -------------------------------------------------------------------------- */
  146. BOOL ObtInit(void)
  147. {
  148. ObtCat = ScanExts(WTX_OBT);
  149. if (ObtCat == 0xFFFF)
  150. return FALSE;
  151. ObtSize = WTInfo(WTI_EXTENSIONS + ObtCat, EXT_DEFAULT, NULL);
  152. if (ObtBuf = (BOOL *)LocalAlloc(LPTR, ObtSize)) {
  153. return TRUE;
  154. }
  155. return FALSE;
  156. }
  157. /* -------------------------------------------------------------------------- */
  158. BOOL ObtGet(UINT wDev)
  159. {
  160. WTInfo(WTI_EXTENSIONS + ObtCat, EXT_DEFAULT, ObtBuf);
  161. return ObtBuf[wDev];
  162. }
  163. /* -------------------------------------------------------------------------- */
  164. BOOL ObtSet(UINT wDev, BOOL fOn)
  165. {
  166. ObtBuf[wDev] = fOn;
  167. return WTMgrExt(hMgr, WTX_OBT, ObtBuf);
  168. }
  169. /* -------------------------------------------------------------------------- */
  170. /* -------------------------------------------------------------------------- */
  171. int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
  172. HANDLE hInstance;
  173. HANDLE hPrevInstance;
  174. LPSTR lpCmdLine;
  175. int nCmdShow;
  176. {
  177. MSG msg;
  178. if (!hPrevInstance)
  179. if (!InitApplication(hInstance))
  180. return (FALSE);
  181. /* Perform initializations that apply to a specific instance */
  182. if (!InitInstance(hInstance, nCmdShow))
  183. return (FALSE);
  184. /* Acquire and dispatch messages until a WM_QUIT message is received. */
  185. while (GetMessage(&msg, NULL, 0, 0)) {
  186. TranslateMessage(&msg);
  187. DispatchMessage(&msg);
  188. }
  189. return (msg.wParam);
  190. }
  191. /* -------------------------------------------------------------------------- */
  192. BOOL InitApplication(hInstance)
  193. HANDLE hInstance;
  194. {
  195. WNDCLASS wc;
  196. /* Fill in window class structure with parameters that describe the */
  197. /* main window. */
  198. wc.style = 0;
  199. wc.lpfnWndProc = MainWndProc;
  200. wc.cbClsExtra = 0;
  201. wc.cbWndExtra = 0;
  202. wc.hInstance = hInstance;
  203. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  204. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  205. wc.hbrBackground = (HBRUSH)(1 + COLOR_APPWORKSPACE);
  206. wc.lpszMenuName = "MgrTestMenu";
  207. wc.lpszClassName = "MgrTestWClass";
  208. /* Register the window class and return success/failure code. */
  209. return (RegisterClass(&wc));
  210. }
  211. /* -------------------------------------------------------------------------- */
  212. BOOL InitInstance(hInstance, nCmdShow)
  213. HANDLE hInstance;
  214. int nCmdShow;
  215. {
  216. HWND hWnd;
  217. HMENU hMenu, hCsrMenu;
  218. char *p;
  219. UINT size;
  220. int i;
  221. /* Save the instance handle in static variable, which will be used in */
  222. /* many subsequence calls from this application to Windows. */
  223. hInst = hInstance;
  224. /* check if WinTab available. */
  225. if (!WTInfo(0, 0, NULL)) {
  226. MessageBox(NULL, "WinTab Services Not Available.", "WinTab",
  227. MB_OK | MB_ICONHAND);
  228. return FALSE;
  229. }
  230. /* Create a main window for this application instance. */
  231. hWnd = CreateWindow(
  232. "MgrTestWClass",
  233. "MgrTest Sample Application",
  234. WS_OVERLAPPEDWINDOW,
  235. CW_USEDEFAULT,
  236. CW_USEDEFAULT,
  237. CW_USEDEFAULT,
  238. CW_USEDEFAULT,
  239. NULL,
  240. NULL,
  241. hInstance,
  242. NULL
  243. );
  244. /* If window could not be created, return "failure" */
  245. if (!hWnd) {
  246. if (!hMgr)
  247. MessageBox(NULL, "Can't get Manager Handle.", "MgrTest",
  248. MB_ICONHAND | MB_OK);
  249. return (FALSE);
  250. }
  251. /* get device count. */
  252. WTInfo(WTI_INTERFACE, IFC_NDEVICES, &NDevices);
  253. /* Tack on more menu items. */
  254. hMenu = GetSubMenu(GetMenu(hWnd), IDM_EDIT);
  255. hCsrMenu = CreatePopupMenu();
  256. AppendMenu(hMenu, MF_POPUP, (UINT)hCsrMenu, "&Active Cursors");
  257. for (i = 0; size = WTInfo(WTI_CURSORS + i, CSR_NAME, NULL); i++) {
  258. if (p = (char *)LocalAlloc(LPTR, 1 + size)) {
  259. BOOL fActive;
  260. p[0] = '&';
  261. WTInfo(WTI_CURSORS + i, CSR_NAME, p + 1);
  262. AppendMenu(hCsrMenu, 0, IDM_CURSORS + i, p);
  263. LocalFree((HLOCAL)p);
  264. WTInfo(WTI_CURSORS + i, CSR_ACTIVE, &fActive);
  265. CheckMenuItem(hCsrMenu, IDM_CURSORS + i,
  266. (fActive ? MF_CHECKED : MF_UNCHECKED));
  267. }
  268. }
  269. hObtMenu = NULL;
  270. if (ObtInit()) {
  271. if (NDevices > 1) {
  272. hObtMenu = CreatePopupMenu();
  273. ModifyMenu(hMenu, IDM_OBT, MF_POPUP, (UINT)hObtMenu,
  274. "&Out of Bounds Tracking");
  275. }
  276. else {
  277. CheckMenuItem(hMenu, IDM_OBT,
  278. (ObtGet(0) ? MF_CHECKED : MF_UNCHECKED));
  279. }
  280. }
  281. else {
  282. EnableMenuItem(hMenu, IDM_OBT, MF_GRAYED);
  283. }
  284. AppendMenu(hMenu, MF_SEPARATOR, 0, NULL);
  285. for (i = 0; size = WTInfo(WTI_DEVICES + i, DVC_NAME, NULL); i++) {
  286. static char suffix[] = " Settings...";
  287. if (p = (char *)LocalAlloc(LPTR, 1 + size + sizeof(suffix))) {
  288. p[0] = '&';
  289. WTInfo(WTI_DEVICES + i, DVC_NAME, p + 1);
  290. strtok(p, ";");
  291. if (hObtMenu)
  292. AppendMenu(hObtMenu, (ObtGet(i) ? MF_CHECKED : MF_UNCHECKED),
  293. IDM_OBTDEVS + i, p);
  294. strcat(p, suffix);
  295. AppendMenu(hMenu, 0, IDM_DEVICES + i, p);
  296. LocalFree((HLOCAL)p);
  297. }
  298. }
  299. /* Make the window visible; update its client area; and return "success" */
  300. ShowWindow(hWnd, nCmdShow);
  301. UpdateWindow(hWnd);
  302. return (TRUE);
  303. }
  304. /* -------------------------------------------------------------------------- */
  305. /* -------------------------------------------------------------------------- */
  306. /* statics for context list painting. */
  307. static int nLine = 0;
  308. static char buf[200];
  309. static SIZE szTextExtent = {0};
  310. static LOGCONTEXT lc;
  311. static char ownertext[40];
  312. static HCTX hCtxOrder[50];
  313. static int nCtxs = 0;
  314. /* -------------------------------------------------------------------------- */
  315. BOOL FAR PASCAL Do1Context(HCTX hCtx, LPARAM lParam)
  316. {
  317. HDC hDC = (HDC)lParam;
  318. char *p = buf;
  319. HWND hOwner;
  320. char status[30] = "";
  321. unsigned len;
  322. hCtxOrder[nLine] = hCtx;
  323. WTGet(hCtx, &lc);
  324. /* Decode status */
  325. if( lc.lcStatus & CXS_DISABLED )
  326. strcpy( status, "Disabled," );
  327. if( lc.lcStatus & CXS_OBSCURED )
  328. strcat( status, "Obscured," );
  329. if( lc.lcStatus & CXS_ONTOP )
  330. strcat( status, "On Top," );
  331. len = strlen( status );
  332. if( len ) /* Get rid of the last comma */
  333. status[len-1] = 0;
  334. hOwner = WTMgrContextOwner(hMgr, hCtx);
  335. GetWindowText(hOwner, ownertext, 40);
  336. TextOut(hDC, 0, nLine * szTextExtent.cy, status, len - 1); /* Display status information */
  337. _itoa( lc.lcDevice, status, 10 );
  338. TextOut(hDC, 17*szTextExtent.cx, nLine*szTextExtent.cy, status, strlen(status) );
  339. wsprintf(p, "%s:%s", (LPSTR)lc.lcName, (LPSTR)ownertext);
  340. TextOut(hDC, 19 * szTextExtent.cx, nLine++ * szTextExtent.cy, buf, strlen(buf)); /* Display context name */
  341. return TRUE;
  342. }
  343. /* -------------------------------------------------------------------------- */
  344. BOOL ListContexts(HDC hDC, PAINTSTRUCT *ps)
  345. {
  346. static char info[] = "To edit a context, click on it in the above list.";
  347. BOOL fResult;
  348. FARPROC fp;
  349. if (!szTextExtent.cx)
  350. GetTextExtentPoint(hDC, "M", 1, &szTextExtent);
  351. nLine = 0;
  352. SetTextColor(hDC, GetSysColor(COLOR_WINDOWTEXT));
  353. SetBkColor(hDC, GetSysColor(COLOR_APPWORKSPACE));
  354. fp = MakeProcInstance((FARPROC)Do1Context, hInst);
  355. fResult = WTMgrContextEnum(hMgr, (WTENUMPROC)fp, (LPARAM)hDC);
  356. FreeProcInstance(fp);
  357. nCtxs = nLine;
  358. TextOut(hDC, 0, (1 + nLine) * szTextExtent.cy, info, strlen(info));
  359. return fResult;
  360. }
  361. /* -------------------------------------------------------------------------- */
  362. HCTX ListPoint(int y)
  363. {
  364. int n = y / szTextExtent.cy;
  365. return ( n < nCtxs ? hCtxOrder[n] : NULL);
  366. }
  367. /* -------------------------------------------------------------------------- */
  368. BOOL QueryKillCtx(HWND hWnd, HCTX hCtx)
  369. {
  370. static char msg[] =
  371. "Closing this context may cause the owning application %s to crash."
  372. "Do you want to close it anyway?";
  373. HWND hOwner;
  374. hOwner = WTMgrContextOwner(hMgr, hCtx);
  375. if (IsWindow(hOwner)) {
  376. GetWindowText(hOwner, ownertext, 40);
  377. wsprintf(buf, msg, (LPSTR)ownertext);
  378. return (MessageBox(hWnd, buf, "MgrTest", MB_ICONSTOP|MB_OKCANCEL)==IDOK);
  379. }
  380. else
  381. return TRUE;
  382. }
  383. void set_default_device( HWND hWnd, int fSys )
  384. {
  385. int id;
  386. HCTX hCtx;
  387. FARPROC lpProcDlg;
  388. lpProcDlg = MakeProcInstance(CursInfoDlgProc, hInst);
  389. id = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_INFOLIST),
  390. hInst, lpProcDlg, WTI_DEVICES);
  391. FreeProcInstance(lpProcDlg);
  392. if( id >= 0 ) {
  393. LOGCONTEXT log;
  394. /* Change the default device
  395. (the device that is used by WTI_DEFCONTEXT, WTI_DEFSYSCTX and WTMgrDefContext) */
  396. hCtx = WTMgrDefContextEx(hMgr, id, fSys);
  397. if( !hCtx ) {
  398. MessageBox(hWnd, "WTMgrDefContextEx failed.", "MgrTest", MB_ICONHAND | MB_OK);
  399. return;
  400. }
  401. if( !WTGet( hCtx, &log ) ) {
  402. MessageBox(hWnd, "WTGet failed.", "MgrTest", MB_ICONHAND | MB_OK);
  403. return;
  404. }
  405. hCtx = WTMgrDefContext(hMgr,fSys);
  406. if( !WTSet( hCtx, &log ) ) {
  407. MessageBox(hWnd, "WTSet failed.", "MgrTest", MB_ICONHAND | MB_OK);
  408. return;
  409. }
  410. /* Test that an innocent WTSet won't inadvertently change defalt_device */
  411. if( id > 0 ) {
  412. log.lcDevice = 0;
  413. hCtx = WTOpen(hWnd, &log, 0);
  414. if( !hCtx ) {
  415. MessageBox(hWnd, "WTOpen failed.", "MgrTest", MB_ICONHAND | MB_OK);
  416. return;
  417. }
  418. if( !WTSet(hCtx, &log) )
  419. MessageBox(hWnd, "WTSet failed.", "MgrTest", MB_ICONHAND | MB_OK);
  420. if( !WTClose(hCtx) )
  421. MessageBox(hWnd, "WTClose failed.", "MgrTest", MB_ICONHAND | MB_OK);
  422. }
  423. /* Test that the change was actually made */
  424. hCtx = WTMgrDefContext(hMgr, fSys);
  425. if( !WTGet( hCtx, &log ) ) {
  426. MessageBox(hWnd, "WTGet failed.", "MgrTest", MB_ICONHAND | MB_OK);
  427. return;
  428. }
  429. if( (int)log.lcDevice == id )
  430. MessageBox(hWnd, "Default device changed.", "MgrTest", MB_ICONINFORMATION | MB_OK);
  431. else
  432. MessageBox(hWnd, "Default device not changed properly.", "MgrTest", MB_ICONHAND | MB_OK);
  433. }
  434. }
  435. /* -------------------------------------------------------------------------- */
  436. /* -------------------------------------------------------------------------- */
  437. BOOL
  438. CALLBACK ctx_edit_DlgProc( HWND hDlg, UINT Msg, WPARAM wParam, LONG lParam )
  439. {
  440. BOOL fResult;
  441. switch( Msg ) {
  442. case WM_COMMAND:
  443. EndDialog(hDlg, wParam);
  444. fResult = TRUE;
  445. break;
  446. default:
  447. fResult = FALSE;
  448. }
  449. return fResult;
  450. }
  451. /* -------------------------------------------------------------------------- */
  452. /* -------------------------------------------------------------------------- */
  453. /* If we can't link WTMgrDefContextEx(), use this instead */
  454. HCTX API autofail(HMGR a, UINT b, BOOL c)
  455. {
  456. return 0;
  457. }
  458. /* -------------------------------------------------------------------------- */
  459. LRESULT FAR PASCAL MainWndProc(hWnd, message, wParam, lParam)
  460. HWND hWnd;
  461. unsigned message;
  462. WPARAM wParam;
  463. LPARAM lParam;
  464. {
  465. HCTX hCtx;
  466. FARPROC lpProcDlg;
  467. LRESULT lResult = 0;
  468. static BOOL fCBRTest = FALSE;
  469. BOOL fEnable;
  470. HMENU hMenu;
  471. int i;
  472. WORD id,specver;
  473. HMODULE hModule;
  474. switch (message) {
  475. case WM_CREATE:
  476. hMgr = WTMgrOpen(hWnd, WT_DEFBASE);
  477. if( !hMgr )
  478. MessageBox(hWnd, "WTMgrOpen failed.", "MgrTest", MB_ICONHAND | MB_OK);
  479. lResult = !!hMgr - 1;
  480. /* Try to link WTMgrDefContextEx() */
  481. hModule = GetModuleHandle(
  482. #ifdef _WIN32
  483. "wintab32.dll"
  484. #else
  485. "wintab.dll"
  486. #endif
  487. );
  488. (FARPROC)pWTMgrDefContextEx = GetProcAddress( hModule, "WTMgrDefContextEx" );
  489. if( !pWTMgrDefContextEx ) {
  490. /* Disable features which depend on WTMgrDefContextEx */
  491. pWTMgrDefContextEx = autofail;
  492. EnableWindow( GetDlgItem(hWnd, IDM_DEFDEV_DIG), FALSE );
  493. EnableWindow( GetDlgItem(hWnd, IDM_DEFDEV_SYS), FALSE );
  494. }
  495. break;
  496. case WT_CTXOPEN:
  497. case WT_CTXCLOSE:
  498. case WT_CTXUPDATE:
  499. case WT_CTXOVERLAP:
  500. case WT_PROXIMITY:
  501. InvalidateRect(hWnd, NULL, TRUE);
  502. UpdateWindow(hWnd);
  503. break;
  504. case WT_INFOCHANGE:
  505. FlashWindow(hWnd, TRUE);
  506. hMenu = GetSubMenu(GetSubMenu(GetMenu(hWnd),IDM_EDIT), IDM_CSRMENU);
  507. if (hMenu) {
  508. for (i = 0; WTInfo(WTI_CURSORS+i, CSR_ACTIVE, &fEnable); i++) {
  509. CheckMenuItem(hMenu, IDM_CURSORS + i,
  510. (fEnable ? MF_CHECKED : MF_UNCHECKED));
  511. }
  512. }
  513. FlashWindow(hWnd, FALSE);
  514. InvalidateRect(hWnd, NULL, TRUE);
  515. UpdateWindow(hWnd);
  516. break;
  517. case WM_LBUTTONDOWN:
  518. hCtx = ListPoint(HIWORD(lParam));
  519. if( hCtx ) {
  520. LOGCONTEXT lc;
  521. lpProcDlg = MakeProcInstance(ctx_edit_DlgProc, hInst);
  522. id = DialogBox(hInst, MAKEINTRESOURCE(IDD_CTXEDIT), hWnd, lpProcDlg);
  523. FreeProcInstance(lpProcDlg);
  524. switch( id ) {
  525. case IDC_WTCONFIG:
  526. WTConfig(hCtx, hWnd);
  527. break;
  528. case IDC_BUTTONS:
  529. WTGet(hCtx, &lc);
  530. set_ctx_BtnMask(hWnd, hCtx, &lc);
  531. break;
  532. case IDC_MOVEMASK:
  533. set_ctx_MoveMask(hWnd, hMgr, hCtx);
  534. break;
  535. }
  536. }
  537. break;
  538. case WM_RBUTTONDOWN:
  539. hCtx = ListPoint(HIWORD(lParam));
  540. if (QueryKillCtx(hWnd, hCtx)) {
  541. WTClose(hCtx);
  542. }
  543. break;
  544. case WM_PAINT:
  545. if (hMgr) {
  546. HDC hDC;
  547. PAINTSTRUCT ps;
  548. hDC = BeginPaint(hWnd, &ps);
  549. ListContexts(hDC, &ps);
  550. EndPaint(hWnd, &ps);
  551. }
  552. break;
  553. case WM_COMMAND:
  554. id = GET_WM_COMMAND_ID(wParam, lParam);
  555. if (id >= IDM_DEVICES &&
  556. WTInfo(WTI_DEVICES + id - IDM_DEVICES, DVC_NAME, NULL))
  557. {
  558. WTMgrDeviceConfig(hMgr, id - IDM_DEVICES, hWnd);
  559. }
  560. if (id >= IDM_CURSORS &&
  561. WTInfo(WTI_CURSORS+id-IDM_CURSORS, CSR_ACTIVE, &fEnable))
  562. {
  563. fEnable ^= WTMgrCsrEnable(hMgr, id - IDM_CURSORS, !fEnable);
  564. hMenu = GetSubMenu(GetSubMenu(GetMenu(hWnd), IDM_EDIT),
  565. IDM_CSRMENU);
  566. CheckMenuItem(hMenu, id,
  567. (fEnable ? MF_CHECKED : MF_UNCHECKED));
  568. }
  569. if (id >= IDM_OBTDEVS &&
  570. id < (WORD)(IDM_OBTDEVS + NDevices)) {
  571. /* one of multiple devices. */
  572. ObtSet(id - IDM_OBTDEVS, !ObtGet(id - IDM_OBTDEVS));
  573. CheckMenuItem(hObtMenu, id,
  574. (ObtGet(0) ? MF_CHECKED : MF_UNCHECKED));
  575. }
  576. switch (id)
  577. {
  578. case IDM_ABOUT:
  579. lpProcDlg = MakeProcInstance(About, hInst);
  580. DialogBox(hInst, "AboutBox", hWnd, lpProcDlg);
  581. FreeProcInstance(lpProcDlg);
  582. break;
  583. case IDM_BUTTMAPS:
  584. lpProcDlg = MakeProcInstance(ButtonDlgProc, hInst);
  585. DialogBox(hInst, MAKEINTRESOURCE(IDD_BUTTONS),
  586. hWnd, lpProcDlg);
  587. FreeProcInstance(lpProcDlg);
  588. break;
  589. case IDM_XBUTTMAPS:
  590. set_xBtnMap( hWnd, hMgr );
  591. break;
  592. case IDM_OBT:
  593. /* only one device present. */
  594. ObtSet(0, !ObtGet(0));
  595. hMenu = GetSubMenu(GetMenu(hWnd), IDM_EDIT);
  596. CheckMenuItem(hMenu, id,
  597. (ObtGet(0) ? MF_CHECKED : MF_UNCHECKED));
  598. break;
  599. case IDM_DEFDIG:
  600. /* Open a dialog to choose which device to use, if nessicary */
  601. lpProcDlg = MakeProcInstance(CursInfoDlgProc, hInst);
  602. id = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_INFOLIST),
  603. hWnd, lpProcDlg, WTI_DDCTXS);
  604. FreeProcInstance(lpProcDlg);
  605. /* Open the Wintab context config dialog */
  606. if (id >= 0) {
  607. int numDevices;
  608. WTInfo(WTI_INTERFACE, IFC_NDEVICES, &numDevices);
  609. if( id < numDevices ) {
  610. hCtx = WTMgrDefContextEx(hMgr, id, 0);
  611. if( !hCtx )
  612. hCtx = WTMgrDefContext(hMgr, 0);
  613. } else
  614. hCtx = WTMgrDefContext(hMgr, 0);
  615. if( hCtx )
  616. WTConfig(hCtx, hWnd);
  617. else
  618. MessageBox(hWnd, "WTMgrDefContext failed.", "MgrTest",
  619. MB_ICONHAND | MB_OK);
  620. }
  621. break;
  622. case IDM_DEFSYS:
  623. /* Open a dialog to choose which device to use, if nessicary */
  624. lpProcDlg = MakeProcInstance(CursInfoDlgProc, hInst);
  625. id = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_INFOLIST),
  626. hInst, lpProcDlg, WTI_DSCTXS);
  627. FreeProcInstance(lpProcDlg);
  628. /* Open the Wintab context dialog */
  629. if (id >= 0) {
  630. int numDevices;
  631. WTInfo(WTI_INTERFACE, IFC_NDEVICES, &numDevices);
  632. if( id < numDevices ) {
  633. hCtx = WTMgrDefContextEx(hMgr, id, 1);
  634. if( !hCtx )
  635. hCtx = WTMgrDefContext(hMgr, 1);
  636. } else
  637. hCtx = WTMgrDefContext(hMgr, 1);
  638. /* 'Default Device' was the last choice in the dialog */
  639. if( hCtx )
  640. WTConfig(hCtx, hWnd);
  641. else
  642. MessageBox(hWnd, "WTMgrDefContext failed.", "MgrTest",
  643. MB_ICONHAND | MB_OK);
  644. }
  645. break;
  646. case IDM_RESET_DEFDIG:
  647. //Check for version 1.1
  648. WTInfo(WTI_INTERFACE,IFC_SPECVERSION,&specver);
  649. if( ( HIBYTE(specver)>=1) && ( LOBYTE(specver)>=1)){
  650. lpProcDlg = MakeProcInstance(CursInfoDlgProc, hInst);
  651. id = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_INFOLIST),
  652. hInst, lpProcDlg, WTI_DDCTXS);
  653. FreeProcInstance(lpProcDlg);
  654. if (id >= 0) {
  655. int numDevices;
  656. WTInfo(WTI_INTERFACE, IFC_NDEVICES, &numDevices);
  657. if( id < numDevices ) {
  658. hCtx = WTMgrDefContextEx(hMgr, id, 0);
  659. if( !hCtx )
  660. hCtx = WTMgrDefContext(hMgr, 0);
  661. } else
  662. hCtx = WTMgrDefContext(hMgr, 0);
  663. if( hCtx ) {
  664. if( WTSet(hCtx, 0) )
  665. MessageBox(hWnd, "Error! WTSet(hCtx, 0)"
  666. "returned success.", "MgrTest",
  667. MB_ICONHAND | MB_OK);
  668. if( !WTSet(hCtx, WTP_LPDEFAULT) )
  669. MessageBox(hWnd, "WTSet failed.", "MgrTest",
  670. MB_ICONHAND | MB_OK);
  671. else
  672. MessageBox(hWnd, "WTSet succeeded.", "MgrTest",
  673. MB_OK | MB_ICONINFORMATION);
  674. }else
  675. MessageBox(hWnd, "WTMgrDefContext failed.", "MgrTest",
  676. MB_ICONHAND | MB_OK);
  677. }
  678. }else
  679. MessageBox(hWnd, "This feature is only supported in "
  680. "devices using Wintab specification 1.1 and later.",
  681. "MgrTest", MB_ICONHAND | MB_OK);
  682. break;
  683. case IDM_RESET_DEFSYS:
  684. //Check for version 1.1
  685. WTInfo(WTI_INTERFACE,IFC_SPECVERSION,&specver);
  686. if( ( HIBYTE(specver)>=1) && ( LOBYTE(specver)>=1)){
  687. lpProcDlg = MakeProcInstance(CursInfoDlgProc, hInst);
  688. id = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_INFOLIST),
  689. hInst, lpProcDlg, WTI_DSCTXS);
  690. FreeProcInstance(lpProcDlg);
  691. if (id >= 0) {
  692. int numDevices;
  693. WTInfo(WTI_INTERFACE, IFC_NDEVICES, &numDevices);
  694. if( id < numDevices ) {
  695. hCtx = WTMgrDefContextEx(hMgr, id, 1);
  696. if( !hCtx )
  697. hCtx = WTMgrDefContext(hMgr, 1);
  698. } else
  699. hCtx = WTMgrDefContext(hMgr, 1);
  700. if( hCtx ) {
  701. if( WTSet(hCtx, 0) )
  702. MessageBox(hWnd, "Error! WTSet(hCtx, 0) "
  703. "returned success.", "MgrTest", MB_ICONHAND | MB_OK);
  704. if( !WTSet(hCtx, WTP_LPDEFAULT) )
  705. MessageBox(hWnd, "WTSet failed.", "MgrTest",
  706. MB_ICONHAND | MB_OK);
  707. else
  708. MessageBox(hWnd, "WTSet succeeded.", "MgrTest",
  709. MB_OK | MB_ICONINFORMATION);
  710. } else
  711. MessageBox(hWnd, "WTMgrDefContext failed.", "MgrTest",
  712. MB_ICONHAND | MB_OK);
  713. }
  714. }else
  715. MessageBox(hWnd, "This feature is only supported in "
  716. "devices using Wintab specification 1.1 and later.",
  717. "MgrTest", MB_ICONHAND | MB_OK);
  718. break;
  719. case IDM_DEFDEV_DIG:
  720. //Check for version 1.1
  721. WTInfo(WTI_INTERFACE,IFC_SPECVERSION,&specver);
  722. if( ( HIBYTE(specver)>=1) && ( LOBYTE(specver)>=1)){
  723. set_default_device( hWnd, 0 );
  724. }else{
  725. MessageBox(hWnd, "This feature is only supported in "
  726. "devices using Wintab specification 1.1 and later.",
  727. "MgrTest", MB_ICONHAND | MB_OK);
  728. }
  729. break;
  730. case IDM_DEFDEV_SYS:
  731. //Check for version 1.1
  732. WTInfo(WTI_INTERFACE,IFC_SPECVERSION,&specver);
  733. if( ( HIBYTE(specver)>=1) && ( LOBYTE(specver)>=1)){
  734. set_default_device( hWnd, 1 );
  735. }else{
  736. MessageBox(hWnd, "This feature is only supported in "
  737. "devices using Wintab specification 1.1 and later.",
  738. "MgrTest", MB_ICONHAND | MB_OK);
  739. }
  740. break;
  741. case IDM_CSRMASK_DIG:
  742. set_default_CsrMask( hWnd, hMgr, 0 );
  743. break;
  744. case IDM_CSRMASK_SYS:
  745. set_default_CsrMask( hWnd, hMgr, 1 );
  746. break;
  747. case IDM_XBTN_DIG:
  748. set_default_BtnMask( hWnd, hMgr, 0 );
  749. break;
  750. case IDM_XBTN_SYS:
  751. set_default_BtnMask( hWnd, hMgr, 1 );
  752. break;
  753. case IDM_CBRTEST:
  754. if (ConfigReplace(hMgr, !fCBRTest,
  755. "MgrDLL.DLL", "CBRTestProc")) {
  756. fCBRTest = !fCBRTest;
  757. }
  758. CheckMenuItem(GetSubMenu(GetMenu(hWnd), IDM_TEST),
  759. IDM_CBRTEST, (fCBRTest ? MF_CHECKED : MF_UNCHECKED));
  760. break;
  761. case IDM_BMSTEST:
  762. BMSTest(hWnd);
  763. break;
  764. case IDM_PMSTEST:
  765. PMSTest(hWnd);
  766. break;
  767. case IDM_PRSTEST:
  768. PRSTest(hWnd);
  769. break;
  770. case IDM_HMGRTEST:
  771. HMGRTest(hWnd);
  772. break;
  773. default:
  774. return (DefWindowProc(hWnd, message, wParam, lParam));
  775. }
  776. break;
  777. case WM_DESTROY:
  778. if (fCBRTest) {
  779. ConfigReplace(hMgr, FALSE, NULL, NULL);
  780. }
  781. if (hMgr)
  782. WTMgrClose(hMgr);
  783. if (LoadLibraryWorked(hWintab))
  784. FreeLibrary(hWintab);
  785. PostQuitMessage(0);
  786. break;
  787. default:
  788. return (DefWindowProc(hWnd, message, wParam, lParam));
  789. }
  790. return lResult;
  791. }
  792. /* -------------------------------------------------------------------------- */
  793. BOOL FAR PASCAL About(hDlg, message, wParam, lParam)
  794. HWND hDlg;
  795. unsigned message;
  796. WPARAM wParam;
  797. LPARAM lParam;
  798. {
  799. switch (message) {
  800. case WM_INITDIALOG:
  801. return (TRUE);
  802. case WM_COMMAND:
  803. if (GET_WM_COMMAND_ID(wParam, lParam) == IDOK
  804. || GET_WM_COMMAND_ID(wParam, lParam) == IDCANCEL) {
  805. EndDialog(hDlg, TRUE);
  806. return (TRUE);
  807. }
  808. break;
  809. }
  810. return (FALSE);
  811. }
  812. /* -------------------------------------------------------------------------- */