FULL LIST OF AVAILABLE FUNCTIONS ON MSDN:
http://msdn.microsoft.com/en-us/library/dd469351(VS.85).aspx

SetCursorPos – Move and Click Mouse Cursor

Move the cursor postion to somewhere, relative to top left corner of screen

Outside of function / in header file:

	[DllImport("user32.dll")]
	static bool SetCursorPos(int X, int Y);

	[DllImport("user32.dll")]
	static void mouse_event(unsigned int dwFlags, unsigned int dx, unsigned int dy, unsigned int dwData,  int dwExtraInfo);
In function:

	SetCursorPos(1370,900);
	mouse_event(0x02,0,0,0,0);		//Left mouse button down
	mouse_event(0x04,0,0,0,0);		//Left mouse button up

Get Handle To An Application


using namespace System::Diagnostics
	Dim NoteProc() As Process = Process.GetProcessesByName("notepad") 'Get Notepad's handle

	array
 ^Processes1 =  Process::GetProcesses();

GetForegroundWindow

(Which window has user focus)


	[System::Runtime::InteropServices::DllImport(L"user32.dll")]
	static System::IntPtr GetForegroundWindow();

	//Check if some process we started has been selected
	System::IntPtr WinHandle = GetForegroundWindow();
	if (WinHandle == SomeProcess->MainWindowHandle)

IsWindowVisible


	[System::Runtime::InteropServices::DllImport(L"user32.dll")]
	static bool IsWindowVisible(System::IntPtr hWnd);

	if (IsWindowVisible(IndigoProcess->MainWindowHandle))

MoveWindow – Move Window / Set Size


	[System::Runtime::InteropServices::DllImport(L"user32.dll")]
	static bool MoveWindow(System::IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
	//See also GetWindowPos and SetWindowPos

Source link: http://www.codeguru.com/forum/showthread.php?p=1738737&mode=linear#post1738737

PostMessage – Click A Button On Another Applications Form


	//If the PostMessage function fails, the return value is zero (Chekc if we want to)
	int Xposn = 0;
	int Yposn = 0;
	PostMessage(
		SomeProcess->MainWindowHandle,	//hWnd - Handle to the window whose window procedure is to receive the message (we opened this process so we alreay know it)
		273,			//Msg - Specifies the message to be posted
		0x80ff,		//wParam - Specifies additional message-specific information (Control ID of the Synchronise button | (BN_CLICKED = 0))
		((Yposn * 0x10000) + Xposn));		//lParam - Specifies additional message-specific information

//GETTING THE CONTROL ID OF THE SYNCHRONISE BUTTON
//There is a property called a Control ID. This is the ID of the control and doesnt change.
//Run SPY++ from VS Tool Menu.  Run Control Centre.
//Right Click > Refresh SPY++
//Menu > Search > Find Window
//Click and hold the finder tool target button and drag it onto the applications control you want the ID of
//Click OK.  You are taken to the controls class in the class list.  Right click > Properties
//The controls 'Control ID' is shown in the general tab.  In the above example its 0x80ff.

Good resources:
http://www.autohotkey.com/docs/misc/SendMessage.htm
http://www.voidnish.com/articles/ShowArticle.aspx?code=ShellTrayInfo

SetForegroundWindow

(For window to be user focus)


	[System::Runtime::InteropServices::DllImport(L"user32.dll")]
	static bool SetForegroundWindow(System::IntPtr  hWnd);

SendKeys – Send Keystrokes

The SendKeys calss can be used to send keystrokes to the currently active window


	SendKeys::Send("{F12}");
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *