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.

183 lines
4.2 KiB

  1. #include <windows.h>
  2. #include "wintab.h"
  3. #include "Mgrtest.h"
  4. #include "resource.h"
  5. static const unsigned textfield[4] = { IDC_TEXT1, IDC_TEXT2, IDC_TEXT3, IDC_TEXT4 };
  6. extern HANDLE hInst;
  7. static void CsrDisplayBits( HWND hDlg, const BYTE FAR csrmask[16] )
  8. {
  9. char buf[33];
  10. unsigned i, j;
  11. buf[32] = 0;
  12. for( i = 0; i < 4; i++ ) {
  13. for( j = 0; j < 32; j++ )
  14. buf[j] = '0' + ((csrmask[4*i + j/8] >> (j%8)) & 0x01);
  15. SetWindowText(GetDlgItem(hDlg, textfield[i]), buf);
  16. }
  17. }
  18. BOOL
  19. CALLBACK CsrmaskDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LONG lParam)
  20. {
  21. static BYTE FAR * csrmask;
  22. BOOL fResult;
  23. int i;
  24. LRESULT val;
  25. switch (Msg) {
  26. case WM_INITDIALOG:
  27. /* Display the Csrmask bitfield bits */
  28. csrmask = (BYTE FAR *)lParam;
  29. CsrDisplayBits(hDlg, csrmask);
  30. fResult = TRUE;
  31. /* List the available cursors, and highlight them if their Csrmask bits are set */
  32. i = 0;
  33. while( WTInfo( WTI_CURSORS + i, 0, 0 ) ) {
  34. char name[1024];
  35. WTInfo( WTI_CURSORS + i, CSR_NAME, name );
  36. SendDlgItemMessage( hDlg, IDC_CSRLST, LB_ADDSTRING, 0, (LPARAM)((char FAR *)name) );
  37. i++;
  38. }
  39. /* for Unknown Reason, sending LB_SETSEL right after LB_ADDSTRING doesn't work reliably */
  40. i = 0;
  41. while( WTInfo( WTI_CURSORS + i, 0, 0 ) ) {
  42. /* Highlight the name in the selection box */
  43. SendDlgItemMessage( hDlg, IDC_CSRLST, LB_SETSEL, (csrmask[i/8] >> (i%8)) & 0x01, i );
  44. i++;
  45. }
  46. break;
  47. case WM_LBUTTONDOWN:
  48. /* If clicked on a number in IDC_TEXT?, then change it's corrisponding bit */
  49. i = test_bitboxes( hDlg, lParam, 32, 4, textfield );
  50. if( i > -1 ) {
  51. /* Flip the bit */
  52. csrmask[i / 8] ^= 1 << (i % 8);
  53. CsrDisplayBits(hDlg, csrmask);
  54. /* Highlight the corrisponding cursor in the listbox appropriately */
  55. SendDlgItemMessage( hDlg, IDC_CSRLST, LB_SETSEL, (csrmask[i/8] >> (i%8)) & 0x01, i );
  56. }
  57. fResult = TRUE;
  58. break;
  59. case WM_COMMAND:
  60. switch( wParam ) {
  61. case IDOK:
  62. EndDialog(hDlg, wParam);
  63. fResult = TRUE;
  64. break;
  65. case IDCANCEL:
  66. EndDialog(hDlg, wParam);
  67. fResult = TRUE;
  68. break;
  69. default:
  70. if( HIWORD(wParam) == LBN_SELCHANGE || wParam == IDC_CSRLST ) {
  71. /* Set all of the bits according to the selection box selections until error */
  72. i = 0;
  73. fResult = FALSE;
  74. while( !fResult ) {
  75. val = SendMessage( (HWND)lParam, LB_GETSEL, i, 0 );
  76. if( val > 0 )
  77. csrmask[i/8] |= 1 << (i%8);
  78. else
  79. if( val == 0 )
  80. csrmask[i/8] &= ~(1 << (i%8));
  81. else
  82. fResult = TRUE;
  83. i++;
  84. }
  85. /* Redisplay the bits */
  86. CsrDisplayBits(hDlg, csrmask);
  87. }
  88. break;
  89. }
  90. break;
  91. default:
  92. fResult = FALSE;
  93. break;
  94. }
  95. return fResult;
  96. }
  97. void
  98. set_default_CsrMask( HWND hWnd, HMGR hMgr, int fSys )
  99. {
  100. int wDev;
  101. FARPROC lpProcDlg;
  102. /* Get a device # */
  103. lpProcDlg = MakeProcInstance( (FARPROC)CursInfoDlgProc, hInst);
  104. wDev = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_INFOLIST),
  105. hWnd, lpProcDlg, WTI_DDCTXS);
  106. FreeProcInstance(lpProcDlg);
  107. if( wDev >= 0 ) {
  108. FARPROC fpProc;
  109. HCTX hCtx;
  110. int id;
  111. BYTE CsrMask[16];
  112. unsigned numDevices;
  113. WTInfo(WTI_INTERFACE, IFC_NDEVICES, &numDevices);
  114. if( wDev < (int)numDevices ) {
  115. hCtx = WTMgrDefContextEx(hMgr, wDev, fSys);
  116. if( !hCtx )
  117. hCtx = WTMgrDefContext(hMgr, fSys);
  118. } else
  119. hCtx = WTMgrDefContext(hMgr, fSys); /* 'Default Device' was the last choice in the dialog */
  120. /* Read the button masks */
  121. if( !hCtx ) {
  122. MessageBox( hWnd, "Failed to open default context.", "MgrTest", MB_ICONHAND | MB_OK );
  123. return;
  124. }
  125. if( !WTExtGet( hCtx, WTX_CSRMASK, CsrMask ) ) {
  126. MessageBox( hWnd, "Cursor mask not supported on this device.", "MgrTest", MB_ICONHAND | MB_OK );
  127. return;
  128. }
  129. /* Do the button bit dialog */
  130. fpProc = MakeProcInstance((FARPROC)CsrmaskDlgProc, hInst );
  131. id = DialogBoxParam(hInst, MAKEINTRESOURCE(IDD_CSRMASKS), hWnd, fpProc, (long)((BYTE FAR *)CsrMask));
  132. FreeProcInstance(fpProc);
  133. /* Set the new button masks */
  134. if( id == IDOK ) {
  135. if( !WTExtSet( hCtx, WTX_CSRMASK, CsrMask ) )
  136. MessageBox( hWnd, "WTExtSet failed.", "MgrTest", MB_ICONHAND | MB_OK );
  137. }
  138. }
  139. }