我有一個窗體,其中有各種按鈕和麪板。我有一個按鈕,當按下按鈕時會對某些值執行檢查,如果檢查通過,我需要鼠標單擊以通過窗體下落並打到應用程序窗口下面的任何按鈕。點擊通過表單上的條件
被按下後,按鈕,檢查已通過什麼我目前做的是,我的表格設置爲透明使用:
[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