{"id":504,"date":"2011-01-06T19:39:05","date_gmt":"2011-01-06T19:39:05","guid":{"rendered":"https:\/\/ibex.tech\/visualcpp\/?p=504"},"modified":"2022-02-17T06:24:04","modified_gmt":"2022-02-17T06:24:04","slug":"manipulating-other-applications","status":"publish","type":"post","link":"https:\/\/ibex.tech\/visualcpp\/application-control\/manipulating-other-applications","title":{"rendered":"Manipulating Other Applications"},"content":{"rendered":"<p>FULL LIST OF AVAILABLE FUNCTIONS ON MSDN:<br \/>\n<a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/dd469351(VS.85).aspx\"> http:\/\/msdn.microsoft.com\/en-us\/library\/dd469351(VS.85).aspx<\/a><\/p>\n<h4>SetCursorPos &#8211; Move and Click Mouse Cursor<\/h4>\n<p>Move the cursor postion to somewhere, relative to top left corner of screen<\/p>\n<h5>Outside of function \/ in header file:<\/h5>\n<pre><code>\r\n\t[DllImport(\"user32.dll\")]\r\n\tstatic bool SetCursorPos(int X, int Y);\r\n\r\n\t[DllImport(\"user32.dll\")]\r\n\tstatic void mouse_event(unsigned int dwFlags, unsigned int dx, unsigned int dy, unsigned int dwData,  int dwExtraInfo);\r\n<\/code><\/pre>\n<h5>In function:<\/h5>\n<pre><code>\r\n\tSetCursorPos(1370,900);\r\n\tmouse_event(0x02,0,0,0,0);\t\t\/\/Left mouse button down\r\n\tmouse_event(0x04,0,0,0,0);\t\t\/\/Left mouse button up\r\n<\/code><\/pre>\n<h4>Get Handle To An Application<\/h4>\n<pre><code>\r\nusing namespace System::Diagnostics\r\n\tDim NoteProc() As Process = Process.GetProcessesByName(\"notepad\") 'Get Notepad's handle\r\n\r\n\tarray\r\n ^Processes1 =  Process::GetProcesses();\r\n<\/code><\/pre>\n<h4>GetForegroundWindow<\/h4>\n<p>(Which window has user focus)<\/p>\n<pre><code>\r\n\t[System::Runtime::InteropServices::DllImport(L\"user32.dll\")]\r\n\tstatic System::IntPtr GetForegroundWindow();\r\n\r\n\t\/\/Check if some process we started has been selected\r\n\tSystem::IntPtr WinHandle = GetForegroundWindow();\r\n\tif (WinHandle == SomeProcess-&gt;MainWindowHandle)\r\n<\/code><\/pre>\n<h4>IsWindowVisible<\/h4>\n<pre><code>\r\n\t[System::Runtime::InteropServices::DllImport(L\"user32.dll\")]\r\n\tstatic bool IsWindowVisible(System::IntPtr hWnd);\r\n\r\n\tif (IsWindowVisible(IndigoProcess-&gt;MainWindowHandle))\r\n<\/code><\/pre>\n<h4>MoveWindow &#8211; Move Window \/ Set Size<\/h4>\n<pre><code>\r\n\t[System::Runtime::InteropServices::DllImport(L\"user32.dll\")]\r\n\tstatic bool MoveWindow(System::IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);\r\n\t\/\/See also GetWindowPos and SetWindowPos\r\n<\/code><\/pre>\n<p>Source link: http:\/\/www.codeguru.com\/forum\/showthread.php?p=1738737&amp;mode=linear#post1738737<\/p>\n<h4>PostMessage &#8211; Click A Button On Another Applications Form<\/h4>\n<pre><code>\r\n\t\/\/If the PostMessage function fails, the return value is zero (Chekc if we want to)\r\n\tint Xposn = 0;\r\n\tint Yposn = 0;\r\n\tPostMessage(\r\n\t\tSomeProcess-&gt;MainWindowHandle,\t\/\/hWnd - Handle to the window whose window procedure is to receive the message (we opened this process so we alreay know it)\r\n\t\t273,\t\t\t\/\/Msg - Specifies the message to be posted\r\n\t\t0x80ff,\t\t\/\/wParam - Specifies additional message-specific information (Control ID of the Synchronise button | (BN_CLICKED = 0))\r\n\t\t((Yposn * 0x10000) + Xposn));\t\t\/\/lParam - Specifies additional message-specific information\r\n\r\n\/\/GETTING THE CONTROL ID OF THE SYNCHRONISE BUTTON\r\n\/\/There is a property called a Control ID. This is the ID of the control and doesnt change.\r\n\/\/Run SPY++ from VS Tool Menu.  Run Control Centre.\r\n\/\/Right Click &gt; Refresh SPY++\r\n\/\/Menu &gt; Search &gt; Find Window\r\n\/\/Click and hold the finder tool target button and drag it onto the applications control you want the ID of\r\n\/\/Click OK.  You are taken to the controls class in the class list.  Right click &gt; Properties\r\n\/\/The controls 'Control ID' is shown in the general tab.  In the above example its 0x80ff.\r\n<\/code><\/pre>\n<p>Good resources:<br \/>\nhttp:\/\/www.autohotkey.com\/docs\/misc\/SendMessage.htm<br \/>\nhttp:\/\/www.voidnish.com\/articles\/ShowArticle.aspx?code=ShellTrayInfo<\/p>\n<h4>SetForegroundWindow<\/h4>\n<p>(For window to be user focus)<\/p>\n<pre><code>\r\n\t[System::Runtime::InteropServices::DllImport(L\"user32.dll\")]\r\n\tstatic bool SetForegroundWindow(System::IntPtr  hWnd);\r\n<\/code><\/pre>\n<h4>SendKeys &#8211; Send Keystrokes<\/h4>\n<p>The SendKeys calss can be used to send keystrokes to the currently active window<\/p>\n<pre><code>\r\n\tSendKeys::Send(\"{F12}\");\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>FULL LIST OF AVAILABLE FUNCTIONS ON MSDN: http:\/\/msdn.microsoft.com\/en-us\/library\/dd469351(VS.85).aspx SetCursorPos &#8211; 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(&#8220;user32.dll&#8221;)] static bool SetCursorPos(int X, int Y); [DllImport(&#8220;user32.dll&#8221;)] static void mouse_event(unsigned int dwFlags, unsigned int dx, unsigned int dy, unsigned [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-504","post","type-post","status-publish","format-standard","hentry","category-application-control"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/504","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/comments?post=504"}],"version-history":[{"count":1,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/504\/revisions"}],"predecessor-version":[{"id":505,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/504\/revisions\/505"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/media?parent=504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/categories?post=504"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/tags?post=504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}