Jump to content

CMouse - Win32 C Mouse Coordinates Notifier

- - - - -

  • Please log in to reply
No replies to this topic

#1
RhetoricalRuvim

RhetoricalRuvim

    JavaScript Programmer

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,254 posts
  • Location:C:\Countries\US
This program can be used to determine the current X and Y coordinates of the mouse cursor. It uses hotkeys for user input. CMouse is what I decided to call it; the 'c' in 'cmouse' stands for 'coordinates' .

Here are the available hotkeys:
  • Ctrl + Alt + C Display a message box with the coordinates of where the mouse is at right now.
  • Ctrl + Alt + E Exit the CMouse program.

You can also modify the 'c_notify' and 'c_exit' #defines, to alter the shortcut key used for the functions.

Here's the source code:
// Copyring (C) 2011 By RhetoricalRuvim 

// Program:  CMouse 


#include <windows.h> 

#include <stdio.h> 


#define KEY_NOTIFY 1 

#define KEY_FINISH 2 


#define c_notify    'C' 

#define c_exit      'E' 


int WinMain (HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR CmdLine, int CmdShow){ 

	POINT mouse; 

	char string1 [512]; 

	LRESULT result; 

	MSG msg; 

	if ( RegisterHotKey (0, KEY_NOTIFY, MOD_CONTROL | MOD_ALT, (UINT)(c_notify)) * RegisterHotKey (0, KEY_FINISH, MOD_CONTROL | MOD_ALT, (UINT)(c_exit)) ){ 

		while (GetMessage (&msg, 0, 0, 0)){ 

			if (msg.message == WM_HOTKEY){ 

				if (msg.wParam == KEY_NOTIFY){ 

					GetCursorPos (&mouse); 

					sprintf (string1, "Current Cursor Position:  (%d, %d)", mouse.x, mouse.y); 

					MessageBoxA (0, string1, "Cursor Coordinates - CMouse", MB_OK | MB_SETFOREGROUND); 

				} else if (msg.wParam == KEY_FINISH){ 

					ReplyMessage (0); 

					break; 

				} else { 

					// Nothing... 

				} 

				result= 0; 

			} else if (msg.message == WM_CLOSE){ 

				ReplyMessage (0); 

				break; 

			} else { 

				// Nothing... 

				result= 0; 

			} 

			ReplyMessage (result); 

		} 

	} else { 

		MessageBoxA (0, "Error:  Could not register hotkeys. ", "Error - CMouse", MB_OK | MB_SETFOREGROUND); 

	} 

	UnregisterHotKey (0, KEY_NOTIFY); 

	UnregisterHotKey (0, KEY_FINISH); 

	ExitProcess (0); 

} 






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users