public static void ClickCommon(IntPtr Parent, IntPtr Handle, int X, int Y) { if (!NM.IsWindowVisible(Handle)) { throw new Exception("Window is not visible"); } if (!NM.IsWindowEnabled(Handle)) { throw new Exception("Window is not enabled"); } IntPtr ActualParent; if (Parent == IntPtr.Zero) { ActualParent = Handle; } else { ActualParent = Parent; } if (NM.IsIconic(ActualParent)) { throw new Exception("Window is minimised"); } if (!ActiveWindow(ActualParent)) { SetFocus(Parent, Handle); } else { NM.BringWindowToTop(ActualParent); } NM.tagPoint thePoint = MouseMove(Handle, X, Y); IntPtr WindowAtPoint = NM.WindowFromPoint(thePoint); if (WindowAtPoint != Handle) { throw new Exception("Window is obscured"); } }
//TODO remove theses and replace with above so we get better error messages private static void WaitToBeVisibleAndEnabled(IntPtr handle) { Stopwatch timer = Stopwatch.StartNew(); while (true) { if (timer.ElapsedMilliseconds > GUI.GetTimeOut()) { throw new Exception("Control is not enabled"); } if (NM.IsWindowEnabled(handle)) { if (NM.IsWindowVisible(handle)) { break; } } } timer.Stop(); }
private static void WaitToBeVisibleAndEnabled(GUIObject control) { Stopwatch timer = Stopwatch.StartNew(); while (true) { if (timer.ElapsedMilliseconds > GUI.GetTimeOut()) { throw new Exception(control.Description + " is not enabled"); } if (NM.IsWindowEnabled(control.Handle)) { if (NM.IsWindowVisible(control.Handle)) { break; } } } timer.Stop(); }
/// <summary> /// Waits for the handler to set the m_GenericWalkerControl variable to true then removes the handler /// </summary> /// <param name="ptrMessage">A pointer to the message</param> unsafe private void WaitForAndRemoveGenericWalkerSelectedHandler(Message *ptrMessage) { if (m_GenericWalkerControl != null) { try { Stopwatch timer = Stopwatch.StartNew(); while (true) { if (m_GenericWalkerSelected || m_GenericWalkerControl.Disposing || m_GenericWalkerControl.IsDisposed) { break; } if (!NM.IsWindowEnabled(m_GenericWalkerParent)) { //parent not enabled so probably a modal popup displayed so break out the loop break; } if (timer.ElapsedMilliseconds > m_TimeOut) { throw new Exception("Failed to find generic walker selected event"); } Thread.Sleep(15); } } finally { m_GenericWalkerSelectedEventInfo.RemoveEventHandler(m_GenericWalkerControl, m_GenericWalkerSelectedHandler); m_GenericWalkerControl = null; m_GenericWalkerParent = IntPtr.Zero; } } CleanUpMessage(ptrMessage); }
/// <summary> /// Waits for the handler to set the m_ToolStripItemEntered variable to true then removes the handler /// </summary> /// <param name="ptrMessage">A pointer to the message</param> unsafe private void WaitForAndRemoveToolStripItemEnteredHandler(Message *ptrMessage) { if (m_ToolStripItemControl != null) { try { Stopwatch timer = Stopwatch.StartNew(); while (true) { if (m_ToolStripItemEntered || m_ToolStripItemControl.IsDisposed) { break; } if (!NM.IsWindowEnabled(m_ToolStripControlHandle)) { //toolstrip not enabled so probably a modal popup displayed so break out the loop break; } if (timer.ElapsedMilliseconds > m_TimeOut) { throw new Exception("Failed to find toolstrip item entered event"); } Thread.Sleep(15); } } finally { m_ToolStripItemEnteredEventInfo.RemoveEventHandler(m_ToolStripItemControl, m_ToolStripItemEnteredHandler); m_ToolStripItemControl = null; m_ToolStripControlHandle = IntPtr.Zero; } } CleanUpMessage(ptrMessage); }