示例#1
0
void fnHook()
{
	HWND         hwndMain;        /* Handle for the main window. */
	MSG          msg;             /* A Win32 message structure. */
	WNDCLASSEX   wndclass;        /* A window class structure. */
	char*        szMainWndClass = "MyWind";
	memset (&wndclass, 0, sizeof(WNDCLASSEX));
	wndclass.lpszClassName = szMainWndClass;
	wndclass.cbSize = sizeof(WNDCLASSEX);
	wndclass.lpfnWndProc = MainWndProc;
	wndclass.hInstance = NULL;


	RegisterClassEx (&wndclass);
	hwndMain = CreateWindow (
		szMainWndClass,             /* Class name */
		NULL,                    /* Caption */
		NULL,        /* Style */
		CW_USEDEFAULT,              /* Initial x (use default) */
		CW_USEDEFAULT,              /* Initial y (use default) */
		CW_USEDEFAULT,              /* Initial x size (use default) */
		CW_USEDEFAULT,              /* Initial y size (use default) */
		HWND_MESSAGE,                       /* No parent window */
		NULL,                       /* No menu */
		NULL,                      /* This program instance */
		NULL                        /* Creation parameters */
		);

	ShowWindow (hwndMain, SW_SHOW);
	UpdateWindow (hwndMain);

	if (!init_raw_mouse(0, 0, 1,hwndMain)) { // registers for (sysmouse=yes,  terminal services mouse=no, HID_mice=yes)
		printf("RawInput not supported by Operating System.  Exiting.\n");
		return;
	}


   // Set mouse hook	
   HHOOK mouseHook = SetWindowsHookEx(
                  WH_MOUSE_LL,      
                  mouseHookProc,    
                  NULL,            
                  NULL);


	while (GetMessage (&msg, NULL, 0, 0))
	{
		TranslateMessage (&msg);
		DispatchMessage (&msg);
	}

	 UnhookWindowsHookEx(mouseHook);
	destroy_raw_mouse();

}
示例#2
0
int APIENTRY 
WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
{
        HWND         hwndMain;        /* Handle for the main window. */
        MSG          msg;             /* A Win32 message structure. */
        WNDCLASSEX   wndclass;        /* A window class structure. */
        char*        szMainWndClass = "WinTestWin";
                                      /* The name of the main window class */

        memset (&wndclass, 0, sizeof(WNDCLASSEX));
        wndclass.lpszClassName = szMainWndClass;
        wndclass.cbSize = sizeof(WNDCLASSEX);
        wndclass.style = CS_HREDRAW | CS_VREDRAW;
        wndclass.lpfnWndProc = MainWndProc;
        wndclass.hInstance = hInst;
        wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
        wndclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
        wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
	wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
        RegisterClassEx (&wndclass);
        hwndMain = CreateWindow (
                szMainWndClass,             /* Class name */
                "Hello",                    /* Caption */
                WS_OVERLAPPEDWINDOW,        /* Style */
                CW_USEDEFAULT,              /* Initial x (use default) */
                CW_USEDEFAULT,              /* Initial y (use default) */
                CW_USEDEFAULT,              /* Initial x size (use default) */
                CW_USEDEFAULT,              /* Initial y size (use default) */
                NULL,                       /* No parent window */
                NULL,                       /* No menu */
                hInst,                      /* This program instance */
                NULL                        /* Creation parameters */
                );
        
        ShowWindow (hwndMain, nShow);
        UpdateWindow (hwndMain);

	// checks for Windows XP.  If no XP is available, gracefully exit.
	//  A real program might opt to use DirectX or regular mouse input
	//  for versions of Windows that fail this call.
	if (!init_raw_mouse(1, 0, 1)) { // registers for (sysmouse=yes,  terminal services mouse=no, HID_mice=yes)
	  MessageBox(NULL, "RawInput not supported by Operating System.  Exiting." , "Error!" ,MB_OK);
	  return 0; 
	}
        while (GetMessage (&msg, NULL, 0, 0))
        {
                TranslateMessage (&msg);
                DispatchMessage (&msg);
        }

	/* deallocate rawmouse stuff */
	destroy_raw_mouse();

        return msg.wParam;
}
示例#3
0
int APIENTRY 
WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
{
         HWND         hwndMain;        /* Handle for the main window. */
        MSG          msg;             /* A Win32 message structure. */
        WNDCLASSEX   wndclass;        /* A window class structure. */
        char*        szMainWndClass = "MyWind";
        memset (&wndclass, 0, sizeof(WNDCLASSEX));
        wndclass.lpszClassName = szMainWndClass;
        wndclass.cbSize = sizeof(WNDCLASSEX);
        wndclass.lpfnWndProc = MainWndProc;
        wndclass.hInstance = hInst;


        RegisterClassEx (&wndclass);
        hwndMain = CreateWindow (
                szMainWndClass,             /* Class name */
                NULL,                    /* Caption */
                NULL,        /* Style */
                CW_USEDEFAULT,              /* Initial x (use default) */
                CW_USEDEFAULT,              /* Initial y (use default) */
                CW_USEDEFAULT,              /* Initial x size (use default) */
                CW_USEDEFAULT,              /* Initial y size (use default) */
                HWND_MESSAGE,                       /* No parent window */
                NULL,                       /* No menu */
                hInst,                      /* This program instance */
                NULL                        /* Creation parameters */
                );
       
        ShowWindow (hwndMain, SW_SHOW);
        UpdateWindow (hwndMain);

	if (!init_raw_mouse(1, 0, 1,hwndMain)) { // registers for (sysmouse=yes,  terminal services mouse=no, HID_mice=yes)
	  MessageBox(NULL, L"RawInput not supported by Operating System.  Exiting." , L"Error!" ,MB_OK);
	  return 0; 
	}
        while (GetMessage (&msg, NULL, 0, 0))
        {
                TranslateMessage (&msg);
                DispatchMessage (&msg);
        }

	/* deallocate rawmouse stuff */
	destroy_raw_mouse();

    return msg.wParam;
}