Example #1
0
        /// <summary>
        /// Gets the parameters from the message then adds a mouse hook to the specified thread
        /// </summary>
        /// <param name="ptrMessage">A pointer to the message</param>
        /// <param name="messageNumber">The message number</param>
        private unsafe void AddMouseHook(Message *ptrMessage, int messageNumber)
        {
            if (messageNumber != 1)
            {
                throw new Exception("AddMouseHook must be the first message");
            }

            IntPtr handle = GetParameterIntPtr(ptrMessage, 0);

            CleanUpMessage(ptrMessage);

            int threadId = NM.GetWindowThreadProcessId(handle, IntPtr.Zero);

            m_HookWindow = handle;

            // Add the mouse hook
            DebugLogging.WriteLog("Adding Mouse hook");
            m_hMouseHook = NM.SetWindowsHookEx(NM.WH_MOUSE, MouseHookProcedure, IntPtr.Zero, threadId);
            if (m_hMouseHook == 0)
            {
                throw new Exception("SetWindowsHookEx failed to add mouse hook");
            }
            DebugLogging.WriteLog("Added Mouse hook");

            ClearMouseState();
        }
Example #2
0
        /// <summary>
        /// Gets the parameters from the message then removes the mouse hook on the specified thread
        /// </summary>
        /// <param name="ptrMessage">A pointer to the message</param>
        /// <param name="messageNumber">The message number</param>
        private unsafe void RemoveMouseHook(Message *ptrMessage, int messageNumber)
        {
            try
            {
                if (messageNumber != 1)
                {
                    throw new Exception("RemoveMouseHook must be the first message");
                }

                IntPtr handle = GetParameterIntPtr(ptrMessage, 0);;
                CleanUpMessage(ptrMessage);

                // Remove the hook
                DebugLogging.WriteLog("Removing Mouse hook");
                bool returnValue = NM.UnhookWindowsHookEx(m_hMouseHook);
                if (!returnValue)
                {
                    string errorMessage = null;
                    bool   ignoreFailedToUnhook;

                    if (Marshal.GetLastWin32Error() == 0)
                    {
                        ignoreFailedToUnhook = true;
                    }
                    else
                    {
                        ignoreFailedToUnhook = false;
                        errorMessage         = new Win32Exception(Marshal.GetLastWin32Error()).Message;
                    }

                    if (!ignoreFailedToUnhook)
                    {
                        throw new Exception("UnhookWindowsHookEx Failed for Mouse hook: " + errorMessage);
                    }
                }
            }
            finally
            {
                m_hMouseHook = 0;
                ClearMouseState();
                DebugLogging.WriteLog("Removed Mouse hook");
            }
        }
Example #3
0
        /// <summary>
        /// Gets the parameters from the message then waits for the desired mouse button messages to arrive
        /// </summary>
        /// <param name="ptrMessage">A pointer to the message</param>
        /// <param name="messageNumber">The message number</param>
        private unsafe void WaitForMouseMove(Message *ptrMessage, int messageNumber)
        {
            if (messageNumber != 1)
            {
                throw new Exception("WaitForMouseState must be the first message");
            }

            int screenXParameter = GetParameterInt32(ptrMessage, 0);
            int screenYParameter = GetParameterInt32(ptrMessage, 1);

            CleanUpMessage(ptrMessage);
            Stopwatch timer = Stopwatch.StartNew();

            DebugLogging.WriteLog("Waiting on mouse move " + screenXParameter.ToString() + ", " + screenYParameter.ToString());

            try
            {
                while (true)
                {
                    if (m_WM_MouseMove_ScreenX <= screenXParameter + 1 && m_WM_MouseMove_ScreenX >= screenXParameter - 1)
                    {
                        if (m_WM_MouseMove_ScreenY <= screenYParameter + 1 && m_WM_MouseMove_ScreenY >= screenYParameter - 1)
                        {
                            break;
                        }
                    }

                    Thread.Sleep(15);

                    if (timer.ElapsedMilliseconds > m_TimeOut)
                    {
                        //throw new Exception("Want: " + screenXParameter.ToString() + ", " + screenYParameter.ToString() + " got: " + m_WM_MouseMove_ScreenX.ToString() + ", " + m_WM_MouseMove_ScreenY.ToString());
                        throw new Exception("Failed to find Mouse Move");
                    }
                }
            }
            finally
            {
                ClearMouseState();
            }

            DebugLogging.WriteLog("Mouse Move done");
        }
Example #4
0
        /// <summary>
        /// Callback that is called after the mouse hook has been installed when the thread recieves a mouse message
        /// </summary>
        /// <param name="nCode">A code that the hook procedure uses to determine how to process the message</param>
        /// <param name="wParam">The identifier of the mouse message</param>
        /// <param name="lParam">A pointer to a MOUSEHOOKSTRUCT structure</param>
        /// <returns>Value returned by CallNextHookEx</returns>
        public int MouseHookProc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode < 0)
            {
                return(NM.CallNextHookEx(m_hMouseHook, nCode, wParam, lParam));
            }
            else
            {
                NM.MouseHookStruct MyMouseHookStruct = (NM.MouseHookStruct)Marshal.PtrToStructure(lParam, typeof(NM.MouseHookStruct));

                if (MyMouseHookStruct.hwnd == m_HookWindow)
                {
                    if (nCode == NM.HC_ACTION)
                    {
                        switch (wParam.ToInt32())
                        {
                        case NM.WM_LBUTTONDOWN:
                            DebugLogging.WriteLog("Left Down " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            m_WM_LBUTTONDOWN = true;
                            break;

                        case NM.WM_NCLBUTTONDOWN:
                            DebugLogging.WriteLog("NCLeft Down " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            m_WM_LBUTTONDOWN = true;
                            break;

                        case NM.WM_LBUTTONUP:
                            DebugLogging.WriteLog("Left Up " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            m_WM_LBUTTONUP = true;
                            break;

                        case NM.WM_NCLBUTTONUP:
                            DebugLogging.WriteLog("NCLeft Up " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            m_WM_LBUTTONUP = true;
                            break;

                        case NM.WM_LBUTTONDBLCLK:
                            DebugLogging.WriteLog("Left Double " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            m_WM_LBUTTONDBLCLK = true;
                            break;

                        case NM.WM_NCLBUTTONDBLCLK:
                            DebugLogging.WriteLog("NCLeft Double " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            m_WM_LBUTTONDBLCLK = true;
                            break;

                        case NM.WM_RBUTTONDOWN:
                            DebugLogging.WriteLog("Right Down " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            m_WM_RBUTTONDOWN = true;
                            break;

                        case NM.WM_NCRBUTTONDOWN:
                            DebugLogging.WriteLog("NCRight Down " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            m_WM_RBUTTONDOWN = true;
                            break;

                        case NM.WM_RBUTTONUP:
                            DebugLogging.WriteLog("Right Up " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            m_WM_RBUTTONUP = true;
                            break;

                        case NM.WM_NCRBUTTONUP:
                            DebugLogging.WriteLog("NCRight Up " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            m_WM_RBUTTONUP = true;
                            break;

                        case NM.WM_RBUTTONDBLCLK:
                            DebugLogging.WriteLog("Right Double " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            m_WM_RBUTTONDBLCLK = true;
                            break;

                        case NM.WM_NCRBUTTONDBLCLK:
                            DebugLogging.WriteLog("NCRight Double " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            m_WM_RBUTTONDBLCLK = true;
                            break;

                        case NM.WM_MBUTTONDOWN:
                            DebugLogging.WriteLog("Middle Down " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            m_WM_MBUTTONDOWN = true;
                            break;

                        case NM.WM_NCMBUTTONDOWN:
                            DebugLogging.WriteLog("NCMiddle Down " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            m_WM_MBUTTONDOWN = true;
                            break;

                        case NM.WM_MBUTTONUP:
                            DebugLogging.WriteLog("Middle Up " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            break;

                        case NM.WM_NCMBUTTONUP:
                            DebugLogging.WriteLog("NCMiddle Up " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            m_WM_MBUTTONUP = true;
                            break;

                        case NM.WM_MBUTTONDBLCLK:
                            DebugLogging.WriteLog("Middle Double " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            m_WM_MBUTTONDBLCLK = true;
                            break;

                        case NM.WM_NCMBUTTONDBLCLK:
                            DebugLogging.WriteLog("NCMiddle Double " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                            m_WM_MBUTTONDBLCLK = true;
                            break;
                        }
                    }
                }
                return(NM.CallNextHookEx(m_hMouseHook, nCode, wParam, lParam));
            }
        }
Example #5
0
        /// <summary>
        /// Gets the parameters from the message then waits for the desired mouse messages to arrive
        /// </summary>
        /// <param name="ptrMessage">A pointer to the message</param>
        /// <param name="messageNumber">The message number</param>
        private unsafe void WaitForMouseState(Message *ptrMessage, int messageNumber)
        {
            if (messageNumber != 1)
            {
                throw new Exception("WaitForMouseState must be the first message");
            }

            MouseButton button     = (MouseButton)GetParameterInt32(ptrMessage, 0);
            bool        mouseDown  = GetParameterBoolean(ptrMessage, 1);
            bool        firstClick = GetParameterBoolean(ptrMessage, 2);

            CleanUpMessage(ptrMessage);
            Stopwatch timer = Stopwatch.StartNew();

            if (mouseDown)
            {
                DebugLogging.WriteLog("Waiting on " + button.ToString() + " mouse down");
            }
            else
            {
                DebugLogging.WriteLog("Waiting on " + button.ToString() + " mouse up");
            }

            try
            {
                bool done = false;
                while (!done)
                {
                    switch (button)
                    {
                    case MouseButton.Left:
                        if (mouseDown)
                        {
                            if (firstClick)
                            {
                                if (m_WM_LBUTTONDOWN)
                                {
                                    timer.Stop();
                                    return;
                                }
                            }
                            else
                            {
                                if (m_WM_LBUTTONDOWN || m_WM_LBUTTONDBLCLK)
                                {
                                    timer.Stop();
                                    return;
                                }
                            }
                        }
                        else
                        {
                            if (m_WM_LBUTTONUP)
                            {
                                timer.Stop();
                                return;
                            }
                        }
                        break;

                    case MouseButton.Right:
                        if (mouseDown)
                        {
                            if (firstClick)
                            {
                                if (m_WM_RBUTTONDOWN)
                                {
                                    timer.Stop();
                                    return;
                                }
                            }
                            else
                            {
                                if (m_WM_RBUTTONDOWN || m_WM_RBUTTONDBLCLK)
                                {
                                    timer.Stop();
                                    return;
                                }
                            }
                        }
                        else
                        {
                            if (m_WM_RBUTTONUP)
                            {
                                timer.Stop();
                                return;
                            }
                        }
                        break;

                    case MouseButton.Middle:
                        if (mouseDown)
                        {
                            if (firstClick)
                            {
                                if (m_WM_MBUTTONDOWN)
                                {
                                    timer.Stop();
                                    return;
                                }
                            }
                            else
                            {
                                if (m_WM_MBUTTONDOWN || m_WM_MBUTTONDBLCLK)
                                {
                                    timer.Stop();
                                    return;
                                }
                            }
                        }
                        else
                        {
                            if (m_WM_MBUTTONUP)
                            {
                                timer.Stop();
                                return;
                            }
                        }
                        break;
                    }

                    if (!done)
                    {
                        Thread.Yield();
                    }

                    if (timer.ElapsedMilliseconds > m_TimeOut)
                    {
                        timer.Stop();
                        if (mouseDown)
                        {
                            throw new Exception("Failed to find " + button.ToString() + " mouse down");
                        }
                        else
                        {
                            throw new Exception("Failed to find " + button.ToString() + " mouse up");
                        }
                    }
                }
            }
            finally
            {
                ClearMouseState();
            }

            DebugLogging.WriteLog("Mouse State done");
        }
Example #6
0
        unsafe public void ProcessMessages(int APEPID, string AppDomainToLoadInto)
        {
            m_ManagedThreadId = Thread.CurrentThread.ManagedThreadId;
            try
            {
                AUTProcess = Process.GetCurrentProcess();
                string AUTProcessId = AUTProcess.Id.ToString();
                string APEProcessId = APEPID.ToString();

                // Set the thread name so its easy to find in the debugger
                Thread.CurrentThread.Name = "APE_" + APEProcessId + "_" + AppDomainToLoadInto + "_" + AUTProcessId;

                m_HandleMemoryMappedFileStringStore      = NM.CreateFileMapping((IntPtr)(NM.INVALID_HANDLE_VALUE), (IntPtr)0, NM.FileMapProtection.PageReadWrite, 0, StringSpaceBytes, APEProcessId + "_String_" + AppDomainToLoadInto + "_" + AUTProcessId);
                m_IntPtrMemoryMappedFileViewStringStore  = NM.MapViewOfFile(m_HandleMemoryMappedFileStringStore, NM.FileMapAccess.FileMapAllAccess, 0, 0, (UIntPtr)StringSpaceBytes);
                m_HandleMemoryMappedFileMessageStore     = NM.CreateFileMapping((IntPtr)(NM.INVALID_HANDLE_VALUE), (IntPtr)0, NM.FileMapProtection.PageReadWrite, 0, (uint)sizeof(MessageStore), APEProcessId + "_Message_" + AppDomainToLoadInto + "_" + AUTProcessId);
                m_IntPtrMemoryMappedFileViewMessageStore = NM.MapViewOfFile(m_HandleMemoryMappedFileMessageStore, NM.FileMapAccess.FileMapAllAccess, 0, 0, (UIntPtr)sizeof(MessageStore));
                m_PtrMessageStore = (MessageStore *)m_IntPtrMemoryMappedFileViewMessageStore.ToPointer();

                m_eventIPC = new EventWaitHandle(false, EventResetMode.AutoReset, APEProcessId + "_EventIPC_" + AppDomainToLoadInto + "_" + AUTProcessId);

                Side = EventSet.AUT;
                try
                {
                    ApeProcess = Process.GetProcessById(APEPID);
                }
                catch
                {
                }

                // Setup the hook procedures
                SetupmouseHelperHooks();
                EnumThreadProcedue = new NM.EnumWindow(EnumThreadCallback);

                // Setup the delegates
                m_GetWPFHandleAndNameAndTitleDelegater = new GetWPFHandleAndNameAndTitleDelegate(GetWPFHandleAndNameAndTitle);
                m_ConvertTypeDelegater = new ConvertTypeDelegate(Cast);
                m_GetTextDelegater     = new GetTextDelegate(GetText);
                m_GetAccessibilityObjectNameDelegater = new GetAccessibilityObjectNameDelegate(GetAccessibilityObjectName);
                SetupSentinelGridsHelperDelegates();
                SetupFlexgridHelperDelegates();
                SetupComHelperDelegates();
                SetupGridControlHelperDelegates();
                SetupFormHelperDelegates();
                SetupDictionaryHelperDelegates();
                SetupDataGridViewHelperDelegates();

                //Process all the messages
                while (true)
                {
                    WaitForMessages(EventSet.AUT);
                    if (m_Abort)
                    {
                        RemoveFileMapping();
                        break;
                    }

                    string result           = null;
                    int    messageNumber    = -1;
                    int    numberOfMessages = -1;

                    try
                    {
                        numberOfMessages = m_PtrMessageStore->NumberOfMessages;
                        m_PtrMessageStore->NumberOfMessages = 0;
                        m_StringStoreOffset = 0;

                        for (messageNumber = 1; messageNumber <= numberOfMessages; messageNumber++)
                        {
                            Message *ptrMessage = (Message *)(m_IntPtrMemoryMappedFileViewMessageStore + ((messageNumber - 1) * m_SizeOfMessage));

                            DebugLogging.WriteLog("Processing message " + ptrMessage->Action.ToString());
                            //get the message action:
                            switch (ptrMessage->Action)
                            {
                            case MessageAction.GetListViewGroupRectangle:
                                GetListViewGroupRectangle(messageNumber);
                                break;

                            case MessageAction.GetListViewItemRectangle:
                                GetListViewItemRectangle(messageNumber);
                                break;

                            case MessageAction.ControlExists:
                                string findText = Find(messageNumber, 0);
                                if (findText != null)
                                {
                                    ControlIdentifier newIdentifier = new ControlIdentifier();
                                    AddIdentifierMessage(newIdentifier);
                                }
                                break;

                            case MessageAction.Find:
                                result = Find(messageNumber, m_TimeOut);
                                break;

                            case MessageAction.RefindByHandle:
                                RefindByHandle(messageNumber);
                                break;

                            case MessageAction.RefindByUniqueId:
                                RefindByUniqueId(messageNumber);
                                break;

                            case MessageAction.ReflectGet:
                                Reflect(messageNumber);
                                break;

                            case MessageAction.ConvertType:
                                ConvertType(messageNumber);
                                break;

                            case MessageAction.SentinelGridsGetUnderlyingGrid:
                                SentinelGridsGetUnderlyingGrid(ptrMessage);
                                break;

                            case MessageAction.ReflectPoll:
                                ReflectPoll(messageNumber);
                                break;

                            case MessageAction.GetResult:
                                GetResult(messageNumber);
                                break;

                            case MessageAction.AddMouseHook:
                                AddMouseHook(ptrMessage, messageNumber);
                                break;

                            case MessageAction.RemoveMouseHook:
                                RemoveMouseHook(ptrMessage, messageNumber);
                                break;

                            case MessageAction.WaitForMouseState:
                                WaitForMouseState(ptrMessage, messageNumber);
                                break;

                            case MessageAction.SetTimeOuts:
                                SetTimeOuts(messageNumber);
                                break;

                            case MessageAction.GetTitleBarItemRectangle:
                                GetTitleBarItemRectangle(ptrMessage, messageNumber);
                                break;

                            case MessageAction.GarbageCollect:
                                GarbageCollect(ptrMessage, messageNumber);
                                break;

                            case MessageAction.GetContextMenuStrip:
                                GetContextMenuStrip(messageNumber);
                                break;

                            case MessageAction.GetAppDomains:
                                GetAppDomains(messageNumber);
                                break;

                            case MessageAction.GetRecognisedType:
                                GetRecognisedType(messageNumber);
                                break;

                            case MessageAction.GetApeTypeFromType:
                                GetApeTypeFromType(messageNumber);
                                break;

                            case MessageAction.GetApeTypeFromObject:
                                GetApeTypeFromObject(messageNumber);
                                break;

                            // Flexgrid helper methods
                            case MessageAction.FlexgridGetCellRangeBackColourName:
                                FlexgridGetCellRange(ptrMessage, CellProperty.BackColourName);
                                break;

                            case MessageAction.FlexgridGetCellRangeForeColourName:
                                FlexgridGetCellRange(ptrMessage, CellProperty.ForeColourName);
                                break;

                            case MessageAction.FlexgridGetCellRangeDataType:
                                FlexgridGetCellRange(ptrMessage, CellProperty.DataType);
                                break;

                            case MessageAction.FlexgridGetCellRangeCheckBox:
                                FlexgridGetCellRange(ptrMessage, CellProperty.CheckBox);
                                break;

                            case MessageAction.FlexgridGetCellRangeImage:
                                FlexgridGetCellRange(ptrMessage, CellProperty.Image);
                                break;

                            case MessageAction.FlexgridGetCellRangeBackgroundImage:
                                FlexgridGetCellRange(ptrMessage, CellProperty.BackgroundImage);
                                break;

                            case MessageAction.FlexgridGetAllColumnsHidden:
                                FlexgridGetAllColumnsHidden(ptrMessage);
                                break;

                            case MessageAction.FlexgridGetAllRowsHidden:
                                FlexgridGetAllRowsHidden(ptrMessage);
                                break;

                            case MessageAction.FlexgridGetAllColumnsWidth:
                                FlexgridGetAllColumnsWidth(ptrMessage);
                                break;

                            case MessageAction.FlexgridGetAllRowsHeight:
                                FlexgridGetAllRowsHeight(ptrMessage);
                                break;

                            case MessageAction.GridControlGetTitleRows:
                                GridControlGetTitleRows(ptrMessage);
                                break;

                            case MessageAction.GridControlGetTitleRowCount:
                                GridControlGetTitleRowCount(ptrMessage);
                                break;

                            case MessageAction.GridControlGetAllColumnsHidden:
                                GridControlGetAllColumnsVisible(ptrMessage);
                                break;

                            case MessageAction.GetDateTimePickerCheckboxRectangle:
                                GetDateTimePickerCheckboxRectangle(ptrMessage, messageNumber);
                                break;

                            case MessageAction.GetDateTimePickerButtonRectangle:
                                GetDateTimePickerButtonRectangle(ptrMessage, messageNumber);
                                break;

                            case MessageAction.ScrollControlIntoView:
                                ScrollControlIntoView(ptrMessage, messageNumber);
                                break;

                            case MessageAction.PeakMessage:
                                PeakMessage(ptrMessage, messageNumber);
                                break;

                            case MessageAction.SetFocus:
                                SetFocus(ptrMessage, messageNumber);
                                break;

                            case MessageAction.SetFocusAsync:
                                SetFocusAsync(ptrMessage, messageNumber);
                                break;

                            case MessageAction.GridControlEnsureTitleCellVisible:
                                GridControlEnsureTitleCellVisible(ptrMessage);
                                break;

                            case MessageAction.DictionaryContainsKey:
                                DictionaryContainsKey(ptrMessage);
                                break;

                            case MessageAction.AddMouseClickHandler:
                                AddMouseClickHandler(ptrMessage);
                                break;

                            case MessageAction.WaitForAndRemoveMouseClickHandler:
                                WaitForAndRemoveMouseClickHandler(ptrMessage);
                                break;

                            case MessageAction.RemoveMouseClickHandler:
                                RemoveMouseClickHandler(ptrMessage);
                                break;

                            case MessageAction.AddFlexgridCellChangedHandler:
                                AddFlexgridCellChangedHandler(ptrMessage);
                                break;

                            case MessageAction.WaitForAndRemoveFlexgridCellChangedHandler:
                                WaitForAndRemoveFlexgridCellChangedHandler(ptrMessage);
                                break;

                            case MessageAction.AddFlexgridAfterRowColChangeHandler:
                                AddFlexgridAfterRowColChangeHandler(ptrMessage);
                                break;

                            case MessageAction.WaitForAndRemoveFlexgridAfterRowColChangeHandler:
                                WaitForAndRemoveFlexgridAfterRowColChangeHandler(ptrMessage);
                                break;

                            case MessageAction.RemoveFlexgridAfterRowColChangeHandler:
                                RemoveFlexgridAfterRowColChangeHandler(ptrMessage);
                                break;

                            case MessageAction.AddGenericWalkerSelectedHandler:
                                AddGenericWalkerSelectedHandler(ptrMessage);
                                break;

                            case MessageAction.WaitForAndRemoveGenericWalkerSelectedHandler:
                                WaitForAndRemoveGenericWalkerSelectedHandler(ptrMessage);
                                break;

                            case MessageAction.RemoveGenericWalkerSelectedHandler:
                                RemoveGenericWalkerSelectedHandler(ptrMessage);
                                break;

                            case MessageAction.VisualStyleSupported:
                                VisualStyleSupported(ptrMessage, messageNumber);
                                break;

                            case MessageAction.DataGridViewShowCell:
                                DataGridViewShowCell(ptrMessage);
                                break;

                            case MessageAction.GetToolTip:
                                GetToolTip(ptrMessage, messageNumber);
                                break;

                            case MessageAction.DumpActiveX:
                                DumpActiveX(ptrMessage, messageNumber);
                                break;

                            case MessageAction.FlexgridGetNodeCollapsedState:
                                FlexgridGetNodeCollapsedState(ptrMessage);
                                break;

                            case MessageAction.GetTypeInformationActiveX:
                                GetTypeInformationActiveX(ptrMessage);
                                break;

                            case MessageAction.GetTabRect:
                                GetTabRect(ptrMessage);
                                break;

                            case MessageAction.GetInvokeFormActiveX:
                                GetInvokeFormActiveX(ptrMessage, messageNumber);
                                break;

                            case MessageAction.GetComboBoxExItemText:
                                GetComboBoxExItemText(ptrMessage, messageNumber);
                                break;

                            case MessageAction.WaitForMouseMove:
                                WaitForMouseMove(ptrMessage, messageNumber);
                                break;

                            case MessageAction.AddToolStripItemEnteredHandler:
                                AddToolStripItemEnteredHandler(ptrMessage);
                                break;

                            case MessageAction.WaitForAndRemoveToolStripItemEnteredHandler:
                                WaitForAndRemoveToolStripItemEnteredHandler(ptrMessage);
                                break;

                            case MessageAction.DumpControl:
                                DumpControl(ptrMessage, messageNumber);
                                break;

                            case MessageAction.FlexgridGetCellRangeTextDisplay:
                                FlexgridGetCellRange(ptrMessage, CellProperty.TextDisplay);
                                break;

                            case MessageAction.FlexgridGetCellRangeFontStyle:
                                FlexgridGetCellRange(ptrMessage, CellProperty.FontStyle);
                                break;

                            case MessageAction.FlexgridGetCellBackgroundImage:
                                FlexgridGetCellBackgroundImage(ptrMessage);
                                break;

                            default:
                                throw new Exception("Unknown action for message " + messageNumber.ToString() + " : " + ptrMessage->Action.ToString());
                            }

                            if (result != null)
                            {
                                break;
                            }
                        }

                        if (result == null)
                        {
                            AddResultMessage(MessageResult.Success);
                        }
                    }
                    catch (Exception ex)
                    {
                        result  = "Message " + messageNumber.ToString() + " of " + numberOfMessages + " failed:\r\n";
                        result += ex.GetType().Name + " " + ex.Message + "\r\n" + ex.StackTrace;
                        if (ex.InnerException != null)
                        {
                            //TODO make this better?
                            result += "\r\n" + ex.InnerException.GetType().Name + " " + ex.InnerException.Message + "\r\n" + ex.InnerException.StackTrace;
                        }
                    }

                    if (result != null)
                    {
                        //clean up all the messages
                        for (messageNumber = 1; messageNumber <= MessageStore.MaxMessages; messageNumber++)
                        {
                            Message *ptrMessage = (Message *)(m_IntPtrMemoryMappedFileViewMessageStore + ((messageNumber - 1) * m_SizeOfMessage));
                            CleanUpMessage(ptrMessage);
                        }

                        m_PtrMessageStore->NumberOfMessages = 0;
                        m_StringStoreOffset = 0;

                        AddResultMessage(MessageResult.Failure, result);
                    }

                    //clear the data stores so we don't hold any references to objects in the AUT
                    //which would stop them being garbage collected
                    if (tempStore0ReleaseComObject)
                    {
                        Marshal.ReleaseComObject(tempStore0);
                        tempStore0ReleaseComObject = false;
                    }
                    tempStore0 = null;
                    if (tempStore1ReleaseComObject)
                    {
                        Marshal.ReleaseComObject(tempStore1);
                        tempStore1ReleaseComObject = false;
                    }
                    tempStore1 = null;
                    if (tempStore2ReleaseComObject)
                    {
                        Marshal.ReleaseComObject(tempStore2);
                        tempStore2ReleaseComObject = false;
                    }
                    tempStore2 = null;
                    if (tempStore3ReleaseComObject)
                    {
                        Marshal.ReleaseComObject(tempStore3);
                        tempStore3ReleaseComObject = false;
                    }
                    tempStore3 = null;
                    if (tempStore4ReleaseComObject)
                    {
                        Marshal.ReleaseComObject(tempStore4);
                        tempStore4ReleaseComObject = false;
                    }
                    tempStore4 = null;
                    if (tempStore5ReleaseComObject)
                    {
                        Marshal.ReleaseComObject(tempStore5);
                        tempStore5ReleaseComObject = false;
                    }
                    tempStore5 = null;
                    if (tempStore6ReleaseComObject)
                    {
                        Marshal.ReleaseComObject(tempStore6);
                        tempStore6ReleaseComObject = false;
                    }
                    tempStore6 = null;
                    if (tempStore7ReleaseComObject)
                    {
                        Marshal.ReleaseComObject(tempStore7);
                        tempStore7ReleaseComObject = false;
                    }
                    tempStore7 = null;
                    if (tempStore8ReleaseComObject)
                    {
                        Marshal.ReleaseComObject(tempStore8);
                        tempStore8ReleaseComObject = false;
                    }
                    tempStore8 = null;
                    if (tempStore9ReleaseComObject)
                    {
                        Marshal.ReleaseComObject(tempStore9);
                        tempStore9ReleaseComObject = false;
                    }
                    tempStore9 = null;

                    //send back our response
                    SendMessages(EventSet.AUT);
                }
            }
            catch (Exception ex)
            {
                TextWriter log = File.AppendText(Environment.GetEnvironmentVariable("TEMP") + @"\critical.log");
                log.WriteLine(DateTime.Now.ToString() + "\t" + ex.Message);
                log.WriteLine(DateTime.Now.ToString() + "\t" + ex.StackTrace);
                log.Close();
                throw;
            }
        }
Example #7
0
        /// <summary>
        /// Callback that is called after the mouse hook has been installed when the thread recieves a mouse message
        /// </summary>
        /// <param name="nCode">A code that the hook procedure uses to determine how to process the message</param>
        /// <param name="wParam">The identifier of the mouse message</param>
        /// <param name="lParam">A pointer to a MOUSEHOOKSTRUCT structure</param>
        /// <returns>Value returned by CallNextHookEx</returns>
        public int MouseHookProc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode < 0)
            {
                return(NM.CallNextHookEx(m_hMouseHook, nCode, wParam, lParam));
            }
            else
            {
                NM.MouseHookStruct MyMouseHookStruct = (NM.MouseHookStruct)Marshal.PtrToStructure(lParam, typeof(NM.MouseHookStruct));

                //Check if the window or its parent recieved a mouse message (we check for a parent as they have a bad habit of eating some clicks)
                //if (MyMouseHookStruct.hwnd == m_HookWindow || NM.IsChild(MyMouseHookStruct.hwnd, m_HookWindow))
                //{
                if (nCode == NM.HC_ACTION)
                {
                    switch (wParam.ToInt32())
                    {
                    case NM.WM_MOUSEMOVE:
                    case NM.WM_NCMOUSEMOVE:
                        m_WM_MouseMove_ScreenX = MyMouseHookStruct.pt.x;
                        m_WM_MouseMove_ScreenY = MyMouseHookStruct.pt.y;
                        break;

                    case NM.WM_LBUTTONDOWN:
                        DebugLogging.WriteLog("Left Down " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        m_WM_LBUTTONDOWN = true;
                        break;

                    case NM.WM_NCLBUTTONDOWN:
                        DebugLogging.WriteLog("NCLeft Down " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        m_WM_LBUTTONDOWN = true;
                        break;

                    case NM.WM_LBUTTONUP:
                        DebugLogging.WriteLog("Left Up " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        m_WM_LBUTTONUP = true;
                        break;

                    case NM.WM_NCLBUTTONUP:
                        DebugLogging.WriteLog("NCLeft Up " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        m_WM_LBUTTONUP = true;
                        break;

                    case NM.WM_LBUTTONDBLCLK:
                        DebugLogging.WriteLog("Left Double " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        m_WM_LBUTTONDBLCLK = true;
                        break;

                    case NM.WM_NCLBUTTONDBLCLK:
                        DebugLogging.WriteLog("NCLeft Double " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        m_WM_LBUTTONDBLCLK = true;
                        break;

                    case NM.WM_RBUTTONDOWN:
                        DebugLogging.WriteLog("Right Down " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        m_WM_RBUTTONDOWN = true;
                        break;

                    case NM.WM_NCRBUTTONDOWN:
                        DebugLogging.WriteLog("NCRight Down " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        m_WM_RBUTTONDOWN = true;
                        break;

                    case NM.WM_RBUTTONUP:
                        DebugLogging.WriteLog("Right Up " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        m_WM_RBUTTONUP = true;
                        break;

                    case NM.WM_NCRBUTTONUP:
                        DebugLogging.WriteLog("NCRight Up " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        m_WM_RBUTTONUP = true;
                        break;

                    case NM.WM_RBUTTONDBLCLK:
                        DebugLogging.WriteLog("Right Double " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        m_WM_RBUTTONDBLCLK = true;
                        break;

                    case NM.WM_NCRBUTTONDBLCLK:
                        DebugLogging.WriteLog("NCRight Double " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        m_WM_RBUTTONDBLCLK = true;
                        break;

                    case NM.WM_MBUTTONDOWN:
                        DebugLogging.WriteLog("Middle Down " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        m_WM_MBUTTONDOWN = true;
                        break;

                    case NM.WM_NCMBUTTONDOWN:
                        DebugLogging.WriteLog("NCMiddle Down " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        m_WM_MBUTTONDOWN = true;
                        break;

                    case NM.WM_MBUTTONUP:
                        DebugLogging.WriteLog("Middle Up " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        break;

                    case NM.WM_NCMBUTTONUP:
                        DebugLogging.WriteLog("NCMiddle Up " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        m_WM_MBUTTONUP = true;
                        break;

                    case NM.WM_MBUTTONDBLCLK:
                        DebugLogging.WriteLog("Middle Double " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        m_WM_MBUTTONDBLCLK = true;
                        break;

                    case NM.WM_NCMBUTTONDBLCLK:
                        DebugLogging.WriteLog("NCMiddle Double " + nCode.ToString() + " " + MyMouseHookStruct.hwnd.ToString() + " " + MyMouseHookStruct.pt.x.ToString() + " x " + MyMouseHookStruct.pt.y.ToString() + " " + MyMouseHookStruct.wHitTestCode.ToString());
                        m_WM_MBUTTONDBLCLK = true;
                        break;
                    }
                }
                //}
                return(NM.CallNextHookEx(m_hMouseHook, nCode, wParam, lParam));
            }
        }