/// <summary> /// Centers the window in the screen. You must call it after the window is created, but before it is shown to avoid flickering /// </summary> public void CenterTopLevelWindow() { #if WINDOWS PInvokeUtils.RECT rectWindow; PInvokeWindows.GetWindowRect(_hwnd, out rectWindow); PInvokeUtils.RECT rectWorkArea = new PInvokeUtils.RECT(); PInvokeWindows.SystemParametersInfo(PInvokeWindows.SPI_GETWORKAREA, 0, ref rectWorkArea, 0); int nX = (rectWorkArea.Width - rectWindow.Width) / 2 + rectWorkArea.left; int nY = (rectWorkArea.Height - rectWindow.Height) / 2 + rectWorkArea.top; PInvokeWindows.MoveWindow(_hwnd, nX, nY, rectWindow.Width, rectWindow.Height, false); #elif GTKMONO int screen_width = PInvokeGTK.gdk_screen_width(); int screen_height = PInvokeGTK.gdk_screen_height(); int window_width, window_height; PInvokeGTK.gtk_window_get_size(_gtkwindow, out window_width, out window_height); int nX = (screen_width - window_width) / 2; int nY = (screen_height - window_height) / 2; PInvokeGTK.gtk_window_move(_gtkwindow, nX, nY); #elif OSX _nsview.Window.Center(); #endif }
/* #if WINDOWS || NETCORE * public bool ModifyStyle(PInvokeWindows.WindowStyles dwRemove, PInvokeWindows.WindowStyles dwAdd) * { * int GWL_EXSTYLE = -20; * * PInvokeWindows.WindowStyles dwStyle = * (PInvokeWindows.WindowStyles) PInvokeWindows.GetWindowLongPtr(Handle, GWL_EXSTYLE); * PInvokeWindows.WindowStyles dwNewStyle = (dwStyle & ~dwRemove) | dwAdd; * * if (dwStyle == dwNewStyle) * return false; * * PInvokeWindows.SetWindowLongPtr(Handle, GWL_EXSTYLE, (IntPtr) dwNewStyle); * return true; * } * * public bool ModifyStyleEx(PInvokeWindows.WindowStyles dwRemove, PInvokeWindows.WindowStyles dwAdd) * { * int GWL_STYLE = -16; * * PInvokeWindows.WindowStyles dwStyle = * (PInvokeWindows.WindowStyles) PInvokeWindows.GetWindowLongPtr(Handle, GWL_STYLE); * PInvokeWindows.WindowStyles dwNewStyle = (dwStyle & ~dwRemove) | dwAdd; * if (dwStyle == dwNewStyle) * return false; * * PInvokeWindows.SetWindowLongPtr(Handle, GWL_STYLE, (IntPtr) dwNewStyle); * return true; * } #endif*/ /// <summary> /// Centers the window in the screen. You must call it after the window is created, but before it is shown to avoid flickering /// </summary> public void CenterWindow(IntPtr handle) { PInvokeWindows.GetWindowRect(handle, out var rectWindow); var rectWorkArea = new PInvokeUtils.RECT(); PInvokeWindows.SystemParametersInfo(PInvokeWindows.SPI_GETWORKAREA, 0, ref rectWorkArea, 0); var newX = (rectWorkArea.Width - rectWindow.Width) / 2 + rectWorkArea.Left; var newY = (rectWorkArea.Height - rectWindow.Height) / 2 + rectWorkArea.Top; PInvokeWindows.MoveWindow(handle, newX, newY, rectWindow.Width, rectWindow.Height, false); }
/// <summary> /// Centers the window in the screen. You must call it after the window is created, but before it is shown to avoid flickering /// </summary> public void CenterTopLevelWindow() { #if WINDOWS IntPtr hwndParent = PInvokeWindows.GetDesktopWindow(); PInvokeUtils.RECT rectWindow, rectParent; PInvokeWindows.GetWindowRect(_hwnd, out rectWindow); PInvokeWindows.GetWindowRect(hwndParent, out rectParent); int nWidth = rectWindow.right - rectWindow.left; int nHeight = rectWindow.bottom - rectWindow.top; int nX = ((rectParent.right - rectParent.left) - nWidth) / 2 + rectParent.left; int nY = ((rectParent.bottom - rectParent.top) - nHeight) / 2 + rectParent.top; int nScreenWidth = PInvokeWindows.GetSystemMetrics(PInvokeWindows.SystemMetric.SM_CXSCREEN); int nScreenHeight = PInvokeWindows.GetSystemMetrics(PInvokeWindows.SystemMetric.SM_CYSCREEN); if (nX < 0) { nX = 0; } if (nY < 0) { nY = 0; } if (nX + nWidth > nScreenWidth) { nX = nScreenWidth - nWidth; } if (nY + nHeight > nScreenHeight) { nY = nScreenHeight - nHeight; } PInvokeWindows.MoveWindow(_hwnd, nX, nY, nWidth, nHeight, false); #elif GTKMONO int screen_width = PInvokeGTK.gdk_screen_width(); int screen_height = PInvokeGTK.gdk_screen_height(); int window_width, window_height; PInvokeGTK.gtk_window_get_size(_gtkwindow, out window_width, out window_height); int nX = (screen_width - window_width) / 2; int nY = (screen_height - window_height) / 2; PInvokeGTK.gtk_window_move(_gtkwindow, nX, nY); #elif OSX _nsview.Window.Center(); #endif }
public SciterPoint GetPosition(IntPtr handle) { PInvokeWindows.GetWindowRect(handle, out var rectWindow); return(new SciterPoint(rectWindow.Left, rectWindow.Top)); }
public SciterSize Size(IntPtr handle) { PInvokeWindows.GetWindowRect(handle, out var rectWindow); return(new SciterSize(rectWindow.Width, rectWindow.Height)); }