Example #1
0
        private void AppbarQueryPos(ref NM.tagRect appRect)
        {
            float ScreenScalingFactor;

            using (Graphics g = Graphics.FromHwnd(IntPtr.Zero))
            {
                IntPtr desktop              = g.GetHdc();
                int    LogicalScreenHeight  = NM.GetDeviceCaps(desktop, NM.DeviceCap.VERTRES);
                int    PhysicalScreenHeight = NM.GetDeviceCaps(desktop, NM.DeviceCap.DESKTOPVERTRES);
                g.ReleaseHdc();
                ScreenScalingFactor = (float)PhysicalScreenHeight / (float)LogicalScreenHeight;
            }

            // prepare data structure of message
            NM.APPBARDATA msgData = new NM.APPBARDATA();
            msgData.cbSize = (UInt32)Marshal.SizeOf(msgData);
            msgData.hWnd   = Handle;
            msgData.uEdge  = (UInt32)m_Edge;
            msgData.rc     = appRect;

            // query postion for the appbar
            msgData.rc.left   = (int)(Math.Round((float)msgData.rc.left * ScreenScalingFactor));
            msgData.rc.right  = (int)(Math.Round((float)msgData.rc.right * ScreenScalingFactor));
            msgData.rc.top    = (int)(Math.Round((float)msgData.rc.top * ScreenScalingFactor));
            msgData.rc.bottom = (int)(Math.Round((float)msgData.rc.bottom * ScreenScalingFactor));

            NM.SHAppBarMessage(NM.AppBarMessages.QueryPos, ref msgData);

            msgData.rc.left   = (int)(Math.Round((float)msgData.rc.left / ScreenScalingFactor));
            msgData.rc.right  = (int)(Math.Round((float)msgData.rc.right / ScreenScalingFactor));
            msgData.rc.top    = (int)(Math.Round((float)msgData.rc.top / ScreenScalingFactor));
            msgData.rc.bottom = (int)(Math.Round((float)msgData.rc.bottom / ScreenScalingFactor));

            appRect = msgData.rc;
        }
Example #2
0
        public void AppbarNew(AppBarEdges Edge)
        {
            if (!m_IsAppbarDocked)
            {
                if (m_CallbackMessageID == 0)
                {
                    throw new Exception("CallbackMessageID is 0");
                }

                m_Edge = Edge;

                m_OriginalSize     = this.Size;
                m_OriginalLocation = this.Location;
                m_PrevBorderStyle  = this.FormBorderStyle;

                this.FormBorderStyle = FormBorderStyle.None;

                // prepare data structure of message
                NM.APPBARDATA msgData = new NM.APPBARDATA();
                msgData.cbSize           = (UInt32)Marshal.SizeOf(msgData);
                msgData.hWnd             = this.Handle;
                msgData.uCallbackMessage = m_CallbackMessageID;

                // install new appbar
                UIntPtr Return = NM.SHAppBarMessage(NM.AppBarMessages.New, ref msgData);
                if (Return == UIntPtr.Zero)
                {
                    throw new Exception("Failed to add AppBar");
                }
                m_IsAppbarDocked = true;

                SizeAppBar();
            }
        }
Example #3
0
        public void AppbarRemove()
        {
            if (m_IsAppbarDocked)
            {
                // prepare data structure of message
                NM.APPBARDATA msgData = new NM.APPBARDATA();
                msgData.cbSize = (UInt32)Marshal.SizeOf(msgData);
                msgData.hWnd   = this.Handle;

                // remove appbar
                UIntPtr Return = NM.SHAppBarMessage(NM.AppBarMessages.Remove, ref msgData);
                if (Return == UIntPtr.Zero)
                {
                    throw new Exception("Failed to remove AppBar");
                }

                this.FormBorderStyle = m_PrevBorderStyle;
                this.Size            = m_OriginalSize;
                this.Location        = m_OriginalLocation;

                m_IsAppbarDocked = false;
            }
        }