示例#1
0
        /// <summary>
        /// Perform your logic-operations here
        /// </summary>
        /// <param name="seconds">Time in seconds since the last Tick-call</param>
        protected virtual void OnTick(double seconds)
        {
            if (this.TrackTargetWindow)
            {
                WinAPI.WINDOWINFO info = new WinAPI.WINDOWINFO();
                if (WinAPI.GetWindowInfo(this.hWnd, ref info))
                {
                    int width  = info.rcWindow.Right - info.rcWindow.Left;
                    int height = info.rcWindow.Bottom - info.rcWindow.Top;
                    if (this.Location.X != info.rcClient.Left ||
                        this.Location.Y != info.rcClient.Top)
                    {
                        this.Location = new System.Drawing.Point(info.rcClient.Left, info.rcClient.Top);
                    }
                    if (this.Width != info.rcClient.Right - info.rcClient.Left ||
                        this.Height != info.rcClient.Bottom - info.rcClient.Top)
                    {
                        this.Size = new System.Drawing.Size(info.rcClient.Right - info.rcClient.Left, info.rcClient.Bottom - info.rcClient.Top);
                        this.OnResize();
                    }
                    WinAPI.SetWindowPos(this.hWnd, this.handle, info.rcWindow.Left, info.rcWindow.Top, width, height, 0);
                }
            }

            OnTickEvent(new DeltaEventArgs(seconds, this));
        }
示例#2
0
        public override void Attach(IntPtr hWnd)
        {
            WinAPI.WINDOWINFO info = new WinAPI.WINDOWINFO();
            if (!WinAPI.GetWindowInfo(hWnd, ref info))
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }

            this.hWnd = hWnd;
            this.Renderer.InitializeDevice(this.Handle, new Vector2(info.rcClient.Right - info.rcClient.Left, info.rcClient.Bottom - info.rcClient.Top));
            base.Attach(hWnd);
        }
示例#3
0
        public override void Window(ProcessWindowStyle windowStyle, IntPtr sideBySideWith)
        {
            if ((_mapInfoParentWindow == null) || !WinAPI.IsWindow(_mapInfoParentWindow) || !_mapInfoApp.Visible)
            {
                _mapInfoApp.Visible = true;
                _mapInfoProcess = GetMapInfoProcess(_mapInfoProcsPreStart);
                if (_mapInfoProcess == null) return;
                _mapInfoParentWindow = _mapInfoProcess.MainWindowHandle;
            }

            System.Windows.Forms.Screen mapInfoScreen = System.Windows.Forms.Screen.FromHandle(_mapInfoParentWindow);
            Rectangle mapInfoWorkingArea = mapInfoScreen.WorkingArea;

            System.Windows.Forms.Screen hluScreen =
                System.Windows.Forms.Screen.FromHandle(Process.GetCurrentProcess().MainWindowHandle);

            WinAPI.WINDOWINFO winfo = new WinAPI.WINDOWINFO();
            winfo.cbSize = (uint)Marshal.SizeOf(winfo);
            WinAPI.GetWindowInfo(_mapInfoParentWindow, ref winfo);

            // Set the window style based on the parameter passed to the procedure
            switch (windowStyle)
            {
                case ProcessWindowStyle.Hidden:
                    _mapInfoApp.Visible = false;
                    break;
                case ProcessWindowStyle.Maximized:
                    _mapInfoApp.Visible = true;
                    if ((winfo.rcClient.Width < mapInfoScreen.WorkingArea.Width) ||
                         (winfo.rcClient.Bottom < mapInfoScreen.WorkingArea.Height))
                    {
                        WinAPI.ShowWindow(_mapInfoParentWindow, (int)WinAPI.WindowStates.SW_SHOWNORMAL);
                        WinAPI.ShowWindow(_mapInfoParentWindow, (int)WinAPI.WindowStates.SW_SHOWMAXIMIZED);
                    }
                    break;
                case ProcessWindowStyle.Minimized:
                    _mapInfoApp.Visible = true;
                    WinAPI.ShowWindow(_mapInfoParentWindow, (int)WinAPI.WindowStates.SW_SHOWMINIMIZED);
                    break;
                case ProcessWindowStyle.Normal:
                    _mapInfoApp.Visible = true;
                    if (sideBySideWith != IntPtr.Zero)
                    {
                        WinAPI.RECT sideBySideRect;
                        if (WinAPI.GetWindowRect(sideBySideWith, out sideBySideRect))
                        {
                            int gisWinWidth = hluScreen.WorkingArea.Width - sideBySideRect.Width;
                            if (gisWinWidth <= 0) return;
                            WinAPI.MoveWindow(sideBySideWith, 0, 0, sideBySideRect.Width, sideBySideRect.Height, true);
                            WinAPI.MoveWindow(_mapInfoParentWindow, sideBySideRect.Width, 0, gisWinWidth,
                                hluScreen.WorkingArea.Height, false);
                        }
                    }
                    else
                    {
                        WinAPI.ShowWindow(_mapInfoParentWindow, (int)WinAPI.WindowStates.SW_SHOWNORMAL);
                    }
                    break;
            }
        }
示例#4
0
 /// <summary>
 /// Gets a struct containing information about the window, including screen and client rectangles.
 /// </summary>
 /// <returns></returns>
 public WinAPI.WINDOWINFO GetWindowInfo()
 {
     WinAPI.WINDOWINFO info = new WinAPI.WINDOWINFO(true);
     WinAPI.GetWindowInfo(this.Handle, ref info);
     return(info);
 }