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.

278 lines
7.5 KiB

  1. /*------------------------------------------------------------------------------
  2. FKeys - using fkey input.
  3. RICO 4/29/93
  4. ------------------------------------------------------------------------------*/
  5. #include <windows.h>
  6. #include "msgpack.h"
  7. #include <wintab.h>
  8. #define PACKETDATA 0
  9. #define PACKETMODE 0
  10. #define PACKETFKEYS PKEXT_ABSOLUTE
  11. #include <pktdef.h>
  12. #include "fkeys.h"
  13. HANDLE hInst;
  14. WTPKT FKeysMask;
  15. UINT FKeysCat;
  16. /* -------------------------------------------------------------------------- */
  17. int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
  18. HANDLE hInstance;
  19. HANDLE hPrevInstance;
  20. LPSTR lpCmdLine;
  21. int nCmdShow;
  22. {
  23. MSG msg;
  24. if (!hPrevInstance)
  25. if (!InitApplication(hInstance))
  26. return (FALSE);
  27. /* Perform initializations that apply to a specific instance */
  28. if (!InitInstance(hInstance, nCmdShow))
  29. return (FALSE);
  30. /* Acquire and dispatch messages until a WM_QUIT message is received. */
  31. while (GetMessage(&msg,
  32. NULL,
  33. 0,
  34. 0))
  35. {
  36. TranslateMessage(&msg);
  37. DispatchMessage(&msg);
  38. }
  39. return (msg.wParam);
  40. }
  41. /* -------------------------------------------------------------------------- */
  42. BOOL InitApplication(hInstance)
  43. HANDLE hInstance;
  44. {
  45. WNDCLASS wc;
  46. /* Fill in window class structure with parameters that describe the */
  47. /* main window. */
  48. wc.style = 0;
  49. wc.lpfnWndProc = MainWndProc;
  50. wc.cbClsExtra = 0;
  51. wc.cbWndExtra = 0;
  52. wc.hInstance = hInstance;
  53. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  54. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  55. wc.hbrBackground = GetStockObject(WHITE_BRUSH);
  56. wc.lpszMenuName = "FKeysMenu";
  57. wc.lpszClassName = "FKeysWClass";
  58. /* Register the window class and return success/failure code. */
  59. return (RegisterClass(&wc));
  60. }
  61. /* -------------------------------------------------------------------------- */
  62. UINT ScanExts(UINT wTag)
  63. {
  64. UINT i;
  65. UINT wScanTag;
  66. /* scan for wTag's info category. */
  67. for (i = 0; WTInfo(WTI_EXTENSIONS + i, EXT_TAG, &wScanTag); i++) {
  68. if (wTag == wScanTag) {
  69. /* return category offset from WTI_EXTENSIONS. */
  70. return i;
  71. }
  72. }
  73. /* return error code. */
  74. return 0xFFFF;
  75. }
  76. /* -------------------------------------------------------------------------- */
  77. BOOL FKeysInit(void)
  78. {
  79. FKeysCat = ScanExts(WTX_FKEYS);
  80. if (FKeysCat != 0xFFFF) {
  81. WTInfo(WTI_EXTENSIONS + FKeysCat, EXT_MASK, &FKeysMask);
  82. return TRUE;
  83. }
  84. return FALSE;
  85. }
  86. /* -------------------------------------------------------------------------- */
  87. BOOL InitInstance(hInstance, nCmdShow)
  88. HANDLE hInstance;
  89. int nCmdShow;
  90. {
  91. HWND hWnd;
  92. char buf[50];
  93. /* Save the instance handle in static variable, which will be used in */
  94. /* many subsequence calls from this application to Windows. */
  95. hInst = hInstance;
  96. /* check if WinTab available. */
  97. if (!WTInfo(0, 0, NULL)) {
  98. MessageBox(NULL, "WinTab Services Not Available.", "WinTab",
  99. MB_OK | MB_ICONHAND);
  100. return FALSE;
  101. }
  102. /* check if WinTab FKeys Extension available. */
  103. if (!FKeysInit()) {
  104. MessageBox(NULL, "WinTab Function Keys Extension Not Available.",
  105. "WinTab", MB_OK | MB_ICONHAND);
  106. return FALSE;
  107. }
  108. /* Create a main window for this application instance. */
  109. wsprintf(buf, "FKeys:%x", hInst);
  110. hWnd = CreateWindow(
  111. "FKeysWClass",
  112. "FKeys Sample Application",
  113. WS_OVERLAPPEDWINDOW,
  114. CW_USEDEFAULT,
  115. CW_USEDEFAULT,
  116. CW_USEDEFAULT,
  117. CW_USEDEFAULT,
  118. NULL,
  119. NULL,
  120. hInstance,
  121. NULL
  122. );
  123. /* If window could not be created, return "failure" */
  124. if (!hWnd)
  125. return (FALSE);
  126. /* Make the window visible; update its client area; and return "success" */
  127. ShowWindow(hWnd, nCmdShow);
  128. UpdateWindow(hWnd);
  129. return (TRUE);
  130. }
  131. /* -------------------------------------------------------------------------- */
  132. HCTX static NEAR TabletInit(HWND hWnd)
  133. {
  134. LOGCONTEXT lcMine;
  135. AXIS a;
  136. /* get default region */
  137. WTInfo(WTI_DEFCONTEXT, 0, &lcMine);
  138. /* modify the digitizing region */
  139. wsprintf(lcMine.lcName, "FKeys %x", hInst);
  140. lcMine.lcOptions |= CXO_MESSAGES;
  141. lcMine.lcPktData = PACKETDATA | FKeysMask;
  142. lcMine.lcPktMode = PACKETMODE;
  143. lcMine.lcMoveMask = PACKETDATA | FKeysMask;
  144. lcMine.lcBtnUpMask = lcMine.lcBtnDnMask = 0;
  145. lcMine.lcInOrgX = lcMine.lcInOrgY = lcMine.lcInOrgZ = 0;
  146. WTInfo(WTI_DEVICES + lcMine.lcDevice, DVC_X, &a);
  147. lcMine.lcInExtX = a.axMax;
  148. WTInfo(WTI_DEVICES + lcMine.lcDevice, DVC_Y, &a);
  149. lcMine.lcInExtY = a.axMax;
  150. if (WTInfo(WTI_DEVICES + lcMine.lcDevice, DVC_Z, &a))
  151. lcMine.lcInExtZ = a.axMax;
  152. /* open the region */
  153. return WTOpen(hWnd, &lcMine, TRUE);
  154. }
  155. /* -------------------------------------------------------------------------- */
  156. LRESULT FAR PASCAL MainWndProc(hWnd, message, wParam, lParam)
  157. HWND hWnd;
  158. unsigned message;
  159. WPARAM wParam;
  160. LPARAM lParam;
  161. {
  162. FARPROC lpProcAbout;
  163. static HCTX hTab = NULL;
  164. static inOverlap;
  165. PACKET pkt;
  166. switch (message) {
  167. case WM_CREATE:
  168. hTab = TabletInit(hWnd);
  169. if (!hTab) {
  170. MessageBox(NULL, " Could Not Open Tablet Context.", "WinTab",
  171. MB_OK | MB_ICONHAND);
  172. SendMessage(hWnd, WM_DESTROY, 0, 0L);
  173. }
  174. break;
  175. case WT_PACKET:
  176. if (WTPacket((HCTX)lParam, wParam, &pkt)) {
  177. static char buf[100];
  178. if (pkt.pkFKeys) {
  179. MessageBeep(0);
  180. }
  181. wsprintf(buf, "FKeys:%x %d", hInst, pkt.pkFKeys);
  182. SetWindowText(hWnd, buf);
  183. }
  184. break;
  185. case WT_CTXOVERLAP:
  186. if (!inOverlap && !(lParam & CXS_ONTOP)) {
  187. inOverlap = TRUE;
  188. WTOverlap(hTab, TRUE);
  189. inOverlap = FALSE;
  190. }
  191. break;
  192. case WM_COMMAND:
  193. if (GET_WM_COMMAND_ID(wParam, lParam) == IDM_ABOUT) {
  194. lpProcAbout = MakeProcInstance(About, hInst);
  195. DialogBox(hInst,
  196. "AboutBox",
  197. hWnd,
  198. lpProcAbout);
  199. FreeProcInstance(lpProcAbout);
  200. break;
  201. }
  202. else
  203. return (DefWindowProc(hWnd, message, wParam, lParam));
  204. case WM_DESTROY:
  205. if (hTab)
  206. WTClose(hTab);
  207. PostQuitMessage(0);
  208. break;
  209. default:
  210. return (DefWindowProc(hWnd, message, wParam, lParam));
  211. }
  212. return 0;
  213. }
  214. /* -------------------------------------------------------------------------- */
  215. BOOL FAR PASCAL About(hDlg, message, wParam, lParam)
  216. HWND hDlg;
  217. unsigned message;
  218. WPARAM wParam;
  219. LPARAM lParam;
  220. {
  221. switch (message) {
  222. case WM_INITDIALOG:
  223. return (TRUE);
  224. case WM_COMMAND:
  225. if (GET_WM_COMMAND_ID(wParam, lParam) == IDOK
  226. || GET_WM_COMMAND_ID(wParam, lParam) == IDCANCEL) {
  227. EndDialog(hDlg, TRUE);
  228. return (TRUE);
  229. }
  230. break;
  231. }
  232. return (FALSE);
  233. }
  234. /* -------------------------------------------------------------------------- */
  235.