Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在c语言中向其他应用程序发送快捷命令#_C#_.net_Wpf_Pywin32_User32 - Fatal编程技术网

C# 在c语言中向其他应用程序发送快捷命令#

C# 在c语言中向其他应用程序发送快捷命令#,c#,.net,wpf,pywin32,user32,C#,.net,Wpf,Pywin32,User32,您好,我正在用c语言开发一个应用程序(A),该应用程序将使用在后台以试用模式运行的其他应用程序(B)。我想通过按下应用程序(A)上的按钮,从应用程序(A)向应用程序(B)发送一些快捷命令。按钮后面有以下代码: [DllImport("user32.dll")] public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("user32.dll")] // public st

您好,我正在用c语言开发一个应用程序(A),该应用程序将使用在后台以试用模式运行的其他应用程序(B)。我想通过按下应用程序(A)上的按钮,从应用程序(A)向应用程序(B)发送一些快捷命令。按钮后面有以下代码:

[DllImport("user32.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
// public static extern IntPtr FindWindowEx(IntPtr handleParent, IntPtr handleChild, string className, string WindowName);


[DllImport("user32.dll")]
public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);

public const int WM_SYSCOMMAND = 0x0112;
public const int SC_CLOSE = 0xF060;
public const int WM_KEYDOWN = 0x0102;
public const int VK_SHIFT=10;
public const int VK_A = 0x41;

public void sendShortcutsToOneScreenConnect()
{
     Process[] process1 = Process.GetProcessesByName("NameOfTheProcess");
     process1[0].WaitForInputIdle();
     IntPtr handler = FindWindow(null,"Tittle Of The Window ");
     SendMessage(handler, WM_KEYDOWN, VK_A, VK_SHIFT);          
}

我正在获取此窗口的“0”处理程序。有人能告诉我这是正确的方法吗?我不想让应用程序(B)窗口出现在前台。

FindWindow部分看起来不错-验证窗口的标题是否正确。应用程序B是您开发的另一个应用程序,如果在其中嵌入WCF服务,则可以很容易地从应用程序a运行任何远程命令。