public override void RemoveButton() { base.RemoveButton(); reBarInfo rbInfo = API.CalcRebarPos(); API.MoveWindow(rbInfo.hreBar, rbInfo.x, rbInfo.y, rbInfo.width, rbInfo.height, true); }
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 = API.FindWindow("Shell_TrayWnd", null); IntPtr hBar = API.FindWindowEx(hTaskbar, IntPtr.Zero, "ReBarWindow32", null); IntPtr hTray = API.FindWindowEx(hTaskbar, IntPtr.Zero, "TrayNotifyWnd", null); IntPtr hTrayBtn = API.FindWindowEx(hTray, IntPtr.Zero, "Button", null); IntPtr hStart = API.FindWindowEx(hTaskbar, IntPtr.Zero, "Button", null); API.GetWindowRect(hStart, out rcStart); API.GetWindowRect(hBar, out rcBar); API.GetWindowRect(hTrayBtn, out rcTrayBtn); rbInfo.hreBar = hBar; rbInfo.hTaskBar = hTaskbar; AppBarData taskbarInfo = new AppBarData(); API.SHAppBarMessage(0x00000005, ref taskbarInfo); int max_size = 40; switch (taskbarInfo.uEdge) { #region 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 = 40; 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); }
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 = API.FindWindow( "Shell_TrayWnd", null ); IntPtr hBar = API.FindWindowEx( hTaskbar, IntPtr.Zero, "ReBarWindow32", null ); IntPtr hTray = API.FindWindowEx( hTaskbar, IntPtr.Zero, "TrayNotifyWnd", null ); IntPtr hTrayBtn = API.FindWindowEx( hTray, IntPtr.Zero, "Button", null ); IntPtr hStart = API.FindWindowEx( hTaskbar, IntPtr.Zero, "Button", null ); API.GetWindowRect( hStart, out rcStart ); API.GetWindowRect( hBar, out rcBar ); API.GetWindowRect( hTrayBtn, out rcTrayBtn ); rbInfo.hreBar = hBar; rbInfo.hTaskBar = hTaskbar; AppBarData taskbarInfo = new AppBarData(); API.SHAppBarMessage( 0x00000005, ref taskbarInfo ); int max_size = 40; switch ( taskbarInfo.uEdge ) { #region 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 = 40; 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; }
public override void SetAppPos(bool moveRebar) { base.SetAppPos(moveRebar); AppPos pos; reBarInfo rbInfo = API.CalcAppPos(mainWindow.Height, mainWindow.Width, out pos); if (moveRebar) { API.MoveWindow(rbInfo.hreBar, rbInfo.x, rbInfo.y, rbInfo.width, rbInfo.height, true); } API.MoveWindow(startButtonHandle, pos.btn_x, pos.btn_y, pos.btn_size, pos.btn_size, true); mainWindow.Top = pos.main_top; mainWindow.Left = pos.main_left; }
/// <summary> /// 计算rebar正常位置 /// </summary> /// <returns></returns> public reBarInfo CalcRebarPos() { System.Drawing.Rectangle screenRect = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea; RECT rcBar, rcTrayBtn, rcStart; reBarInfo rbInfo = new reBarInfo(); try { IntPtr hTaskbar = API.FindWindow("Shell_TrayWnd", null); IntPtr hBar = API.FindWindowEx(hTaskbar, IntPtr.Zero, "ReBarWindow32", null); IntPtr hTray = API.FindWindowEx(hTaskbar, IntPtr.Zero, "TrayNotifyWnd", null); IntPtr hTrayBtn = API.FindWindowEx(hTray, IntPtr.Zero, "Button", null); IntPtr hStart = API.FindWindowEx(hTaskbar, IntPtr.Zero, "Button", null); API.GetWindowRect(hStart, out rcStart); API.GetWindowRect(hBar, out rcBar); API.GetWindowRect(hTrayBtn, out rcTrayBtn); rbInfo.hreBar = hBar; rbInfo.hTaskBar = hTaskbar; AppBarData taskbarInfo = new AppBarData(); API.SHAppBarMessage(0x00000005, ref taskbarInfo); switch (taskbarInfo.uEdge) { case 0: case 2:////任务栏在右边 rbInfo.x = 0; rbInfo.y = rcBar.Left; rbInfo.height = rcTrayBtn.Top - rbInfo.y; rbInfo.width = rcBar.Right - rcBar.Left; break; case 1: case 3:////任务栏在下边 rbInfo.x = rcBar.Top; rbInfo.y = 0; rbInfo.height = rcBar.Bottom - rcBar.Top; rbInfo.width = rcTrayBtn.Left - rbInfo.x; break; } } catch { } return rbInfo; }