C # Control Other programs

Source: Internet
Author: User

[DllImport ("user32.dll", EntryPoint = "FindWindow", SetLastError = True)]
private static extern IntPtr FindWindow (string lpclassname, string lpwindowname);

[DllImport ("user32.dll", EntryPoint = "FindWindowEx", SetLastError = True)]
private static extern IntPtr FindWindowEx (IntPtr hwndparent, uint hwndchildafter, String lpszclass, string lpszwindow);

[DllImport ("user32.dll", EntryPoint = "SendMessage", SetLastError = true, CharSet = CharSet.Auto)]
private static extern int SendMessage (INTPTR hwnd, uint wmsg, int wParam, int lParam);

[DllImport ("user32.dll", EntryPoint = "SetForegroundWindow", SetLastError = True)]
private static extern void SetForegroundWindow (INTPTR hwnd);


private void Button1_Click (object sender, EventArgs e)
{
var hwndphoto = FindWindow (null, "XMind"); Find the handle to the camera program "Application name in Task Manager"

if (Hwndphoto! = IntPtr.Zero)
{
SetForegroundWindow (Hwndphoto); Set the Ucdemo program as the current active window
Sendkeys.send ("^o");
Clipboard.setdataobject (@ "D:\ thought map \ Document \ Basic Data transformation. Xmind");
System.Threading.Thread.Sleep (200); Pause 500 milliseconds
Sendkeys.send ("^v");
System.Threading.Thread.Sleep (200); Pause 500 milliseconds
Sendkeys.send ("~");
System.Threading.Thread.Sleep (500); Pause 500 milliseconds
Sendkeys.send ("^p");
System.Threading.Thread.Sleep (200); Pause 500 milliseconds
Sendkeys.send ("~");
}
Else
{
MessageBox.Show ("No Boot XMind");
}
}

C # Control Other programs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.