Пример #1
0
        private unsafe void GetTitleBarItemRectangle(Message *ptrMessage, int messageNumber)
        {
            //must be first message
            if (messageNumber != 1)
            {
                throw new Exception("GetTitleBarItemRectangle must be first message");
            }

            // p1  = handle
            IntPtr handle = GetParameterIntPtr(ptrMessage, 0);

            // p2  = TitleBarStateElement
            NM.TitleBarStateElement item = (NM.TitleBarStateElement)GetParameterInt32(ptrMessage, 1);

            // p3 = scalingfactor
            float screenScalingFactor = GetParameterSingle(ptrMessage, 2);

            CleanUpMessage(ptrMessage);

            NM.TITLEBARINFOEX tbi = new NM.TITLEBARINFOEX();
            tbi.cbSize = Marshal.SizeOf(typeof(NM.TITLEBARINFOEX));

            // Send the WM_GETTITLEBARINFOEX message
            IntPtr result;
            IntPtr smtReturn;

            smtReturn = NM.SendMessageTimeout(handle, NM.WM_GETTITLEBARINFOEX, IntPtr.Zero, ref tbi, NM.SendMessageTimeoutFlags.SMTO_NORMAL, TimeOut, out result);

            uint state;
            int  left;
            int  top;
            int  right;
            int  bottom;

            switch (item)
            {
            case NM.TitleBarStateElement.TitleBar:
                state  = (uint)tbi.rgstate[(int)NM.TitleBarStateElement.TitleBar];
                top    = tbi.rcTitleBar.top;
                left   = tbi.rcTitleBar.left;
                bottom = tbi.rcTitleBar.bottom;
                right  = tbi.rcTitleBar.right;
                break;

            case NM.TitleBarStateElement.Minimize:
                state  = (uint)tbi.rgstate[(int)NM.TitleBarStateElement.Minimize];
                top    = tbi.rgrect[(int)NM.TitleBarStateElement.Minimize].top;
                left   = tbi.rgrect[(int)NM.TitleBarStateElement.Minimize].left;
                bottom = tbi.rgrect[(int)NM.TitleBarStateElement.Minimize].bottom;
                right  = tbi.rgrect[(int)NM.TitleBarStateElement.Minimize].right;
                break;

            case NM.TitleBarStateElement.Maximize:
                state  = (uint)tbi.rgstate[(int)NM.TitleBarStateElement.Maximize];
                top    = tbi.rgrect[(int)NM.TitleBarStateElement.Maximize].top;
                left   = tbi.rgrect[(int)NM.TitleBarStateElement.Maximize].left;
                bottom = tbi.rgrect[(int)NM.TitleBarStateElement.Maximize].bottom;
                right  = tbi.rgrect[(int)NM.TitleBarStateElement.Maximize].right;
                break;

            case NM.TitleBarStateElement.Help:
                state  = (uint)tbi.rgstate[(int)NM.TitleBarStateElement.Help];
                top    = tbi.rgrect[(int)NM.TitleBarStateElement.Help].top;
                left   = tbi.rgrect[(int)NM.TitleBarStateElement.Help].left;
                bottom = tbi.rgrect[(int)NM.TitleBarStateElement.Help].bottom;
                right  = tbi.rgrect[(int)NM.TitleBarStateElement.Help].right;
                break;

            case NM.TitleBarStateElement.Close:
                state  = (uint)tbi.rgstate[(int)NM.TitleBarStateElement.Close];
                top    = tbi.rgrect[(int)NM.TitleBarStateElement.Close].top;
                left   = tbi.rgrect[(int)NM.TitleBarStateElement.Close].left;
                bottom = tbi.rgrect[(int)NM.TitleBarStateElement.Close].bottom;
                right  = tbi.rgrect[(int)NM.TitleBarStateElement.Close].right;
                break;

            default:
                throw new Exception("Unknown titlebar element: " + item.ToString());
            }

            //HACK - Windows 10 1809 has a bug where by when the window is maximised and you have a docked app bar above it then the top value is wrong
            if (top < tbi.rcTitleBar.top)
            {
                top = tbi.rcTitleBar.top;
            }

            left   = (int)(Math.Round((float)(left) / screenScalingFactor));
            top    = (int)(Math.Round((float)(top) / screenScalingFactor));
            right  = (int)(Math.Round((float)(right) / screenScalingFactor));
            bottom = (int)(Math.Round((float)(bottom) / screenScalingFactor));

            AddReturnValue(new Parameter(this, state));
            AddReturnValue(new Parameter(this, top));
            AddReturnValue(new Parameter(this, left));
            AddReturnValue(new Parameter(this, bottom));
            AddReturnValue(new Parameter(this, right));
        }
Пример #2
0
        private unsafe void GetTitleBarItemRectangle(Message *ptrMessage, int messageNumber)
        {
            //must be first message
            if (messageNumber != 1)
            {
                throw new Exception("GetTitleBarItemRectangle must be first message");
            }

            // p1  = handle
            IntPtr handle = GetParameterIntPtr(ptrMessage, 0);

            // p2  = TitleBarStateElement
            NM.TitleBarStateElement item = (NM.TitleBarStateElement)GetParameterInt32(ptrMessage, 1);

            CleanUpMessage(ptrMessage);

            NM.TITLEBARINFOEX tbi = new NM.TITLEBARINFOEX();
            tbi.cbSize = Marshal.SizeOf(typeof(NM.TITLEBARINFOEX));

            // Send the WM_GETTITLEBARINFOEX message
            IntPtr result;
            IntPtr smtReturn;

            smtReturn = NM.SendMessageTimeout(handle, NM.WM_GETTITLEBARINFOEX, IntPtr.Zero, ref tbi, NM.SendMessageTimeoutFlags.SMTO_NORMAL, TimeOut, out result);

            uint state;
            int  left;
            int  top;
            int  right;
            int  bottom;

            switch (item)
            {
            case NM.TitleBarStateElement.TitleBar:
                state  = (uint)tbi.rgstate[(int)NM.TitleBarStateElement.TitleBar];
                top    = tbi.rcTitleBar.top;
                left   = tbi.rcTitleBar.left;
                bottom = tbi.rcTitleBar.bottom;
                right  = tbi.rcTitleBar.right;
                break;

            case NM.TitleBarStateElement.Minimize:
                state  = (uint)tbi.rgstate[(int)NM.TitleBarStateElement.Minimize];
                top    = tbi.rgrect[(int)NM.TitleBarStateElement.Minimize].top;
                left   = tbi.rgrect[(int)NM.TitleBarStateElement.Minimize].left;
                bottom = tbi.rgrect[(int)NM.TitleBarStateElement.Minimize].bottom;
                right  = tbi.rgrect[(int)NM.TitleBarStateElement.Minimize].right;
                break;

            case NM.TitleBarStateElement.Maximize:
                state  = (uint)tbi.rgstate[(int)NM.TitleBarStateElement.Maximize];
                top    = tbi.rgrect[(int)NM.TitleBarStateElement.Maximize].top;
                left   = tbi.rgrect[(int)NM.TitleBarStateElement.Maximize].left;
                bottom = tbi.rgrect[(int)NM.TitleBarStateElement.Maximize].bottom;
                right  = tbi.rgrect[(int)NM.TitleBarStateElement.Maximize].right;
                break;

            case NM.TitleBarStateElement.Help:
                state  = (uint)tbi.rgstate[(int)NM.TitleBarStateElement.Help];
                top    = tbi.rgrect[(int)NM.TitleBarStateElement.Help].top;
                left   = tbi.rgrect[(int)NM.TitleBarStateElement.Help].left;
                bottom = tbi.rgrect[(int)NM.TitleBarStateElement.Help].bottom;
                right  = tbi.rgrect[(int)NM.TitleBarStateElement.Help].right;
                break;

            case NM.TitleBarStateElement.Close:
                state  = (uint)tbi.rgstate[(int)NM.TitleBarStateElement.Close];
                top    = tbi.rgrect[(int)NM.TitleBarStateElement.Close].top;
                left   = tbi.rgrect[(int)NM.TitleBarStateElement.Close].left;
                bottom = tbi.rgrect[(int)NM.TitleBarStateElement.Close].bottom;
                right  = tbi.rgrect[(int)NM.TitleBarStateElement.Close].right;
                break;

            default:
                throw new Exception("Unknown titlebar element: " + item.ToString());
            }

            AddReturnValue(new Parameter(this, state));
            AddReturnValue(new Parameter(this, top));
            AddReturnValue(new Parameter(this, left));
            AddReturnValue(new Parameter(this, bottom));
            AddReturnValue(new Parameter(this, right));
        }