Ejemplo n.º 1
0
        /// <summary>
        /// 计算rebar正常位置
        /// </summary>
        /// <returns></returns>
        public static reBarInfo CalcRebarPos()
        {
            System.Drawing.Rectangle screenRect = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
            RECT      rcBar, rcTrayBtn, rcStart;
            reBarInfo rbInfo = new reBarInfo();

            try
            {
                #region
                IntPtr hTaskbar = FindWindow("Shell_TrayWnd", null);
                IntPtr hBar     = FindWindowEx(hTaskbar, IntPtr.Zero, "ReBarWindow32", null);
                IntPtr hTray    = FindWindowEx(hTaskbar, IntPtr.Zero, "TrayNotifyWnd", null);
                IntPtr hTrayBtn = FindWindowEx(hTray, IntPtr.Zero, "Button", null);
                IntPtr hStart   = FindWindowEx(hTaskbar, IntPtr.Zero, "Button", null);
                GetWindowRect(hStart, out rcStart);
                GetWindowRect(hBar, out rcBar);
                GetWindowRect(hTrayBtn, out rcTrayBtn);
                rbInfo.hreBar   = hBar;
                rbInfo.hTaskBar = hTaskbar;

                AppBarData taskbarInfo = new AppBarData();
                SHAppBarMessage(0x00000005, ref taskbarInfo);

                switch (taskbarInfo.uEdge)
                {
                case 0:
                case 2:    ////任务栏在右边
                    rbInfo.x      = 0;
                    rbInfo.y      = GetStartSpace(taskbarInfo.uEdge, rcStart);
                    rbInfo.height = rcTrayBtn.Top - rbInfo.y;
                    rbInfo.width  = rcBar.Right - rcBar.Left;
                    break;

                case 1:
                case 3:    ////任务栏在下边
                    rbInfo.x      = GetStartSpace(taskbarInfo.uEdge, rcStart);
                    rbInfo.y      = 0;
                    rbInfo.height = rcBar.Bottom - rcBar.Top;
                    rbInfo.width  = rcTrayBtn.Left - rbInfo.x;
                    break;
                }
                #endregion
            }
            catch
            { }

            return(rbInfo);
        }
Ejemplo n.º 2
0
 public static extern uint SHAppBarMessage(int dwMessage, ref AppBarData pData);
Ejemplo n.º 3
0
        /// <summary>
        /// 根据任务栏位置计算窗体和主按钮位置,返回计算好的reBar信息
        /// </summary>
        /// <param name="height">主窗体高度</param>
        /// <param name="width">主窗体宽度</param>
        /// <param name="pos">包含主界面和任务栏按钮信息的结构体</param>
        /// <returns></returns>
        public static reBarInfo CalcAppPos(double height, double width, out AppPos pos)
        {
            System.Drawing.Rectangle screenRect = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
            RECT      rcBar, rcTrayBtn, rcStart;
            reBarInfo rbInfo = new reBarInfo();

            try
            {
                #region
                IntPtr hTaskbar = FindWindow("Shell_TrayWnd", null);
                IntPtr hBar     = FindWindowEx(hTaskbar, IntPtr.Zero, "ReBarWindow32", null);
                IntPtr hTray    = FindWindowEx(hTaskbar, IntPtr.Zero, "TrayNotifyWnd", null);
                IntPtr hTrayBtn = FindWindowEx(hTray, IntPtr.Zero, "Button", null);
                IntPtr hStart   = FindWindowEx(hTaskbar, IntPtr.Zero, "Button", null);
                GetWindowRect(hStart, out rcStart);
                GetWindowRect(hBar, out rcBar);
                GetWindowRect(hTrayBtn, out rcTrayBtn);
                rbInfo.hreBar   = hBar;
                rbInfo.hTaskBar = hTaskbar;

                AppBarData taskbarInfo = new AppBarData();
                SHAppBarMessage(0x00000005, ref taskbarInfo);
                int max_size = 40;

                switch (taskbarInfo.uEdge)
                {
                    #region
                case 0:    ////任务栏在左边
                    pos.main_left = taskbarInfo.rc.Right + 3;
                    pos.main_top  = taskbarInfo.rc.Top + 30;
                    pos.btn_size  = rcBar.Right - rcBar.Left > max_size ? max_size : rcBar.Right - rcBar.Left;
                    pos.btn_x     = (rcBar.Right - rcBar.Left - pos.btn_size) / 2;
                    pos.btn_y     = GetStartSpace(taskbarInfo.uEdge, rcStart);

                    rbInfo.x      = 0;
                    rbInfo.y      = pos.btn_y + pos.btn_size;
                    rbInfo.height = rcTrayBtn.Top - rbInfo.y;
                    rbInfo.width  = rcBar.Right - rcBar.Left;
                    break;

                case 1:    ////任务栏在上边
                    pos.main_left = taskbarInfo.rc.Left + 30;
                    pos.main_top  = taskbarInfo.rc.Bottom + 3;
                    pos.btn_size  = rcBar.Bottom - rcBar.Top > max_size ? max_size : rcBar.Bottom - rcBar.Top;
                    pos.btn_x     = GetStartSpace(taskbarInfo.uEdge, rcStart);
                    pos.btn_y     = (rcBar.Bottom - rcBar.Top - pos.btn_size) / 2;

                    rbInfo.x      = pos.btn_x + pos.btn_size;
                    rbInfo.y      = 0;
                    rbInfo.height = rcBar.Bottom - rcBar.Top;
                    rbInfo.width  = rcTrayBtn.Left - rbInfo.x;
                    break;

                case 2:    ////任务栏在右边
                    pos.main_left = screenRect.Right - width - 3;
                    pos.main_top  = taskbarInfo.rc.Top + 30;
                    pos.btn_size  = rcBar.Right - rcBar.Left > max_size ? max_size : rcBar.Right - rcBar.Left;
                    pos.btn_x     = (rcBar.Right - rcBar.Left - pos.btn_size) / 2;
                    pos.btn_y     = GetStartSpace(taskbarInfo.uEdge, rcStart);

                    rbInfo.x      = 0;
                    rbInfo.y      = pos.btn_y + pos.btn_size;
                    rbInfo.height = rcTrayBtn.Top - rbInfo.y;
                    rbInfo.width  = rcBar.Right - rcBar.Left;
                    break;

                case 3:    ////任务栏在下边
                    pos.main_left = taskbarInfo.rc.Left + 30;
                    pos.main_top  = screenRect.Bottom - height - 3;
                    pos.btn_size  = rcBar.Bottom - rcBar.Top > max_size ? max_size : rcBar.Bottom - rcBar.Top;
                    pos.btn_x     = GetStartSpace(taskbarInfo.uEdge, rcStart);
                    pos.btn_y     = (rcBar.Bottom - rcBar.Top - pos.btn_size) / 2;

                    rbInfo.x      = pos.btn_x + pos.btn_size;
                    rbInfo.y      = 0;
                    rbInfo.height = rcBar.Bottom - rcBar.Top;
                    rbInfo.width  = rcTrayBtn.Left - rbInfo.x;
                    break;

                default:
                    pos = new AppPos((screenRect.Width - width) / 2, (screenRect.Height - height) / 2);
                    break;
                    #endregion
                }
                #endregion
            }
            catch
            { pos = new AppPos((screenRect.Width - width) / 2, (screenRect.Height - height) / 2); }

            return(rbInfo);
        }