Fro*_*ire 2 c# operating-system winforms aero-snap
我有一个简单的问题.如何从我的C#代码以编程方式访问aero snap.就像,如果我单击"Snap Left"按钮,我希望我的程序窗口向左侧拍摄,就像它手动放在那里的药物一样.我看起来都是如此,但所有的问题似乎都是关于aero snap不使用表单,并防止它捕捉表单.不是以编程方式捕捉表单.我很高兴使用interloping.谢谢
假设您使用的是Windows 7,则可以将AreoSnap Keypress发送到当前活动的窗口.
这个代码项目有一篇关于这样做的非常好的文章.
另请查看此 SO问题.
似乎有一种方法是sendmessage在User32.dll中使用它.
下面是一个例子,假设"notepad"是你要发送键击的程序:
[DllImport("user32.dll", EntryPoint = "FindWindowEx")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("User32.dll")]
public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, string lParam);
private void button1_Click(object sender, EventArgs e)
{
Process [] notepads=Process.GetProcessesByName("notepad");
if(notepads.Length==0)return;
if (notepads[0] != null)
{
IntPtr child= FindWindowEx(notepads[0].MainWindowHandle, new IntPtr(0), "Edit", null);
SendMessage(child, 0x000C, 0, textBox1.Text);
}
}
Run Code Online (Sandbox Code Playgroud)