1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184:
|
#include <windows.h> #include <hapi.h> #include <string.h>
LRESULT CALLBACK WindowProc(HWND,UINT,WPARAM,LPARAM);
int count = 0; char message[100]; char position[100]; int buttons[256];
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdParam, int iCmdShow) { static char szAppName[] = "Mouse Test"; HWND hWnd; MSG msg; WNDCLASSEX wndclass; int i; HBITMAP cursors[2]; hPOINT hotspots[2]; wndclass.cbSize = sizeof(wndclass); wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wndclass.lpfnWndProc = WindowProc; wndclass.cbClsExtra = 0; wndclass.cbWndExtra = 0; wndclass.hInstance = hInstance; wndclass.hIcon = LoadIcon(NULL,IDI_APPLICATION); wndclass.hCursor = LoadCursor(NULL,IDC_ARROW); wndclass.hbrBackground = NULL; wndclass.lpszMenuName = NULL; wndclass.lpszClassName = szAppName; wndclass.hIconSm = LoadIcon(NULL,IDI_APPLICATION); RegisterClassEx(&wndclass); hWnd = CreateWindow(szAppName, "CPNMouse test program", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL); ShowWindow(hWnd,iCmdShow);
count = hInitialise(0, hWnd, GetDC(NULL), BUTTON | MOVEMENT | CURSOR | CLIP | ACCELERATE | SUSPEND);
sprintf(message, "I found %i mice using CPNMouse driver", count);
cursors[0] = LoadBitmap(hInstance, (LPCSTR) 20000); cursors[1] = LoadBitmap(hInstance, (LPCSTR) 20001);
hotspots[0].x = 0; hotspots[0].y = 0; hotspots[1].x = 0; hotspots[1].y = 17;
for (i = 0; i < count; ++i) { if (i/2 == 0) hSetCursor(i + 1, hotspots[i % 2], cursors[i % 2], 255, 0, 0); if (i/2 == 1) hSetCursor(i + 1, hotspots[i % 2], cursors[i % 2], 0, 255, 0); if (i/2 == 2) hSetCursor(i + 1, hotspots[i % 2], cursors[i % 2], 0, 0, 255); if (i/2 == 3) hSetCursor(i + 1, hotspots[i % 2], cursors[i % 2], 0, 0, 0); }
UpdateWindow(hWnd); while (GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } hCleanup();
return msg.wParam; }
HDC hDC; HPALETTE hPal; RECT rectangle; LRESULT CALLBACK WindowProc(HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT ps; RECT text; hPOINT p; int i;
switch (iMsg) { case WM_CREATE: hDC = GetDC(hWnd); return 0; case WM_PAINT: BeginPaint(hWnd,&ps); text.right = rectangle.right; text.bottom = 40; text.left = 20; text.top = 20; FillRect(hDC, &rectangle, (HBRUSH) (COLOR_WINDOW + 1)); DrawText(hDC, message, -1, &text, DT_END_ELLIPSIS);
text.top += 20; for (i = 0; i < count; ++i) { hGetAbsolutePosition(i + 1, &p);
sprintf(position, "Mouse #%i is at (%i, %i) with button state %x", i + 1, p.x, p.y, buttons[i]); text.top += 30; text.bottom = text.top + 20; DrawText(hDC, position, -1, &text, DT_END_ELLIPSIS); text.top += 15; text.bottom = text.top + 20; DrawText(hDC, (const char *) lGetDevicePath(i + 1), -1, &text, DT_END_ELLIPSIS | DT_NOPREFIX); } EndPaint(hWnd,&ps); return 0; case WM_SETFOCUS: InvalidateRect(hWnd,NULL,TRUE); return 0; case WM_SIZE: rectangle.right = LOWORD(lParam); rectangle.bottom = HIWORD(lParam); return 0; case WM_DESTROY: DeleteObject(hPal); ReleaseDC(hWnd,hDC); PostQuitMessage(0); return 0; case (WM_USER + 1001): buttons[HIBYTE(HIWORD(wParam)) - 1] = LOWORD(wParam);
InvalidateRect(hWnd,NULL,TRUE); } return DefWindowProc(hWnd,iMsg,wParam,lParam); } |