summaryrefslogtreecommitdiff
path: root/IvyCursor/IvyCursor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'IvyCursor/IvyCursor.cpp')
-rw-r--r--IvyCursor/IvyCursor.cpp325
1 files changed, 325 insertions, 0 deletions
diff --git a/IvyCursor/IvyCursor.cpp b/IvyCursor/IvyCursor.cpp
new file mode 100644
index 0000000..8b5e48e
--- /dev/null
+++ b/IvyCursor/IvyCursor.cpp
@@ -0,0 +1,325 @@
+// IvyCursor.cpp : définit le point d'entrée pour l'application.
+//
+
+#include "stdafx.h"
+#include <winuser.h>
+#include <crtdbg.h>
+#include <shellapi.h>
+#include "Ivy.h"
+#include "IvyCursor.h"
+#define MAX_LOADSTRING 100
+
+#define WM_ICONTRAY_NOTIFY (WM_USER+150)
+// Variables globales :
+HINSTANCE hInst; // instance actuelle
+TCHAR szTitle[MAX_LOADSTRING]; // Le texte de la barre de titre
+TCHAR szWindowClass[MAX_LOADSTRING]; // le nom de la classe de fenêtre principale
+HMENU hMenu; // handle menu icontray
+HMENU hmenuTrackPopup;
+
+// Ivy
+Ivy* ivy;
+
+// Pré-déclarations des fonctions incluses dans ce module de code :
+ATOM MyRegisterClass(HINSTANCE hInstance);
+BOOL InitInstance(HINSTANCE, int);
+LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
+LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);
+
+
+void ivyCursorMouve(IvyApplication *app, void *user_data, int argc, const char **argv)
+{
+ UINT nb;
+ INPUT Inputs;
+ int x,y;
+ double xf = atof( *argv++ );
+ double yf = atof( *argv++ );
+ x = (int)(65535 * xf / 100.0 + 0.5);
+ y = (int)(65535 * yf / 100.0 + 0.5);
+ Inputs.type = INPUT_MOUSE;
+ Inputs.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;
+ Inputs.mi.time = 0; // system provide it
+ Inputs.mi.dx = x;
+ Inputs.mi.dy = y;
+ nb = SendInput( 1, &Inputs, sizeof(INPUT));
+
+ if ( nb != 1 )
+ {
+ _RPT3(_CRT_WARN,"ivyCursorMouve can move to x=%d y=%d error=%d\n",x,y,GetLastError());
+ }
+}
+void ivyCursorClick(IvyApplication *app, void *user_data, int argc, const char **argv)
+{
+ UINT nb;
+ INPUT Inputs[2];
+ int x,y;
+ double xf = atof( *argv++ );
+ double yf = atof( *argv++ );
+ x = (int)(65535 * xf / 100.0 + 0.5);
+ y = (int)(65535 * yf / 100.0 + 0.5);
+ Inputs[0].type = INPUT_MOUSE;
+ Inputs[0].mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_ABSOLUTE;
+ Inputs[0].mi.time = 0; // system provide it
+ Inputs[0].mi.dx = x;
+ Inputs[0].mi.dy = y;
+ Inputs[1].type = INPUT_MOUSE;
+ Inputs[1].mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_LEFTUP | MOUSEEVENTF_ABSOLUTE;
+ Inputs[1].mi.time = 0; // system provide it
+ Inputs[1].mi.dx = x;
+ Inputs[1].mi.dy = y;
+ nb = SendInput( 2, Inputs, sizeof(INPUT));
+
+ if ( nb != 2 )
+ {
+ _RPT3(_CRT_WARN,"ivyCursorClick can click to x=%d y=%d error=%d\n",x,y,GetLastError());
+ }
+}
+int APIENTRY _tWinMain(HINSTANCE hInstance,
+ HINSTANCE hPrevInstance,
+ LPTSTR lpCmdLine,
+ int nCmdShow)
+{
+ MSG msg;
+ // Initialise les chaînes globales
+ LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
+ LoadString(hInstance, IDC_IVYCURSOR, szWindowClass, MAX_LOADSTRING);
+ hMenu = LoadMenu(hInstance, MAKEINTRESOURCE( IDR_MENU1 ) );
+
+ // TrackPopupMenu cannot display the menu bar so get
+ // a handle to the first shortcut menu.
+
+ hmenuTrackPopup = GetSubMenu(hMenu, 0);
+
+ if ( hmenuTrackPopup == NULL )
+ {
+ return FALSE;
+ }
+ MyRegisterClass(hInstance);
+
+ // Effectue l'initialisation de l'application :
+ if (!InitInstance (hInstance, nCmdShow))
+ {
+ return FALSE;
+ }
+ // Initoiailize ivy
+ ivy = new Ivy("IvyCursor", "IvyCursor Ready", 0, FALSE );
+ ivy->BindMsg(BUS_CALLBACK(ivyCursorMouve,0),"Cigale SetCursorPosition x=([0-9.]+) y=([0-9.]+)");
+ ivy->BindMsg(BUS_CALLBACK(ivyCursorClick,0),"Cigale CursorSelectEvent x=([0-9.]+) y=([0-9.]+)");
+ ivy->start( 0 );
+
+ // Boucle de messages principale :
+ while (GetMessage(&msg, NULL, 0, 0))
+ {
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+
+ return (int) msg.wParam;
+}
+
+
+
+//
+// FONCTION : MyRegisterClass()
+//
+// BUT : inscrit la classe de fenêtre.
+//
+// COMMENTAIRES :
+//
+// Cette fonction et son utilisation sont nécessaires uniquement si vous souhaitez que ce code
+// soit compatible avec les systèmes Win32 avant la fonction 'RegisterClassEx'
+// qui a été ajoutée à Windows 95. Il est important d'appeler cette fonction
+// afin que l'application dispose des petites icônes correctes qui lui sont
+// associées.
+//
+ATOM MyRegisterClass(HINSTANCE hInstance)
+{
+ WNDCLASSEX wcex;
+
+ wcex.cbSize = sizeof(WNDCLASSEX);
+
+ wcex.style = CS_HREDRAW | CS_VREDRAW;
+ wcex.lpfnWndProc = (WNDPROC)WndProc;
+ wcex.cbClsExtra = 0;
+ wcex.cbWndExtra = 0;
+ wcex.hInstance = hInstance;
+ wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_IVYCURSOR);
+ wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
+ wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
+ wcex.lpszMenuName = NULL;
+ wcex.lpszClassName = szWindowClass;
+ wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);
+
+ return RegisterClassEx(&wcex);
+}
+
+//
+// FONCTION : InitInstance(HANDLE, int)
+//
+// BUT : enregistre le handle de l'instance et crée une fenêtre principale
+//
+// COMMENTAIRES :
+//
+// Dans cette fonction, nous enregistrons le handle de l'instance dans une variable globale, puis
+// créons et affichons la fenêtre principale du programme.
+//
+BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
+{
+ HWND hWnd;
+ NOTIFYICONDATA icodata;
+
+
+ hInst = hInstance; // Stocke le handle d'instance dans la variable globale
+
+ hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
+ CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, HWND_MESSAGE, NULL, hInstance, NULL);
+
+ if (!hWnd)
+ {
+ return FALSE;
+ }
+
+ ShowWindow(hWnd, nCmdShow);
+ UpdateWindow(hWnd);
+
+ icodata.cbSize = sizeof(NOTIFYICONDATA);
+ icodata.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP ;
+ icodata.hWnd = hWnd;
+ icodata.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_IVYCURSOR);
+ icodata.uID = 0;
+ icodata.uVersion = NOTIFYICON_VERSION;
+ icodata.uCallbackMessage = WM_ICONTRAY_NOTIFY;
+ strcpy ( icodata.szTip, "IvyCursor Event redirector");
+
+ if (! Shell_NotifyIcon( NIM_ADD, &icodata) )
+ {
+ return FALSE;
+ }
+ if (! Shell_NotifyIcon( NIM_SETVERSION, &icodata) )
+ {
+ return FALSE;
+ }
+ icodata.uFlags = NIF_INFO;
+ // Info
+ icodata.dwInfoFlags = NIIF_INFO;
+ strcpy ( icodata.szInfoTitle, "IvyCursor Event redirector");
+ strcpy (icodata.szInfo , "IvyCursor Event redirector" );
+ icodata.uTimeout = 10000; // 10 seconds
+ if (! Shell_NotifyIcon( NIM_MODIFY, &icodata) )
+ {
+ return FALSE;
+ }
+
+ return TRUE;
+}
+void RemoveTrayIcon(HWND hWnd)
+{
+ NOTIFYICONDATA icodata;
+ icodata.cbSize = sizeof( icodata );
+ icodata.uFlags = 0;
+ icodata.hWnd = hWnd;
+ icodata.uID = 0;
+ Shell_NotifyIcon( NIM_DELETE, &icodata);
+}
+void ReturnFocus(HWND hWnd)
+{
+ NOTIFYICONDATA icodata;
+ icodata.cbSize = sizeof( icodata );
+ icodata.uFlags = 0;
+ icodata.hWnd = hWnd;
+ icodata.uID = 0;
+ Shell_NotifyIcon( NIM_SETFOCUS, &icodata);
+}
+void Quitting( HWND hWnd )
+{
+ RemoveTrayIcon(hWnd);
+ DestroyMenu(hMenu);
+ DestroyWindow(hWnd);
+ ivy->stop();
+}
+//
+// FONCTION : WndProc(HWND, unsigned, WORD, LONG)
+//
+// BUT : traite les messages pour la fenêtre principale.
+//
+// WM_COMMAND - traite le menu de l'application
+// WM_PAINT - dessine la fenêtre principale
+// WM_DESTROY - génère un message d'arrêt et retourne
+//
+//
+LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ int wmId, wmEvent;
+ int xPos,yPos;
+ POINT point;
+
+ switch (message)
+ {
+ case WM_COMMAND:
+ wmId = LOWORD(wParam);
+ wmEvent = HIWORD(wParam);
+ // Analyse les sélections de menu :
+ switch (wmId)
+ {
+ case IDM_ABOUT:
+ //DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
+ break;
+ case IDM_EXIT:
+ case ID_QUIT:
+ Quitting(hWnd);
+ break;
+ default:
+ return DefWindowProc(hWnd, message, wParam, lParam);
+ }
+ break;
+ case WM_CONTEXTMENU:
+ // Display the shortcut menu. Track the right mouse
+ // button.
+ xPos = LOWORD(lParam);
+ yPos = HIWORD(lParam);
+
+ TrackPopupMenu(hmenuTrackPopup, TPM_LEFTALIGN | TPM_RIGHTBUTTON,
+ xPos, yPos, 0, hWnd, NULL);
+ PostMessage(hWnd, WM_NULL, 0, 0);
+
+ break;
+ case WM_ICONTRAY_NOTIFY:
+ switch ( lParam )
+ {
+ case WM_LBUTTONDOWN:
+ break;
+ case WM_RBUTTONDOWN:
+ GetCursorPos(&point);
+ TrackPopupMenu(hmenuTrackPopup, TPM_LEFTALIGN | TPM_RIGHTBUTTON,
+ point.x, point.y, 0, hWnd, NULL);
+ PostMessage(hWnd, WM_NULL, 0, 0);
+ break;
+ }
+ break;
+ case WM_DESTROY:
+ PostQuitMessage(0);
+ break;
+ default:
+ return DefWindowProc(hWnd, message, wParam, lParam);
+ }
+ return 0;
+}
+
+// Gestionnaire de messages pour la boîte de dialogue À propos de.
+LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ switch (message)
+ {
+ case WM_INITDIALOG:
+ return TRUE;
+
+ case WM_COMMAND:
+ if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
+ {
+ EndDialog(hDlg, LOWORD(wParam));
+ return TRUE;
+ }
+ break;
+ }
+ return FALSE;
+}