Example #1
0
        public Magnifier(Form form)
        {
            if (form == null)
            {
                throw new ArgumentNullException("form");
            }

            this.form                   = form;
            this.form.Resize           += new EventHandler(form_Resize);
            this.form.FormClosing      += new FormClosingEventHandler(form_FormClosing);
            this.updateTimer            = new Timer();
            this.updateTimer.Interval   = WinUser.USER_TIMER_MINIMUM;
            this.updateTimer.Tick      += new EventHandler(updateTimer_Tick);
            this.animateTimer           = new Timer();
            this.animateTimer.Interval  = 50;
            this.animateTimer.Tick     += new EventHandler(animateTimer_Tick);
            this.magnificationFactor    = 2.0f;
            this.magnificatorWindowRect = new RECT();
            this.isInitialized          = Magnification.MagInitialize();

            if (this.isInitialized)
            {
                this.CreateMagnifier();
                this.updateTimer.Start();
            }
        }
Example #2
0
 private void DestroyMagnifier()
 {
     if (isInitialized)
     {
         Magnification.MagUninitialize();
     }
 }
Example #3
0
        private void CreateMagnifier()
        {
            if (!this.isInitialized)
            {
                return;
            }

            IntPtr hInst = Kernel32.GetModuleHandle(null);

            this.form.AllowTransparency = true;
            this.form.TransparencyKey   = Color.Empty;
            this.form.Opacity           = 0;
            User32.GetClientRect(this.form.Handle, ref this.magnificatorWindowRect);
            this.hwndMagnificator = User32.CreateWindow(
                0,
                Magnification.WC_MAGNIFIER,
                "MagnifierWindow",
                (int)WinUser.WS_VISIBLE | (int)WinUser.WS_CHILD | (int)Magnification.MagnifierStyle.MS_SHOWMAGNIFIEDCURSOR,
                this.magnificatorWindowRect.left,
                this.magnificatorWindowRect.top,
                this.magnificatorWindowRect.right,
                this.magnificatorWindowRect.bottom,
                this.form.Handle,
                IntPtr.Zero,
                hInst,
                IntPtr.Zero
                );

            if (this.hwndMagnificator == IntPtr.Zero)
            {
                return;
            }

            Magnification.Transformation matrix = new Magnification.Transformation(this.magnificationFactor);

            Magnification.MagSetWindowTransform(this.hwndMagnificator, ref matrix);
        }
Example #4
0
        private void UpdateMaginifier()
        {
            if (!this.isInitialized || this.hwndMagnificator == IntPtr.Zero)
            {
                return;
            }

            //POINT mousePosition = new POINT();
            RECT rect = new RECT();

            //User32.GetCursorPos(ref mousePosition);

            int width  = (int)((this.magnificatorWindowRect.right - this.magnificatorWindowRect.left) / this.magnificationFactor);
            int height = (int)((this.magnificatorWindowRect.bottom - this.magnificatorWindowRect.top) / this.magnificationFactor);

            rect.left = Magnifier.X /*mousePosition.x*/ - width / 2;
            rect.top  = Magnifier.Y /*mousePosition.y*/ - height / 2;

            if (rect.left < 0)
            {
                rect.left = 0;
            }

            if (rect.left > User32.GetSystemMetrics(WinUser.SM_CXSCREEN) - width)
            {
                rect.left = User32.GetSystemMetrics(WinUser.SM_CXSCREEN) - width;
            }

            if (rect.top < 0)
            {
                rect.top = 0;
            }

            if (rect.top > User32.GetSystemMetrics(WinUser.SM_CYSCREEN) - height)
            {
                rect.top = User32.GetSystemMetrics(WinUser.SM_CYSCREEN) - height;
            }

            rect.right  = rect.left + width;
            rect.bottom = rect.top + height;

            if (this.form == null)
            {
                this.updateTimer.Stop();
                this.animateTimer.Stop();
                return;
            }

            if (this.form.IsDisposed)
            {
                this.updateTimer.Enabled = false;
                return;
            }

            Magnification.MagSetWindowSource(this.hwndMagnificator, rect);
            User32.SetWindowPos(
                this.form.Handle,
                Magnification.HWND_TOPMOST,
                0,
                0,
                0,
                0,
                (int)WinUser.SWP_NOSIZE | (int)WinUser.SWP_NOMOVE | (int)WinUser.SWP_NOACTIVATE
                );

            User32.InvalidateRect(this.hwndMagnificator, IntPtr.Zero, true);
            this.animateTimer.Start();
        }