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.

293 lines
6.9 KiB

  1. /*------------------------------------------------------------------------------
  2. PrsTest - using pressure input.
  3. RICO 4/1/92
  4. ------------------------------------------------------------------------------*/
  5. #include <windows.h>
  6. #include "msgpack.h"
  7. #include <wintab.h>
  8. #define PACKETDATA (PK_X | PK_Y | PK_BUTTONS | PK_NORMAL_PRESSURE)
  9. #define PACKETMODE PK_BUTTONS
  10. #include <pktdef.h>
  11. #include "prstest.h"
  12. #ifdef USE_X_LIB
  13. #include <wintabx.h>
  14. #endif
  15. HANDLE hInst;
  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. #ifdef USE_X_LIB
  40. _UnlinkWintab();
  41. #endif
  42. return (msg.wParam);
  43. }
  44. /* -------------------------------------------------------------------------- */
  45. BOOL InitApplication(hInstance)
  46. HANDLE hInstance;
  47. {
  48. WNDCLASS wc;
  49. /* Fill in window class structure with parameters that describe the */
  50. /* main window. */
  51. wc.style = 0;
  52. wc.lpfnWndProc = MainWndProc;
  53. wc.cbClsExtra = 0;
  54. wc.cbWndExtra = 0;
  55. wc.hInstance = hInstance;
  56. wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  57. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  58. wc.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE + 1);
  59. wc.lpszMenuName = "PrsTestMenu";
  60. wc.lpszClassName = "PrsTestWClass";
  61. /* Register the window class and return success/failure code. */
  62. return (RegisterClass(&wc));
  63. }
  64. /* -------------------------------------------------------------------------- */
  65. BOOL InitInstance(hInstance, nCmdShow)
  66. HANDLE hInstance;
  67. int nCmdShow;
  68. {
  69. HWND hWnd;
  70. char buf[50];
  71. /* Save the instance handle in static variable, which will be used in */
  72. /* many subsequence calls from this application to Windows. */
  73. hInst = hInstance;
  74. /* check if WinTab available. */
  75. if (!WTInfo(0, 0, NULL)) {
  76. MessageBox(NULL, "WinTab Services Not Available.", "WinTab",
  77. MB_OK | MB_ICONHAND);
  78. return FALSE;
  79. }
  80. /* Create a main window for this application instance. */
  81. wsprintf(buf, "PrsTest:%x", hInst);
  82. hWnd = CreateWindow(
  83. "PrsTestWClass",
  84. buf,
  85. WS_OVERLAPPEDWINDOW,
  86. CW_USEDEFAULT,
  87. CW_USEDEFAULT,
  88. CW_USEDEFAULT,
  89. CW_USEDEFAULT,
  90. NULL,
  91. NULL,
  92. hInstance,
  93. NULL
  94. );
  95. /* If window could not be created, return "failure" */
  96. if (!hWnd)
  97. return (FALSE);
  98. /* Make the window visible; update its client area; and return "success" */
  99. ShowWindow(hWnd, nCmdShow);
  100. UpdateWindow(hWnd);
  101. return (TRUE);
  102. }
  103. /* -------------------------------------------------------------------------- */
  104. HCTX static NEAR TabletInit(HWND hWnd)
  105. {
  106. LOGCONTEXT lcMine;
  107. /* get default region */
  108. WTInfo(WTI_DEFCONTEXT, 0, &lcMine);
  109. /* modify the digitizing region */
  110. wsprintf(lcMine.lcName, "PrsTest Digitizing %x", hInst);
  111. lcMine.lcOptions |= CXO_MESSAGES;
  112. lcMine.lcPktData = PACKETDATA;
  113. lcMine.lcPktMode = PACKETMODE;
  114. lcMine.lcMoveMask = PACKETDATA;
  115. lcMine.lcBtnUpMask = lcMine.lcBtnDnMask;
  116. /* output in 10000 x 10000 grid */
  117. lcMine.lcOutOrgX = lcMine.lcOutOrgY = 0;
  118. lcMine.lcOutExtX = 10000;
  119. lcMine.lcOutExtY = 10000;
  120. /* open the region */
  121. return WTOpen(hWnd, &lcMine, TRUE);
  122. }
  123. /* -------------------------------------------------------------------------- */
  124. LRESULT FAR PASCAL MainWndProc(hWnd, message, wParam, lParam)
  125. HWND hWnd;
  126. unsigned message;
  127. WPARAM wParam;
  128. LPARAM lParam;
  129. {
  130. FARPROC lpProcAbout;
  131. static HCTX hTab = NULL;
  132. static POINT ptOld, ptNew;
  133. static UINT prsOld, prsNew;
  134. static RECT rcClient;
  135. PAINTSTRUCT psPaint;
  136. HDC hDC;
  137. PACKET pkt;
  138. BOOL fHandled = TRUE;
  139. LRESULT lResult = 0L;
  140. switch (message) {
  141. case WM_CREATE:
  142. hTab = TabletInit(hWnd);
  143. if (!hTab) {
  144. MessageBox(NULL, " Could Not Open Tablet Context.", "WinTab",
  145. MB_OK | MB_ICONHAND);
  146. SendMessage(hWnd, WM_DESTROY, 0, 0L);
  147. }
  148. break;
  149. case WM_SIZE:
  150. GetClientRect(hWnd, &rcClient);
  151. InvalidateRect(hWnd, NULL, TRUE);
  152. break;
  153. case WM_COMMAND:
  154. if (GET_WM_COMMAND_ID(wParam, lParam) == IDM_ABOUT) {
  155. lpProcAbout = MakeProcInstance(About, hInst);
  156. DialogBox(hInst,
  157. "AboutBox",
  158. hWnd,
  159. lpProcAbout);
  160. FreeProcInstance(lpProcAbout);
  161. }
  162. else
  163. fHandled = FALSE;
  164. break;
  165. case WT_PACKET:
  166. if (WTPacket((HCTX)lParam, wParam, &pkt)) {
  167. if (HIWORD(pkt.pkButtons)==TBN_DOWN) {
  168. MessageBeep(0);
  169. }
  170. ptOld = ptNew;
  171. prsOld = prsNew;
  172. ptNew.x = MulDiv((UINT)pkt.pkX, rcClient.right, 10000);
  173. ptNew.y = MulDiv((UINT)pkt.pkY, rcClient.bottom, 10000);
  174. prsNew = pkt.pkNormalPressure;
  175. if (ptNew.x != ptOld.x ||
  176. ptNew.y != ptOld.y ||
  177. prsNew != prsOld) {
  178. InvalidateRect(hWnd, NULL, TRUE);
  179. }
  180. }
  181. break;
  182. case WM_ACTIVATE:
  183. if (GET_WM_ACTIVATE_STATE(wParam, lParam))
  184. InvalidateRect(hWnd, NULL, TRUE);
  185. /* if switching in the middle, disable the region */
  186. if (hTab) {
  187. WTEnable(hTab, GET_WM_ACTIVATE_STATE(wParam, lParam));
  188. if (hTab && GET_WM_ACTIVATE_STATE(wParam, lParam))
  189. WTOverlap(hTab, TRUE);
  190. }
  191. break;
  192. case WM_DESTROY:
  193. if (hTab)
  194. WTClose(hTab);
  195. PostQuitMessage(0);
  196. break;
  197. case WM_PAINT:
  198. if (hDC = BeginPaint(hWnd, &psPaint)) {
  199. POINT ptHere;
  200. ptHere.x = ptNew.x;
  201. ptHere.y = rcClient.bottom - ptNew.y;
  202. /* redo horz */
  203. Ellipse(hDC, ptHere.x - prsNew, ptHere.y - prsNew,
  204. ptHere.x + prsNew, ptHere.y + prsNew);
  205. PatBlt(hDC, rcClient.left, ptHere.y,
  206. rcClient.right, 1, DSTINVERT);
  207. /* redo vert */
  208. PatBlt(hDC, ptHere.x, rcClient.top,
  209. 1, rcClient.bottom, DSTINVERT);
  210. EndPaint(hWnd, &psPaint);
  211. }
  212. break;
  213. default:
  214. fHandled = FALSE;
  215. break;
  216. }
  217. if (fHandled)
  218. return (lResult);
  219. else
  220. return (DefWindowProc(hWnd, message, wParam, lParam));
  221. }
  222. /* -------------------------------------------------------------------------- */
  223. BOOL FAR PASCAL About(hDlg, message, wParam, lParam)
  224. HWND hDlg;
  225. unsigned message;
  226. WPARAM wParam;
  227. LPARAM lParam;
  228. {
  229. switch (message) {
  230. case WM_INITDIALOG:
  231. return (TRUE);
  232. case WM_COMMAND:
  233. if (GET_WM_COMMAND_ID(wParam, lParam) == IDOK
  234. || GET_WM_COMMAND_ID(wParam, lParam) == IDCANCEL) {
  235. EndDialog(hDlg, TRUE);
  236. return (TRUE);
  237. }
  238. break;
  239. }
  240. return (FALSE);
  241. }
  242. /* -------------------------------------------------------------------------- */
  243.