Exemplo n.º 1
0
        private ScalingMode TabStripScalingMode()
        {
            IntPtr containerHandle = NM.GetAncestor(Handle, NM.GetAncestorFlags.GetParent);

            NM.tagPoint containerClientPoint = new NM.tagPoint();
            NM.ClientToScreen(containerHandle, ref containerClientPoint);

            NM.tagPoint clientPoint = new NM.tagPoint();
            NM.ClientToScreen(Handle, ref clientPoint);

            int containerOffsetX = clientPoint.x - containerClientPoint.x;
            int containerOffsetY = clientPoint.y - containerClientPoint.y;

            int placement = TabStripPlacement();

            switch (placement)
            {
            case 0:     //Top
            case 1:     //Bottom
                GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, Identity.ParentHandle, Identity.Handle);
                GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "ClientLeft", MemberTypes.Property);
                GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store1);
                GUI.m_APE.SendMessages(EventSet.APE);
                GUI.m_APE.WaitForMessages(EventSet.APE);
                //Get the value(s) returned MUST be done straight after the WaitForMessages call
                int clientLeft = (int)(Math.Round(GUI.m_APE.GetValueFromMessage()));
                if (clientLeft - containerOffsetX < 10)
                {
                    return(ScalingMode.Pixel);
                }
                if (TwipsToPixels(clientLeft, Direction.Horizontal) - containerOffsetX < 10)
                {
                    return(ScalingMode.Twip);
                }
                throw GUI.ApeException("Unsupported scaling mode");

            case 2:     //Left
            case 3:     //Right
                GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, Identity.ParentHandle, Identity.Handle);
                GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "ClientTop", MemberTypes.Property);
                GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store1);
                GUI.m_APE.SendMessages(EventSet.APE);
                GUI.m_APE.WaitForMessages(EventSet.APE);
                //Get the value(s) returned MUST be done straight after the WaitForMessages call
                int clientTop = (int)(Math.Round(GUI.m_APE.GetValueFromMessage()));
                if (clientTop - containerOffsetY < 10)
                {
                    return(ScalingMode.Pixel);
                }
                if (TwipsToPixels(clientTop, Direction.Vertical) - containerOffsetY < 10)
                {
                    return(ScalingMode.Twip);
                }
                throw GUI.ApeException("Unsupported scaling mode");

            default:
                throw GUI.ApeException("The " + Description + " placement is of unsupported type " + placement.ToString());
            }
        }
Exemplo n.º 2
0
        public static void GetWindowBitmap(IntPtr Handle, int X, int Y, ref Bitmap WindowBitmap, bool CaptureMouse, bool ClearClientArea)
        {
            using (Graphics gdest = Graphics.FromImage(WindowBitmap))
            {
                using (Graphics gsrc = Graphics.FromHwnd(IntPtr.Zero))
                {
                    try
                    {
                        IntPtr hSrcDC = gsrc.GetHdc();
                        IntPtr hDC    = gdest.GetHdc();

                        // BitBlt is faster than CopyFromScreen
                        bool retval = NM.BitBlt(hDC, 0, 0, WindowBitmap.Width, WindowBitmap.Height, hSrcDC, X, Y, CopyPixelOperation.SourceCopy | CopyPixelOperation.CaptureBlt);

                        if (ClearClientArea)
                        {
                            NM.tagRect theRect;
                            NM.GetClientRect(Handle, out theRect);

                            NM.tagPoint thePoint = new NM.tagPoint();
                            NM.ClientToScreen(Handle, ref thePoint);

                            NM.Rectangle(hDC, thePoint.x - X, thePoint.y - Y, (thePoint.x - X) + theRect.right, (thePoint.y - Y) + theRect.bottom);
                        }

                        if (CaptureMouse)
                        {
                            NM.tagCURSORINFO cursorInfo = new NM.tagCURSORINFO();
                            cursorInfo.cbSize = Marshal.SizeOf(typeof(NM.tagCURSORINFO));

                            if (NM.GetCursorInfo(ref cursorInfo))
                            {
                                if (cursorInfo.flags.HasFlag(NM.CursorFlags.Cursor_Showing))
                                {
                                    NM.ICONINFO iconInfo;

                                    if (NM.GetIconInfo(cursorInfo.hCursor, out iconInfo))
                                    {
                                        NM.DrawIcon(hDC, cursorInfo.ptScreenPos.x - iconInfo.xHotspot, cursorInfo.ptScreenPos.y - iconInfo.yHotspot, cursorInfo.hCursor);
                                    }
                                }
                            }
                        }
                    }
                    finally
                    {
                        // Clean up
                        gdest.ReleaseHdc();
                        gsrc.ReleaseHdc();
                    }
                }
            }
        }
Exemplo n.º 3
0
        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");
            }
        }
Exemplo n.º 4
0
        public static void MouseUp(IntPtr ParentHandle, IntPtr Handle, int x, int y, MouseButton Button, MouseKeyModifier Keys)
        {
            bool hooked = false;

            WaitToBeVisibleAndEnabled(Handle);
            Block(ParentHandle, Handle);
            try
            {
                NM.tagPoint thePoint = new NM.tagPoint();
                thePoint.x = x;
                thePoint.y = y;
                IntPtr TopLevelHandle = NM.ChildWindowFromPoint(NM.GetDesktopWindow(), thePoint);

                NM.tagRect WindowSize;
                NM.GetWindowRect(Handle, out WindowSize);

                thePoint.x = x + WindowSize.left;
                thePoint.y = y + WindowSize.top;
                IntPtr ChildHandle = NM.WindowFromPoint(thePoint);

                if (!WaitForInputIdle(ChildHandle, GUI.m_APE.TimeOut))
                {
                    throw new Exception("Window did not go idle within timeout");
                }

                IntPtr ActualParent;

                if (ParentHandle == IntPtr.Zero)
                {
                    ActualParent = Handle;
                }
                else
                {
                    ActualParent = ParentHandle;
                }

                TimerResolution.SetMaxTimerResolution();

                //TODO this looks wrong should use clickcommon only for this
                if (ChildHandle == ActualParent)
                {
                    ClickCommon(ParentHandle, Handle, x, y);
                }
                else
                {
                    MouseMove(Handle, x, y, false);
                }

                if (Handle == ActualParent)
                {
                    GUI.m_APE.AddFirstMessageAddMouseHook(Handle);
                    GUI.m_APE.SendMessages(EventSet.APE);
                    GUI.m_APE.WaitForMessages(EventSet.APE);
                    hooked = true;
                }

                MouseClick(Button, false, true, 1, Keys.HasFlag(MouseKeyModifier.Control), Keys.HasFlag(MouseKeyModifier.Shift));

                if (Handle == ActualParent)
                {
                    GUI.m_APE.AddFirstMessageWaitForMouseState((APEIPC.MouseButton)Button, false, true);
                    GUI.m_APE.SendMessages(EventSet.APE);
                    GUI.m_APE.WaitForMessages(EventSet.APE);
                }
            }
            catch
            {
                Reset();    //Reset the mouse blocking
                throw;
            }
            finally
            {
                try
                {
                    if (hooked)
                    {
                        GUI.m_APE.AddFirstMessageRemoveMouseHook(Handle);
                        GUI.m_APE.SendMessages(EventSet.APE);
                        GUI.m_APE.WaitForMessages(EventSet.APE);
                    }
                }
                finally
                {
                    TimerResolution.UnsetMaxTimerResolution();
                    Unblock();
                    IsMouseDown = false;
                }
            }
        }
Exemplo n.º 5
0
        private Rectangle TabRectangle(int actualTabIndex)
        {
            int x;
            int y;
            int width;
            int height;

            switch (Identity.TechnologyType)
            {
            case "Windows Forms (WinForms)":
                GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, Identity.ParentHandle, Identity.Handle);
                GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "GetTabRect", MemberTypes.Method, new Parameter(GUI.m_APE, actualTabIndex));
                GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store2, "X", MemberTypes.Property);
                GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store3, "Y", MemberTypes.Property);
                GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store4, "Width", MemberTypes.Property);
                GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store5, "Height", MemberTypes.Property);
                GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store2);
                GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store3);
                GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store4);
                GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store5);
                GUI.m_APE.SendMessages(EventSet.APE);
                GUI.m_APE.WaitForMessages(EventSet.APE);
                //Get the value(s) returned MUST be done straight after the WaitForMessages call
                x      = GUI.m_APE.GetValueFromMessage();
                y      = GUI.m_APE.GetValueFromMessage();
                width  = GUI.m_APE.GetValueFromMessage();
                height = GUI.m_APE.GetValueFromMessage();
                break;

            case "Windows ActiveX":
                switch (Identity.TypeName)
                {
                case "SftTabs":
                    GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, Identity.ParentHandle, Identity.Handle);
                    GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "Tab", MemberTypes.Method, new Parameter(GUI.m_APE, actualTabIndex));
                    GUI.m_APE.AddQueryMessageGetTabRect(DataStores.Store1);
                    GUI.m_APE.SendMessages(EventSet.APE);
                    GUI.m_APE.WaitForMessages(EventSet.APE);
                    //Get the value(s) returned MUST be done straight after the WaitForMessages call
                    x      = GUI.m_APE.GetValueFromMessage();
                    y      = GUI.m_APE.GetValueFromMessage();
                    width  = GUI.m_APE.GetValueFromMessage();
                    height = GUI.m_APE.GetValueFromMessage();
                    break;

                case "TabStrip":
                    GUI.m_APE.AddFirstMessageFindByHandle(DataStores.Store0, Identity.ParentHandle, Identity.Handle);
                    GUI.m_APE.AddQueryMessageReflect(DataStores.Store0, DataStores.Store1, "Tabs", MemberTypes.Method, new Parameter(GUI.m_APE, actualTabIndex));
                    GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store2, "Left", MemberTypes.Property);
                    GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store3, "Top", MemberTypes.Property);
                    GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store4, "Width", MemberTypes.Property);
                    GUI.m_APE.AddQueryMessageReflect(DataStores.Store1, DataStores.Store5, "Height", MemberTypes.Property);
                    GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store2);
                    GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store3);
                    GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store4);
                    GUI.m_APE.AddRetrieveMessageGetValue(DataStores.Store5);
                    GUI.m_APE.SendMessages(EventSet.APE);
                    GUI.m_APE.WaitForMessages(EventSet.APE);
                    //Get the value(s) returned MUST be done straight after the WaitForMessages call
                    x      = (int)(Math.Round(GUI.m_APE.GetValueFromMessage()));
                    y      = (int)(Math.Round(GUI.m_APE.GetValueFromMessage()));
                    width  = (int)(Math.Round(GUI.m_APE.GetValueFromMessage()));
                    height = (int)(Math.Round(GUI.m_APE.GetValueFromMessage()));

                    IntPtr containerHandle = NM.GetAncestor(Handle, NM.GetAncestorFlags.GetParent);

                    NM.tagPoint containerClientPoint = new NM.tagPoint();
                    NM.ClientToScreen(containerHandle, ref containerClientPoint);

                    NM.tagPoint clientPoint = new NM.tagPoint();
                    NM.ClientToScreen(Handle, ref clientPoint);

                    int containerOffsetX = clientPoint.x - containerClientPoint.x;
                    int containerOffsetY = clientPoint.y - containerClientPoint.y;

                    ScalingMode scaleMode = TabStripScalingMode();
                    switch (scaleMode)
                    {
                    case ScalingMode.Twip:             //Twip
                        x      = TwipsToPixels(x, Direction.Horizontal);
                        y      = TwipsToPixels(y, Direction.Vertical);
                        width  = TwipsToPixels(width, Direction.Horizontal);
                        height = TwipsToPixels(height, Direction.Vertical);
                        break;

                    case ScalingMode.Pixel:             //Pixel
                        //do nothing
                        break;

                    case ScalingMode.User:
                    case ScalingMode.Point:
                    case ScalingMode.Character:
                    case ScalingMode.Inch:
                    case ScalingMode.Millimeter:
                    case ScalingMode.Centimeter:
                        throw GUI.ApeException("The " + Description + " scaling mode is of unsupported type " + scaleMode.ToString());

                    default:
                        throw GUI.ApeException("The " + Description + " scaling mode is of unsupported type " + scaleMode.ToString());
                    }

                    x = x - containerOffsetX;
                    y = y - containerOffsetY;

                    int placement = TabStripPlacement();
                    switch (placement)
                    {
                    case 0:             //Top
                    case 1:             //Bottom
                        //do nothing
                        break;

                    case 2:             //Left
                    case 3:             //Right
                        //swap width and height
                        int temp = width;
                        width  = height;
                        height = temp;
                        break;

                    default:
                        throw GUI.ApeException("The " + Description + " placement is of unsupported type " + placement.ToString());
                    }

                    break;

                default:
                    throw GUI.ApeException("The " + Description + " is of an unsupported type " + Identity.TypeNameSpace + "." + Identity.TypeName);
                }
                break;

            default:
                throw GUI.ApeException("The " + Description + " is of an unsupported type " + Identity.TypeNameSpace + "." + Identity.TypeName);
            }
            Rectangle tabRectangle = new Rectangle(x, y, width, height);

            return(tabRectangle);
        }