Autor Beitrag
Timi-loader
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58

Win XP
Delphi 7 Personal
BeitragVerfasst: Mi 27.05.09 12:04 
Hallo.

Leider habe ich keine Ahnung von C. Daher brauch ich eure Hilfe beim portieren einer Funktion.
Also der Sinn der Software ist es eine Cursorposition und Buttonstate zu bekommen von einer Hardwaremaus mit bestimmtem Treiber, der vorher installiert sein muss. Der Treiber filtert von jeder normalen HUD-Maus während des Betriebs des Programms dann diese Mausbewegungen von der normalen Windows-Maus weg und man hat eine extra Maus für spezielle Programmierungen.

Das C-Programm stellt einen zweiten Cursor dar, der sich eben mit den Bewegungen der 2. Maus mit speziellem Treiber bewegt.

Ich würde nun gern diese Funktion eines zweiten Cursors in Delphi nutzen wollen.
In der Theorie muss man doch nur auf den Treiber über Windows zugreifen.. oder so. Jedenfalls sind die Funktionen wie WindowProc doch auch in Delphi oder?

Hier der Quellcode des Programmes in C:
ausblenden volle Höhe C#-Quelltext
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:
/****************************************************************************\
 *                                                                            *
 *  First.c                                                                   *
 *                                                                            *
 *  This is the first Fastgraph for Windows example program. It demonstrates  *
 *  tasks common to most Fastgraph for Windows programs and serves as a       *
 *  template for building the other examples.                                 *
 *                                                                            *
 \****************************************************************************/



#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, // window class name
      "CPNMouse test program"// window caption
      WS_OVERLAPPEDWINDOW,     // window style
      CW_USEDEFAULT,           // initial x position
      CW_USEDEFAULT,           // initial y position
      CW_USEDEFAULT,           // initial x size
      CW_USEDEFAULT,           // initial y size
      NULL,                    // parent window handle
      NULL,                    // window menu handle
      hInstance,               // program instance handle
      NULL);                   // creation parameters
  ShowWindow(hWnd,iCmdShow);

  /* CPNMOUSE
   * Grab all mice. Send images to the just created window.  Draw on the
   * entire desktop (GetDC(NULL) returns a device context for the entire
   * screen).  We want events on button press/release and mouse movement,
   * we want the API to draw cursors, the cursor should be kept on
   * screen, the mouse should be accelerated and we want events for
   * suspended mice. */

  count = hInitialise(0, hWnd, GetDC(NULL), BUTTON | MOVEMENT | CURSOR | CLIP | ACCELERATE | SUSPEND);

  sprintf(message, "I found %i mice using CPNMouse driver", count);

  /* CPNMOUSE
   * Set cursors -- all odd mice use an arrow pointing to the left, all
   * even mice use an arrow pointing right.
   * We also set the colour.  I have arbitrarily hard-coded 4 colours,
   * so up to 8 mice can be distinguished.
   */

  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], 25500);
    if (i/2 == 1)
      hSetCursor(i + 1, hotspots[i % 2], cursors[i % 2], 02550);
    if (i/2 == 2)
      hSetCursor(i + 1, hotspots[i % 2], cursors[i % 2], 00255);
    if (i/2 == 3)
      hSetCursor(i + 1, hotspots[i % 2], cursors[i % 2], 000);
  }

  UpdateWindow(hWnd);
  while (GetMessage(&msg,NULL,0,0)) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
  }
  
  /* CPNMOUSE
   * Give the mice back to Windows.  This is also done automatically when
   * the application exits (even when it crashes) */

  hCleanup();

  return msg.wParam;
}

/****************************************************************************\
 *                                                                            *
 *  WindowProc                                                                *
 *                                                                            *
 *  Window procedure to handle messages sent to the window.                   *
 *                                                                            *
 \****************************************************************************/

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) {
        /* CPNMOUSE
         * Get absolute position of mice.  Note that the mice are numbered from 1 */

        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;
    /* CPNMOUSE
     * The following event is sent whenever the mouse status has changed.  The information
     * returned is as follows:
     *
     * LOWORD(lParam): dx
     * HIWORD(lParam): dy
     * LOWORD(wParam): bitfield indicating buttons pressed or released
     * HIBYTE(HIWORD(wParam)): Number of mouse the event concerns
     * LOBYTE(HIWORD(wParam)): Flags
     */

    case (WM_USER + 1001):
      /* CPNMOUSE
       * If the number of the mouse is below 100 (we have only allocated that much
       * memory), store the button state (used for printing) */

      buttons[HIBYTE(HIWORD(wParam)) - 1] = LOWORD(wParam);

      InvalidateRect(hWnd,NULL,TRUE);
  }
  return DefWindowProc(hWnd,iMsg,wParam,lParam);
}


Wäre echt nice, wenn das jemand als Delphi hinbekommt. Ich würde das Projekt gern fortsetzen bzw selbst nutzen.

Link zum Projekt und den Treibern und Anleitung zum installieren: cpnmouse.sourceforge.net/
Ich hab das selbst installiert und es funktioniert. (Ich musste auch die Treiber-inf ergänzen)

MfG
Tim
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mi 27.05.09 14:14 
Einzig wichtig für dich in der Übersetzung sind die Funktionsaufrufe für die HAPI-Funktionen, wozu du eine entsprechende API-Übersetzung der hapi.h brauchst.

Für die Mausbewegegung ist der case WM_USER+1001 zuständig, den Du unter Delphi mit WM_CPNMOUSE_STATUS wie folgt abfragen kannst:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
const
    WM_CPNMOUSE_STATUS = WM_USER+1001;

procedure TFormKlasse.CPNMouseStatus(var Message:TMessage); message WM_CPNMOUSE_STATUS;
begin
    //Informationen aus Message auslesen wie im Kommentar beschrieben).
end;

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Timi-loader Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 58

Win XP
Delphi 7 Personal
BeitragVerfasst: Mi 27.05.09 16:08 
oh gott.. das hatte ich befürchtet, dass die HAPI auch übersetzt werden muss.. hm. die messages werden bestimmt auch nicht global übertragen, sodass ich vllt das originalprogramm und meines paralell laufen lassen könnte um mir die übersetzung zu sparen.

dass jemand die hapi übersetzt wäre zuviel verlangt oder? :-S
wären ca. 25kb text in 5 dateien: include/guid.h include/hapi.h include/lapi.h und src/hapi.c und src/lapi.c
down zu loaden in der prdownloads.sourcefo...i-0.9.3.zip?download


dann werd ich wohl doch versuchen mein ziel anders zu erreichen. (ziel=mehrere cursor paralell sinnvoll nutzbar und in spezialapps auch gleichzeitig nutzbar für bilder zoomen etc.)
..neuer ansatz wäre die HID von der aktuell bewegenden maus zu bekommen und danach zu handeln. soll wohl auch möglich sein.

für alle die es interessiert, ich hab ne ne gute software gefunden, die grob schon das kann was ich machen will: www.wunderworks.com/teamplayer/

mfg
tim
hui1991
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 433

Windows XP, WIndows Vista
Turbo Delphi Explorer| Delphi, PHP,Blitzbasic
BeitragVerfasst: Mi 27.05.09 20:08 
Mit RAWInput ist das auch möglich.
Blos hab nie wirklich herausgefunden wie das funktioniert.
Auf 32-Bit hat das Programm funktioniert, blos auf 64-Bit hat das irgendwie nicht funktioniert (das Demo-Projekt).
Wollte auch 2 Mäuse/Tastaturen gleichzeitig an einem PC haben können.
Am weitesten kam ich mit den C#-Demos, mit Delphi hab ich kein Code zum laufen bekommen.