如何以编程方式使用C#代码中的aero snap功能

时间:2012-11-11 21:28:21

标签: c# winforms operating-system aero-snap

我有一个简单的问题。如何从我的C#代码以编程方式访问aero snap。就像,如果我单击“Snap Left”按钮,我希望我的程序窗口向左侧拍摄,就像手动上它的药物一样。我看起来都是如此,但所有的问题似乎都是关于aero snap不使用表单,并防止它捕捉表单。不是以编程方式捕捉表单。我很高兴使用interloping。感谢

2 个答案:

答案 0 :(得分:6)

假设您使用的是Windows 7,您可以将AreoSnap Keypress发送到当前活动的窗口。

This codeproject有一篇关于这样做的非常好的文章。

同时查看this问题。

似乎有一种方法是在User32.dll中使用sendmessage

以下是一个示例,假设“记事本”是您要将击键发送到的程序:

[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);
    }
}

答案 1 :(得分:1)

我还需要这样做,发现Windows Input Simulator非常有帮助。

相关问题