我有一个窗体,其中有各种按钮和面板。我有一个按钮,当按下按钮时会对某些值执行检查,如果检查通过,我需要鼠标单击以通过窗体下落并打到应用程序窗口下面的任何按钮。点击通过表单上的条件
被按下后,按钮,检查已通过什么我目前做的是,我的表格设置为透明使用:
[DllImport("user32.dll", SetLastError = true)]
static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
private int oldWindowLong = 0;
public void SetFormTransparent(IntPtr Handle)
{
oldWindowLong = GetWindowLong(Handle, -20);
SetWindowLong(Handle, -20, Convert.ToInt32(oldWindowLong | 0x80000 | 0x20));
}
public void SetFormNormal(IntPtr Handle)
{
SetWindowLong(Handle, -20, Convert.ToInt32(oldWindowLong | 0x80000));
}
然后我创建了一个1毫秒定时器,我模拟鼠标点击使用:
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);
并将窗体设置恢复正常。这导致了一个非常不一致,有时缓慢/无反应的行为。
如果我想在按钮检查通过后模拟鼠标点击,还有其他选择吗?
只要窗口有一个父窗口,或者是一个拥有的窗口,那么你可以[使用这个](http://stackoverflow.com/a/7692496/17034)。 –
你好,感谢您的链接,这对我来说很有用。不过,我的窗户不属于另一个窗户。这是根源,我需要点击才能通过它并击中其他应用程序或其下的桌面。 – Footch