private static void MoveMouse() { try { var monitor = NativeMethods.MonitorFromPoint(new Point(0, 0), NativeMethods.MonitorDefaultToNearest); if (monitor != IntPtr.Zero) { var monitorInfo = new MONITORINFO(); NativeMethods.GetMonitorInfo(monitor, monitorInfo); var monitorArea = monitorInfo.rcMonitor; var offSetX = (monitorArea.Width - 1680) / 2; var offSetY = (monitorArea.Height - 1050) / 2; NativeMethods.SetCursorPos(520 + offSetX, 737 + offSetY); } } // ReSharper disable EmptyGeneralCatchClause catch (Exception) { // ReSharper restore EmptyGeneralCatchClause // Do nothing. } }
/// <summary> /// Windows the loaded event handler. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param> private void WindowLoadedEventHandler(object sender, RoutedEventArgs e) { // Check for new DTM catalog when application is loading var mainWindowVm = this.DataContext as MainWindowVm; if (mainWindowVm != null) { try { this.ServiceHostContainer.Start(); } catch (Exception exception) { var message = @"Exception in client call: " + exception.Message; var caption = @"Exception"; mainWindowVm.Host.UserInterface.DisplayMessage(message, caption, MessageButton.ButtonsOk, MessageType.MessageInformation, DefaultMessageButton.ButtonOk); } // display windows full screen when started first time if (((int)mainWindowVm.SettingsViewModel.WindowsPosLeft == 0) && ((int)mainWindowVm.SettingsViewModel.WindowsPosTop == 0) && ((int)mainWindowVm.SettingsViewModel.WindowsPosWidth == 0) && ((int)mainWindowVm.SettingsViewModel.WindowsPosHeight == 0)) { var monitor = NativeMethods.MonitorFromPoint(new Point(0, 0), NativeMethods.MonitorDefaultToNearest); if (monitor != IntPtr.Zero) { var monitorInfo = new MONITORINFO(); NativeMethods.GetMonitorInfo(monitor, monitorInfo); var workingArea = monitorInfo.rcWork; this.Left = workingArea.left; this.Top = workingArea.top; this.Width = workingArea.Width; this.Height = workingArea.Height; } } else { this.Left = mainWindowVm.SettingsViewModel.WindowsPosLeft; this.Top = mainWindowVm.SettingsViewModel.WindowsPosTop; this.Width = mainWindowVm.SettingsViewModel.WindowsPosWidth; this.Height = mainWindowVm.SettingsViewModel.WindowsPosHeight; } if (SplashScreenHelper.SplashScreen != null) { SplashScreenHelper.SplashScreen.Close(TimeSpan.FromMilliseconds(10)); SplashScreenHelper.SplashScreen = null; } this.applicationLoadedTimer = new Timer(this.ApplicationLoadedTimerElapsed, mainWindowVm, 50, 50); } }
private static IntPtr DragHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handeled) { switch ((WM)msg) { case WM.WINDOWPOSCHANGING: { var pos = (WINDOWPOS)Marshal.PtrToStructure(lParam, typeof(WINDOWPOS)); if ((pos.flags & SWP.NOMOVE) != 0) { return(IntPtr.Zero); } var hwndSource = WinInterop.HwndSource.FromHwnd(hwnd); if (hwndSource != null) { var wnd = (Window)hwndSource.RootVisual; if (wnd == null) { return(IntPtr.Zero); } } bool changedPos = false; // *********************** // Here you check the values inside the pos structure // if you want to override them just change the pos // structure and set changedPos to true // *********************** // this is a simplified version that doesn't work in high-dpi settings // pos.cx and pos.cy are in "device pixels" and MinWidth and MinHeight // are in "WPF pixels" (WPF pixels are always 1/96 of an inch - if your // system is configured correctly). var minWidth = MinMainWidth; var minHeight = MinMainHeight; var monitor = NativeMethods.MonitorFromPoint(new Point(0, 0), NativeMethods.MonitorDefaultToNearest); if (monitor != IntPtr.Zero) { var monitorInfo = new MONITORINFO(); NativeMethods.GetMonitorInfo(monitor, monitorInfo); var workingArea = monitorInfo.rcWork; if (workingArea.Width < minWidth) { minWidth = workingArea.Width; } if (workingArea.Height < minHeight) { minHeight = workingArea.Height; } } if (pos.cx < minWidth + (SystemParameters.ResizeFrameVerticalBorderWidth * 2)) { pos.cx = minWidth + (int)(SystemParameters.ResizeFrameVerticalBorderWidth * 2); changedPos = true; } if (pos.cy < minHeight + (SystemParameters.ResizeFrameHorizontalBorderHeight * 2)) { pos.cy = minHeight + (int)(SystemParameters.ResizeFrameHorizontalBorderHeight * 2); changedPos = true; } // *********************** // end of "logic" // *********************** if (!changedPos) { return(IntPtr.Zero); } Marshal.StructureToPtr(pos, lParam, true); handeled = true; } break; } return(IntPtr.Zero); }