简体   繁体   English

我如何以编程方式使用C#代码中的Aero捕捉功能

[英]How can i programmatically use aero snap features from C# code

I have a simple question. 我有一个简单的问题。 How can I access aero snap programmatically from my C# code. 如何从C#代码以编程方式访问aero snap。 Like, if I click a button "Snap Left", I want my program window to snap to the left, just like when its drug over there manually. 就像,如果我单击“向左对齐”按钮,我希望程序窗口向左对齐,就像手动将药物停在那儿一样。 I looked all over SO, but all the questions seem to be about aero snap not working with a form, and keeping it from snapping a form. 我到处都是,但是所有的问题似乎都与aero snap不与表单一起工作,并阻止它捕捉表单有关。 Not programmatically snapping a form. 没有以编程方式对齐表格。 I'm happy to use interloping. 我很高兴使用插值。 Thanks 谢谢

What you can do, assuming you are on Windows 7, is to send the AreoSnap Keypress to the currently active window. 假设您使用的是Windows 7,您可以做的是将AreoSnap按键发送到当前活动的窗口。

This codeproject has a very nice article on doing just that. 代码项目中有一篇非常不错的文章。

Also check out this SO question. 还要检查这个 SO问题。

It seems that one way to do this is use sendmessage in User32.dll. 似乎执行此操作的一种方法是在User32.dll中使用sendmessage

Here is an example of this, assuming "notepad" is the program you want to send the keystroke to: 这是一个示例,假设“记事本”是您要将按键发送到的程序:

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

我还需要这样做,并且发现Windows Input Simulator非常有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM