Example #1
0
 private void DoPopupFormPaint()
 {
     if (FOnPaint != null)
     {
         PAINTSTRUCT vPaintStruct = new PAINTSTRUCT();
         IntPtr      vDC          = (IntPtr)User.BeginPaint(FPopupWindow, ref vPaintStruct);
         try
         {
             HCCanvas vCanvas = new HCCanvas(vDC);
             try
             {
                 RECT vRect = new RECT();
                 User.GetClientRect(FPopupWindow, ref vRect);
                 FOnPaint(vCanvas, vRect);
             }
             finally
             {
                 vCanvas.Dispose();
             }
         }
         finally
         {
             User.EndPaint(FPopupWindow, ref vPaintStruct);
         }
     }
 }
Example #2
0
 protected override void WndProc(ref Message m)
 {
     if (m.Msg == 15)
     {
         if (!this._bPainting)
         {
             this._bPainting = true;
             PAINTSTRUCT ps = new PAINTSTRUCT();
             NativeMethods.BeginPaint(m.HWnd, ref ps);
             try
             {
                 this.DrawProgressBar(m.HWnd);
             }
             catch
             {
             }
             NativeMethods.ValidateRect(m.HWnd, ref ps.rcPaint);
             NativeMethods.EndPaint(m.HWnd, ref ps);
             this._bPainting = false;
             m.Result        = Result.TRUE;
         }
         else
         {
             base.WndProc(ref m);
         }
     }
     else
     {
         base.WndProc(ref m);
     }
 }
Example #3
0
            //拦截消息
            protected override void WndProc(ref Message m)
            {
                switch (m.Msg)
                {
                case WM_PAINT:
                    if (!_bPainting)
                    {
                        _bPainting = true;
                        PAINTSTRUCT ps = new PAINTSTRUCT();
                        NativeMethods.BeginPaint(m.HWnd, ref ps);
                        DrawUpDownButton();
                        NativeMethods.EndPaint(m.HWnd, ref ps);
                        _bPainting = false;
                        m.Result   = TRUE;
                    }
                    else
                    {
                        base.WndProc(ref m);
                    }
                    break;

                default:
                    base.WndProc(ref m);
                    break;
                }
            }
Example #4
0
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
            case WM_ERASEBKGND:
                return;

            case WM_PAINT:
                PAINTSTRUCT paintStruct = new PAINTSTRUCT();
                IntPtr      screenHdc   = BeginPaint(m.HWnd, ref paintStruct);

                Bitmap f = RenderRawFrame();
                f = effect.Render(f);

                using (Graphics screen = Graphics.FromHdc(screenHdc))
                {
                    screen.DrawImage(f, this.ClientRectangle);
                }
                EndPaint(m.HWnd, ref paintStruct);
                return;

            default:
                base.WndProc(ref m);
                break;
            }
        }
            protected override void WndProc(ref Message m)
            {
                switch (m.Msg)
                {
                case WM_ERASEBKGND:
                    return;

                case (int)WinApi.Messages.WM_NCPAINT:
                    NCPaint(ref m);
                    return;

                case WM_PAINT:
                    PAINTSTRUCT paintStruct = new PAINTSTRUCT();
                    IntPtr      screenHdc   = BeginPaint(m.HWnd, ref paintStruct);

                    using (Graphics screenGraphics = Graphics.FromHdc(screenHdc))
                    {
                        Rectangle clipRect = new Rectangle(paintStruct.rcPaint.left,
                                                           paintStruct.rcPaint.top,
                                                           paintStruct.rcPaint.right - paintStruct.rcPaint.left,
                                                           paintStruct.rcPaint.bottom - paintStruct.rcPaint.top);

                        int width  = (mdiClient.ClientRectangle.Width > 0 ? mdiClient.ClientRectangle.Width : 0);
                        int height = (mdiClient.ClientRectangle.Height > 0 ? mdiClient.ClientRectangle.Height : 0);

                        using (Image i = new Bitmap(width, height))
                        {
                            using (Graphics g = Graphics.FromImage(i))
                            {
                                IntPtr  hdc = g.GetHdc();
                                Message printClientMessage = Message.Create(m.HWnd, WM_PRINTCLIENT, hdc, IntPtr.Zero);
                                DefWndProc(ref printClientMessage);
                                g.ReleaseHdc(hdc);

                                OnPaint(new PaintEventArgs(g, clipRect));
                            }

                            screenGraphics.DrawImage(i, mdiClient.ClientRectangle);
                        }
                    }

                    EndPaint(m.HWnd, ref paintStruct);
                    return;

                case WM_SIZE:
                    mdiClient.Invalidate();
                    break;

                case WM_NCCALCSIZE:
                    NCCalcSize(ref m);
                    return;
                }

                if (m.Msg == (int)WM_FORM_ACTIVE_CHANGED)
                {
                    OnUpdateMDITabsState(m.WParam);
                }

                base.WndProc(ref m);
            }
Example #6
0
        public static IntPtr BeginPaint(HandleRef hWnd, ref PAINTSTRUCT lpPaint)
        {
            IntPtr result = BeginPaint(hWnd.Handle, ref lpPaint);

            GC.KeepAlive(hWnd.Wrapper);
            return(result);
        }
Example #7
0
        public static BOOL EndPaint(HandleRef hWnd, ref PAINTSTRUCT lpPaint)
        {
            BOOL result = EndPaint(hWnd.Handle, ref lpPaint);

            GC.KeepAlive(hWnd.Wrapper);
            return(result);
        }
Example #8
0
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
            case WM.WM_PAINT:
                if (!_bPainting)
                {
                    _bPainting = true;

                    PAINTSTRUCT ps = new PAINTSTRUCT();

                    NativeMethods.BeginPaint(m.HWnd, ref ps);
                    DrawTrackBar(m.HWnd);
                    NativeMethods.ValidateRect(m.HWnd, ref ps.rcPaint);
                    NativeMethods.EndPaint(m.HWnd, ref ps);

                    _bPainting = false;
                    m.Result   = Result.TRUE;
                }
                else
                {
                    base.WndProc(ref m);
                }
                break;

            default:
                base.WndProc(ref m);
                break;
            }
        }
        // Actual rendering is here
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
            case WM_ERASEBKGND:
                return;

            case WM_PAINT:
                PAINTSTRUCT paintStruct = new PAINTSTRUCT();
                IntPtr      screenHdc   = BeginPaint(m.HWnd, ref paintStruct);

                if (effect.Texture != null)
                {
                    Bitmap f = effect.Render(null);     // no need to supply new texture since image is statis. render current texture to bitmap
                    using (Graphics screen = Graphics.FromHdc(screenHdc))
                    {
                        screen.DrawImage(f, this.ClientRectangle);     // Draw current texture to bitmap
                    }
                }


                EndPaint(m.HWnd, ref paintStruct);
                return;

            default:
                base.WndProc(ref m);
                break;
            }
        }
Example #10
0
            protected override void WndProc(ref Message m)
            {
                switch (m.Msg)
                {
                case (int)WindowMessages.WM_PAINT:
                    if (!_bPainting)
                    {
                        PAINTSTRUCT ps = new PAINTSTRUCT();
                        _bPainting = true;
                        Win32.BeginPaint(m.HWnd, ref ps);
                        DrawUpDownButton();
                        Win32.EndPaint(m.HWnd, ref ps);
                        _bPainting = false;
                        m.Result   = Win32.TRUE;
                    }
                    else
                    {
                        base.WndProc(ref m);
                    }
                    break;

                default:
                    base.WndProc(ref m);
                    break;
                }
            }
Example #11
0
        //处理重绘事件
        private void WmPaint(ref Message m)
        {
            if (base.DropDownStyle == ComboBoxStyle.Simple)
            {
                base.WndProc(ref m);
                return;
            }

            if (base.DropDownStyle == ComboBoxStyle.DropDown)
            {
                if (!_bPainting)
                {
                    PAINTSTRUCT ps =
                        new PAINTSTRUCT();

                    _bPainting = true;
                    NativeMethods.BeginPaint(m.HWnd, ref ps);

                    RenderComboBox(ref m);

                    NativeMethods.EndPaint(m.HWnd, ref ps);
                    _bPainting = false;
                    m.Result   = Result.TRUE;
                }
                else
                {
                    base.WndProc(ref m);
                }
            }
            else
            {
                base.WndProc(ref m);
                RenderComboBox(ref m);
            }
        }
Example #12
0
        /// <summary>
        ///  A custom windows procedure that processes events for the splash screen
        ///  window.  the WM_CREATE, WM_DESTROY, WM_TIMER, and WM_PAINT messages are handled
        ///  specifically.
        /// </summary>
        /// <param name="hwnd">The handle of the window.</param>
        /// <param name="msg">The windows message identifier.</param>
        /// <param name="wParam">The *Word* Message parameters.</param>
        /// <param name="lParam">The *Long* Message parameters.</param>
        /// <returns>A return value adequate to the message sent.</returns>
        protected virtual int WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam)
        {
            switch (msg)
            {
            case WM_CREATE:
                if ((_transparencyKey.IsEmpty == false) && IsLayeringSupported())
                {
                    SetLayeredWindowAttributes(hwnd, ColorTranslator.ToWin32(_transparencyKey), 0, LWA_COLORKEY);
                }

                if (_minimumDuration > 0)
                {
                    _timer = SetTimer(hwnd, 1, _minimumDuration, IntPtr.Zero);
                }
                break;

            case WM_DESTROY:
                PostQuitMessage(0);
                break;

            case WM_ERASEBKGND:
                return(1);

            case WM_PAINT:
            {
                var ps  = new PAINTSTRUCT();
                var hdc = BeginPaint(hwnd, ref ps);

                if (hdc != IntPtr.Zero)
                {
                    var g = Graphics.FromHdcInternal(hdc);
                    g.DrawImage(_image, 0, 0, _width, _height);
                    if (_customizer != null)
                    {
                        _customizer(new SplashScreenSurface(g, new Rectangle(0, 0, _width - 1, _height - 1)));
                    }
                    g.Dispose();
                }

                EndPaint(hwnd, ref ps);
            }
                return(0);

            case WM_TIMER:
                KillTimer(hwnd, _timer);
                _timer = 0;
                _minimumDurationComplete = true;

                if (_waitingForTimer)
                {
                    PostMessage(hwnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
                }
                return(0);
            }
            return(DefWindowProc(hwnd, msg, wParam, lParam));
        }
Example #13
0
 protected override void WndProc(ref Message m)
 {
     if (m.Msg == 0xF /*WM_PAINT*/ && ((FlatNumericUpDown)updown.Parent).BorderStyle == BorderStyle.FixedSingle)
     {
         var s = new PAINTSTRUCT();
         IntBeginPaint(updown.Handle, ref s);
         using (var g = Graphics.FromHdc(s.hdc))
         {
             var enabled = updown.Enabled;
             using (var backBrush = new SolidBrush(enabled ? ((FlatNumericUpDown)updown.Parent).BackColor : SystemColors.Control))
             {
                 g.FillRectangle(backBrush, updown.ClientRectangle);
             }
             var r1 = new Rectangle(0, 0, updown.Width, updown.Height / 2);
             var r2 = new Rectangle(0, updown.Height / 2, updown.Width, updown.Height / 2 + 1);
             var p  = updown.PointToClient(MousePosition);
             if (enabled && updown.ClientRectangle.Contains(p))
             {
                 using (var b = new SolidBrush(((FlatNumericUpDown)updown.Parent).ButtonHighlightColor))
                 {
                     if (r1.Contains(p))
                     {
                         g.FillRectangle(b, r1);
                     }
                     else
                     {
                         g.FillRectangle(b, r2);
                     }
                 }
                 using (var pen = new Pen(((FlatNumericUpDown)updown.Parent).BorderColor))
                 {
                     g.DrawLines(pen,
                                 new[] { new Point(0, 0), new Point(0, updown.Height),
                                         new Point(0, updown.Height / 2), new Point(updown.Width, updown.Height / 2) });
                 }
             }
             g.FillPolygon(Brushes.Black, GetUpArrow(r1));
             g.FillPolygon(Brushes.Black, GetDownArrow(r2));
         }
         m.Result = (IntPtr)1;
         base.WndProc(ref m);
         IntEndPaint(updown.Handle, ref s);
     }
     else if (m.Msg == 0x0014 /*WM_ERASEBKGND*/)
     {
         using (var g = Graphics.FromHdcInternal(m.WParam))
             g.FillRectangle(Brushes.White, updown.ClientRectangle);
         m.Result = (IntPtr)1;
     }
     else
     {
         base.WndProc(ref m);
     }
 }
Example #14
0
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
            case (int)WindowMessages.MOUSEWHEEL:
                return;

            case (int)WindowMessages.WM_PAINT:
                switch (this.DropDownStyle)
                {
                case ComboBoxStyle.DropDown:
                    if (!this._BeginPainting)
                    {
                        PAINTSTRUCT ps = new PAINTSTRUCT();
                        this._BeginPainting = true;
                        Win32.BeginPaint(m.HWnd, ref ps);
                        this.DrawComboBox(ref m);
                        Win32.EndPaint(m.HWnd, ref ps);
                        this._BeginPainting = false;
                        m.Result            = Win32.TRUE;
                    }
                    else
                    {
                        base.WndProc(ref m);
                    }
                    break;

                case ComboBoxStyle.DropDownList:
                    base.WndProc(ref m);
                    this.DrawComboBox(ref m);
                    break;

                default:
                    base.WndProc(ref m);
                    break;
                }
                break;

            default:
                base.WndProc(ref m);
                break;
            }
        }
Example #15
0
        private void PaintWithDoubleBuffer(ref Message m)
        {
            using (Graphics g = Graphics.FromImage(myDoubleBufferBitmap))
            {
                // TODO: use correct background brush for non-standard background
                g.FillRectangle(SystemBrushes.Window, 0, 0, ClientSize.Width, ClientSize.Height);
                IntPtr hdc = g.GetHdc();
                // the treeview ignores the drawing options anyway
                Win32Declarations.SendMessage(Handle, Win32Declarations.WM_PRINTCLIENT, hdc, IntPtr.Zero);
                g.ReleaseHdc(hdc);
            }
            PAINTSTRUCT ps = new PAINTSTRUCT();

            Win32Declarations.BeginPaint(m.HWnd, ref ps);
            using (Graphics g = Graphics.FromHdc(ps.hdc))
            {
                g.DrawImage(myDoubleBufferBitmap, 0, 0);
            }
            Win32Declarations.EndPaint(m.HWnd, ref ps);
        }
Example #16
0
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
            case (int)Msgs.WM_PAINT:
                if (!ShouldPaint)
                {
                    break;
                }

                PAINTSTRUCT lpPaint = new PAINTSTRUCT();
                using (Graphics graphics = Graphics.FromHdcInternal(BeginPaint(Handle, ref lpPaint)))
                    Paint(graphics, size);

                EndPaint(Handle, ref lpPaint);

                break;
            }

            base.WndProc(ref m);
        }
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
            case WM_PAINT:
                if (TextLabel.Length > 0 && this.TextLength == 0)
                {
                    PAINTSTRUCT ps = new PAINTSTRUCT();
                    Graphics    gr = Graphics.FromHdc(BeginPaint(m.HWnd, out ps));
                    var         br = new SolidBrush(this.BackColor);
                    gr.FillRectangle(br, gr.VisibleClipBounds);
                    br.Dispose();
                    gr.DrawString(TextLabel, this.Font, Brushes.Gray, 0, 1);
                    gr.Dispose();
                    EndPaint(m.HWnd, ref ps);
                }
                break;
            }

            base.WndProc(ref m);
        }
Example #18
0
        protected override void     WndProc(ref Message aMessage)
        {
            if (aMessage.Msg == (int)WM.PAINT)
            {
                PAINTSTRUCT lPStruct = new PAINTSTRUCT();
                BeginPaint(aMessage.HWnd, ref lPStruct);
                using (Graphics lGraphics = Graphics.FromHwndInternal(aMessage.HWnd))
                {
                    SliderPaint(new PaintEventArgs(lGraphics, this.ClientRectangle));
                }
                EndPaint(aMessage.HWnd, ref lPStruct);

                return;
            }

            if (aMessage.Msg == (int)WM.LBUTTONDOWN && mReadOnly)
            {
                return;
            }

            base.WndProc(ref aMessage);
        }
Example #19
0
 private void WmPaint(ref Message m)
 {
     if (m.WParam == IntPtr.Zero)
     {
         // コントロールに描画する
         var ps  = new PAINTSTRUCT();
         var hdc = BeginPaint(m.HWnd, ref ps);
         if (hdc != IntPtr.Zero)
         {
             var clip = ps.rcPaint.Rectangle;
             if (clip.Width > 0 && clip.Height > 0)
             {
                 IntPtr oldPal = SetUpPalette(hdc, false, false);
                 // ダブルバッファの処理
                 var bufferContext = BufferedGraphicsManager.Current;
                 using (BufferedGraphics bufferedGraphics = bufferContext.Allocate(hdc,
                                                                                   Owner.ClientRectangle)) {
                     bufferedGraphics.Graphics.SetClip(clip);
                     using (var pevent = new PaintEventArgs(bufferedGraphics.Graphics, clip)) {
                         OnCustomDraw(pevent);
                         bufferedGraphics.Render();
                     }
                 }
                 if (oldPal != IntPtr.Zero)
                 {
                     SelectPalette(hdc, oldPal, 0);
                 }
             }
             EndPaint(m.HWnd, ref ps);
         }
     }
     else
     {
         // WPARAM にセットされた HDC に描画を行う
         OnCustomDraw(m.WParam);
     }
 }
        protected override void WndProc(ref Message message)
        {
            switch (message.Msg)
            {
            case 15: {
                var    paintStruct = new PAINTSTRUCT();
                IntPtr targetDC    = BeginPaint(message.HWnd, ref paintStruct);
                var    rectangle   = new Rectangle(paintStruct.rcPaint_left, paintStruct.rcPaint_top,
                                                   paintStruct.rcPaint_right - paintStruct.rcPaint_left,
                                                   paintStruct.rcPaint_bottom - paintStruct.rcPaint_top);
                if ((rectangle.Width > 0) && (rectangle.Height > 0))
                {
                    using (BufferedGraphics graphics = BufferedGraphicsManager.Current.Allocate(targetDC, base.ClientRectangle)) {
                        IntPtr  hdc = graphics.Graphics.GetHdc();
                        Message m   = Message.Create(base.Handle, 0x318, hdc, IntPtr.Zero);
                        DefWndProc(ref m);
                        graphics.Graphics.ReleaseHdc(hdc);
                        graphics.Render();
                    }
                }
                EndPaint(message.HWnd, ref paintStruct);
                message.Result = IntPtr.Zero;
                return;
            }

            case 20:
                message.Result = (IntPtr)1;
                return;

                /*case 0x20:
                 * LinkLabel2.SetCursor(LinkLabel2.LoadCursor(0, 0x7f00));
                 * message.Result = IntPtr.Zero;
                 * return;*/
            }
            base.WndProc(ref message);
        }
 private static extern IntPtr BeginPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
Example #22
0
    public DrawEventArgs(IGraphPort device, PAINTSTRUCT pStruct)
	{
        fPaintStruct = pStruct;
		fDevice = device;
	}
Example #23
0
	public static extern bool EndPaint (IntPtr hwnd, ref PAINTSTRUCT ps);
 internal static extern bool EndPaint(IntPtr hwnd, ref PAINTSTRUCT ps);
Example #25
0
		private extern static IntPtr Win32BeginPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
Example #26
0
 internal static extern bool EndPaint(IntPtr hWnd, [In] ref PAINTSTRUCT lpPaint);
Example #27
0
 public static extern IntPtr BeginPaint(IntPtr hwnd, out PAINTSTRUCT lpPaint);
        protected override void WndProc(ref Message m)
        {
            PAINTSTRUCT ps = new PAINTSTRUCT();

            switch (m.Msg)
            {
                case WM_PAINT:
                    if (!_bPainting && _maskTimer > 1)
                    {
                        _bPainting = true;
                        // start painting engine
                        BeginPaint(m.HWnd, ref ps);
                        drawMask();
                        // done
                        EndPaint(m.HWnd, ref ps);
                        _bPainting = false;
                    }
                    else
                    {
                        base.WndProc(ref m);
                    }
                    break;

                case WM_TIMER:
                    if ((_safeTimer > 50) && (!inArea()))
                    {
                        stopTimer();
                    }
                    else
                    {
                        if (_bFadeIn == true)
                            fadeIn();
                        else
                            fadeOut();
                    }
                    _safeTimer++;
                    base.WndProc(ref m);
                    break;

                case WM_MOUSEMOVE:
                    if (inArea())
                        fadeIn();
                    else
                        fadeOut();
                    base.WndProc(ref m);
                    break;

                case WM_MOUSELEAVE:
                    fadeOut();
                    base.WndProc(ref m);
                    break;

                case WM_LBUTTONDOWN:
                    Dispose();
                    base.WndProc(ref m);
                    break;

                default:
                    base.WndProc(ref m);
                    break;
            }
        }
		protected override void WndProc(ref Message message) {
			switch (message.Msg) {
				case 15: {
					var paintStruct = new PAINTSTRUCT();
					IntPtr targetDC = BeginPaint(message.HWnd, ref paintStruct);
					var rectangle = new Rectangle(paintStruct.rcPaint_left, paintStruct.rcPaint_top,
					                              paintStruct.rcPaint_right - paintStruct.rcPaint_left,
					                              paintStruct.rcPaint_bottom - paintStruct.rcPaint_top);
					if ((rectangle.Width > 0) && (rectangle.Height > 0)) {
						using (BufferedGraphics graphics = BufferedGraphicsManager.Current.Allocate(targetDC, base.ClientRectangle)) {
							IntPtr hdc = graphics.Graphics.GetHdc();
							Message m = Message.Create(base.Handle, 0x318, hdc, IntPtr.Zero);
							DefWndProc(ref m);
							graphics.Graphics.ReleaseHdc(hdc);
							graphics.Render();
						}
					}
					EndPaint(message.HWnd, ref paintStruct);
					message.Result = IntPtr.Zero;
					return;
				}
				case 20:
					message.Result = (IntPtr) 1;
					return;

					/*case 0x20:
					LinkLabel2.SetCursor(LinkLabel2.LoadCursor(0, 0x7f00));
					message.Result = IntPtr.Zero;
					return;*/
			}
			base.WndProc(ref message);
		}
        protected override void WndProc(ref Message m)
        {
            PAINTSTRUCT ps = new PAINTSTRUCT();
            switch (m.Msg)
            {
                case WM_PAINT:
                    if (!_bPainting)
                    {
                        _bPainting = true;
                        // start painting engine
                        BeginPaint(m.HWnd, ref ps);
                        if (!_bFading)
                        drawCombo();
                        ValidateRect(m.HWnd, ref ps.rcPaint);
                        // done
                        EndPaint(m.HWnd, ref ps);
                        _bPainting = false;
                        m.Result = MSG_HANDLED;
                    }
                    else
                    {
                        base.WndProc(ref m);
                    }
                    break;

                case WM_MOUSEMOVE:
                    if (!_bMoved)
                    {
                        if (TransitionGraphic != null)
                        {
                            RECT tr = comboButton();
                            _bFading = true;
                            cTransition ts = new cTransition(m.HWnd, IntPtr.Zero, TransitionGraphic, new Rectangle(tr.Left, tr.Top, tr.Right - tr.Left, tr.Bottom - tr.Top));
                        }
                    }
                    if (overButton())
                        _bMoved = true;
                    base.WndProc(ref m);
                    break;

                case WM_MOUSELEAVE:
                    _bMoved = false;
                    _bFading = false;
                    base.WndProc(ref m);
                    break;

                default:
                    base.WndProc(ref m);
                    break;
            }
        }
        /// <summary>
        /// Invokes the default window procedure associated with this window.
        /// </summary>
        /// <param name="m">A <see cref="System.Windows.Forms.Message"/> that is associated with the current Windows message. </param>
        protected override void WndProc(ref Message m)
        {
            switch(m.Msg)
            {
                //Do all painting in WM_PAINT to reduce flicker.
                case WM_ERASEBKGND:
                    return;

                case WM_PAINT:

                    // This code is influenced by Steve McMahon's article:
                    // "Painting in the MDI Client Area".
                    // http://vbaccelerator.com/article.asp?id=4306

                    // Use Win32 to get a Graphics object.
                    PAINTSTRUCT paintStruct = new PAINTSTRUCT();
                    IntPtr screenHdc = BeginPaint(m.HWnd, ref paintStruct);

                    using(Graphics screenGraphics = Graphics.FromHdc(screenHdc))
                    {
                        // Get the area to be updated.
                        Rectangle clipRect = new Rectangle(
                            paintStruct.rcPaint.left,
                            paintStruct.rcPaint.top,
                            paintStruct.rcPaint.right - paintStruct.rcPaint.left,
                            paintStruct.rcPaint.bottom - paintStruct.rcPaint.top);

                        // Double-buffer by painting everything to an image and
                        // then drawing the image.
                        int width = (mdiClient.ClientRectangle.Width > 0 ? mdiClient.ClientRectangle.Width : 0);
                        int height = (mdiClient.ClientRectangle.Height > 0 ? mdiClient.ClientRectangle.Height : 0);
                        using(Image i = new Bitmap(width, height))
                        {
                            using(Graphics g = Graphics.FromImage(i))
                            {
                                // This code comes from J Young's article:
                                // "Generating missing Paint event for TreeView and ListView".
                                // http://www.codeproject.com/cs/miscctrl/genmissingpaintevent.asp

                                // Draw base graphics and raise the base Paint event.
                                IntPtr hdc = g.GetHdc();
                                Message printClientMessage =
                                    Message.Create(m.HWnd, WM_PRINTCLIENT, hdc, IntPtr.Zero);
                                DefWndProc(ref printClientMessage);
                                g.ReleaseHdc(hdc);

                                // Draw the image here.
                                if(image != null)
                                    DrawImage(g, clipRect);

                                // Call our OnPaint here to draw graphics over the
                                // original and raise our Paint event.
                                OnPaint(new PaintEventArgs(g, clipRect));
                            }

                            // Now draw all the graphics at once.
                            screenGraphics.DrawImage(i, mdiClient.ClientRectangle);
                        }
                    }

                    EndPaint(m.HWnd, ref paintStruct);
                    return;

                case WM_SIZE:

                    // Repaint on every resize.
                    mdiClient.Invalidate();
                    break;

                case WM_NCCALCSIZE:

                    // If AutoScroll is set to false, hide the scrollbars when the control
                    // calculates its non-client area.
                    if(!autoScroll)
                        ShowScrollBar(m.HWnd, SB_BOTH, 0 /*false*/);
                    break;
            }

            base.WndProc(ref m);
        }
Example #32
0
 internal static extern bool EndPaint(IntPtr hWnd, ref PAINTSTRUCT lpPaint);
        protected override void WndProc(ref Message m)
        {
            PAINTSTRUCT ps = new PAINTSTRUCT();

            switch (m.Msg)
            {
                case WM_PAINT:
                    if (!_bPainting)
                    {
                        _bPainting = true;
                        // start painting engine
                        BeginPaint(m.HWnd, ref ps);
                        drawScrollBar();
                        ValidateRect(m.HWnd, ref ps.rcPaint);
                        // done
                        EndPaint(m.HWnd, ref ps);
                        _bPainting = false;
                        m.Result = MSG_HANDLED;
                    }
                    else
                    {
                        base.WndProc(ref m);
                    }
                    break;

                case WM_SIZE:
                case WM_MOVE:
                    sizeCheck();
                    base.WndProc(ref m);
                    break;

                default:
                    base.WndProc(ref m);
                    break;
            }
        }
Example #34
0
 public static extern bool EndPaint(IntPtr hWnd, ref PAINTSTRUCT paintStruct);
        /// <summary>
        /// message pump
        /// </summary>
        /// <param name="m">message struct</param>
        protected override void WndProc(ref Message m)
        {
            TOOLINFO tI = new TOOLINFO(0);
            RECT tR = new RECT();
            Size sZ = new Size();
            Point pT = new Point();
            DrawEventArgs dR;

            switch (m.Msg)
            {
                // window painting
                case WM_PAINT:
                    PAINTSTRUCT tPaint = new PAINTSTRUCT();
                    string sT = String.Empty;
                    string sC = String.Empty;
                    if (_eCustomStyle != TipStyle.Default)
                    {
                        if (!_bPainting)
                        {
                            _bPainting = true;
                            // start painting engine
                            BeginPaint(m.HWnd, ref tPaint);
                            dR = getEventParams();
                            if (Draw != null)
                            {
                                dR.Hdc = tPaint.hdc;
                                Draw(this, dR);
                            }
                            else
                            {
                                drawTip(dR.Bounds, dR.Caption, dR.Title, tPaint.hdc, dR.ParentWnd);
                            }
                            // done
                            EndPaint(m.HWnd, ref tPaint);
                            _bPainting = false;
                        }
                        else
                        {
                            base.DefWndProc(ref m);
                        }
                    }
                    else
                    {
                        // call the old proc
                        base.WndProc(ref m);
                    }
                    break;

                case (WM_NOTIFY | WM_REFLECT):
                    NMHDR nM = new NMHDR(0);
                    RtlMoveMemory(ref nM, m.LParam, Marshal.SizeOf(nM));
                    if (nM.hwndFrom == _hTipWnd)
                    {
                        switch (nM.code)
                        {
                            //case TTN_GETDISPINFOA: <- not working
                            //case TTN_GETDISPINFOW:
                            //    break;
                            case TTN_SHOW:
                                Point tp = new Point();
                                SendMessage(_hTipWnd, TTM_GETCURRENTTOOL, 0, ref tI);
                                _hParentWnd = tI.hwnd;
                                //// SIZE ////
                                // tip size set globally
                                if ((_oSize.Width != 0) || (_oSize.Height != 0))
                                {
                                    tR.Left = 0;
                                    tR.Top = 0;
                                    tR.Bottom = _oSize.Height;
                                    tR.Right = _oSize.Width;
                                    SendMessage(_hTipWnd, TTM_ADJUSTRECT, 1, ref tR);
                                    SetWindowPos(_hTipWnd,
                                                HWND_TOP,
                                                0, 0,
                                                tR.Right, tR.Bottom,
                                                SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
                                    m.Result = RETURN_TRUE;
                                }
                                else
                                {
                                    // tip size set individually
                                    tI.uId = _hTipWnd;
                                    // get tool parent
                                    SendMessage(_hTipWnd, TTM_GETCURRENTTOOL, 0, ref tI);
                                    if (tI.hwnd != IntPtr.Zero)
                                    {
                                        // test the dictionary
                                        if (_dSize.ContainsKey(tI.hwnd))
                                        {
                                            sZ = _dSize[tI.hwnd];
                                            // size tip
                                            if ((sZ.Width != 0) || (sZ.Height != 0))
                                            {
                                                tR.Left = 0;
                                                tR.Top = 0;
                                                tR.Bottom = sZ.Height;
                                                tR.Right = sZ.Width;
                                                SendMessage(_hTipWnd, TTM_ADJUSTRECT, 1, ref tR);
                                                SetWindowPos(_hTipWnd,
                                                            HWND_TOP,
                                                            0, 0,
                                                            tR.Right, tR.Bottom,
                                                            SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
                                                m.Result = RETURN_TRUE;
                                            }
                                        }
                                        // calculate size
                                        else if (_eCustomStyle != TipStyle.Default)
                                        {
                                            StringFormat sF = new StringFormat();
                                            sF.Alignment = StringAlignment.Near;
                                            sF.LineAlignment = StringAlignment.Near;
                                            Rectangle rDmn = new Rectangle(4, sZ.Height, (tR.Right - tR.Left), (tR.Bottom - tR.Top));
                                            calcTipSize(ref rDmn, tI.hwnd, _oTipFont, _dCaption[tI.hwnd], sF);
                                            sF.Dispose();
                                            SetWindowPos(_hTipWnd,
                                                        HWND_TOP,
                                                        0, 0,
                                                        rDmn.Width + 8, rDmn.Height + sZ.Height + 8,
                                                        SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
                                            m.Result = RETURN_TRUE;
                                        }
                                    }
                                }
                                //// POSITION ////
                                if (_ePosition != TipPosition.AutoPosition)
                                {
                                    if (tI.hwnd != IntPtr.Zero)
                                    {
                                        GetCursorPos(ref tp);
                                        GetWindowRect(_hTipWnd, ref tR);
                                        // offset for global size
                                        if ((_oSize.Width != 0) || (_oSize.Height != 0))
                                        {
                                            tR.Bottom = tR.Top + _oSize.Height;
                                            tR.Right = tR.Left + _oSize.Width;
                                        }
                                        // offset for tp size mod
                                        else if (_dSize.ContainsKey(tI.hwnd))
                                        {
                                            sZ = _dSize[tI.hwnd];
                                            tR.Bottom = tR.Top + sZ.Height;
                                            tR.Right = tR.Left + sZ.Width;
                                        }
                                        int iX = 0;
                                        int iY = 0;
                                        if ((_bShowAlways) || (_bClickable))
                                        {
                                            iX = 12;
                                            iY = 12;
                                        }
                                        else
                                        {
                                            iX = 20;
                                            iY = 20;
                                        }
                                        switch (_ePosition)
                                        {
                                            case TipPosition.BottomCenter:
                                                tp.Y += iX;
                                                tp.X -= ((tR.Right - tR.Left) / 2);
                                                break;
                                            case TipPosition.BottomLeft:
                                                tp.Y += iX;
                                                tp.X -= ((tR.Right - tR.Left) - 4);
                                                break;
                                            case TipPosition.BottomRight:
                                                tp.Y += iX;
                                                tp.X += 12;
                                                break;
                                            case TipPosition.LeftCenter:
                                                tp.Y -= ((tR.Bottom - tR.Top) / 2);
                                                tp.X -= ((tR.Right - tR.Left) + 4);
                                                break;
                                            case TipPosition.RightCenter:
                                                tp.Y -= ((tR.Bottom - tR.Top) / 2);
                                                tp.X += 20;
                                                break;
                                            case TipPosition.TopCenter:
                                                tp.Y -= ((tR.Bottom - tR.Top) + 4);
                                                tp.X -= ((tR.Right - tR.Left) / 2);
                                                break;
                                            case TipPosition.TopLeft:
                                                tp.Y -= ((tR.Bottom - tR.Top) + 4);
                                                tp.X -= ((tR.Right - tR.Left) + 4);
                                                break;
                                            case TipPosition.TopRight:
                                                tp.Y -= ((tR.Bottom - tR.Top) + 4);
                                                break;
                                        }
                                        SetWindowPos(_hTipWnd,
                                                    HWND_TOP,
                                                    tp.X, tp.Y,
                                                    0, 0,
                                                    SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
                                    }
                                    m.Result = RETURN_TRUE;
                                }
                                if (PopUp != null) PopUp();
                                tipCapture();
                                break;

                            case TTN_POP:
                                if (Pop != null) Pop();
                                //base.WndProc(ref m);
                                break;

                            //case NM_CUSTOMDRAW:
                            //NMTTCUSTOMDRAW nC = new NMTTCUSTOMDRAW(); //<- can't get this to work..
                            //RtlMoveMemory(ref nC, m.LParam, Marshal.SizeOf(nC));
                            //    break;
                            default:
                                base.WndProc(ref m);
                                break;
                        }
                    }
                    break;

                // mouse events
                case WM_MOUSEMOVE:
                    if (m.HWnd == _hTipWnd)
                    {
                        if (MouseMove != null)
                        {
                            GetCursorPos(ref pT);
                            MouseMove(pT);
                        }
                        if (_bClickable)
                            m.Result = RETURN_TRUE;
                        else
                            base.WndProc(ref m);
                        trackMouse(m.HWnd);
                    }
                    if ((!_bShowAlways) && (!_bClickable))
                        base.WndProc(ref m);
                    break;
                case WM_MOUSELEAVE:
                    if ((_bShowAlways) || (_bClickable))
                    {
                        if (IsVisible())
                        {
                            Hide();
                        }
                    }
                    base.WndProc(ref m);
                    break;
                case WM_LBUTTONDOWN:
                    if (m.HWnd == _hTipWnd)
                    {
                        if (LeftButtonDown != null)
                        {
                            dR = getEventParams();
                            dR.Hdc = GetDC(_hTipWnd);
                            LeftButtonDown(this, dR);
                            ReleaseDC(_hTipWnd, dR.Hdc);
                        }
                        if (_bClickable)
                            m.Result = RETURN_TRUE;
                        else
                            base.WndProc(ref m);
                    }
                    break;
                case WM_LBUTTONUP:
                    if (m.HWnd == _hTipWnd)
                    {
                        if (LeftButtonUp != null)
                        {
                            dR = getEventParams();
                            dR.Hdc = GetDC(_hTipWnd);
                            LeftButtonUp(this, dR);
                            ReleaseDC(_hTipWnd, dR.Hdc);
                        }
                        if (_bCloseButton)
                        {
                            if (closeButtonHitTest())
                            {
                                Hide();
                            }
                            else
                            {
                                base.WndProc(ref m);
                            }
                        }
                        else if (_bClickable)
                        {
                            m.Result = RETURN_TRUE;
                        }
                        else
                        {
                            base.WndProc(ref m);
                        }
                    }
                    break;
                case WM_LBUTTONDBLCLK:
                    if (m.HWnd == _hTipWnd)
                    {
                        if (LeftButtonDblClick != null)
                        {
                            dR = getEventParams();
                            dR.Hdc = GetDC(_hTipWnd);
                            LeftButtonDblClick(this, dR);
                            ReleaseDC(_hTipWnd, dR.Hdc);
                        }
                        if (_bClickable)
                            m.Result = RETURN_TRUE;
                        else
                            base.WndProc(ref m);
                    }
                    break;
                case WM_MBUTTONDOWN:
                    if (m.HWnd == _hTipWnd)
                    {
                        if (MiddleButtonDown != null)
                        {
                            dR = getEventParams();
                            dR.Hdc = GetDC(_hTipWnd);
                            MiddleButtonDown(this, dR);
                            ReleaseDC(_hTipWnd, dR.Hdc);
                        }
                        if (_bClickable)
                            m.Result = RETURN_TRUE;
                        else
                            base.WndProc(ref m);
                    }
                    break;
                case WM_MBUTTONUP:
                    if (m.HWnd == _hTipWnd)
                    {
                        if (MiddleButtonUp != null)
                        {
                            dR = getEventParams();
                            dR.Hdc = GetDC(_hTipWnd);
                            MiddleButtonUp(this, dR);
                            ReleaseDC(_hTipWnd, dR.Hdc);
                        }
                        if (_bClickable)
                            m.Result = RETURN_TRUE;
                        else
                            base.WndProc(ref m);
                    }
                    break;
                case WM_MBUTTONDBLCLK:
                    if (m.HWnd == _hTipWnd)
                    {
                        if (MiddleButtonDblClick != null)
                        {
                            dR = getEventParams();
                            dR.Hdc = GetDC(_hTipWnd);
                            MiddleButtonDblClick(this, dR);
                            ReleaseDC(_hTipWnd, dR.Hdc);
                        }
                        if (_bClickable)
                            m.Result = RETURN_TRUE;
                        else
                            base.WndProc(ref m);
                    }
                    break;
                case WM_RBUTTONDOWN:
                    if (m.HWnd == _hTipWnd)
                    {
                        if (RightButtonDown != null)
                        {
                            dR = getEventParams();
                            dR.Hdc = GetDC(_hTipWnd);
                            RightButtonDown(this, dR);
                            ReleaseDC(_hTipWnd, dR.Hdc);
                        }
                        if (_bClickable)
                            m.Result = RETURN_TRUE;
                        else
                            base.WndProc(ref m);
                    }
                    break;
                case WM_RBUTTONUP:
                    if (m.HWnd == _hTipWnd)
                    {
                        if (RightButtonUp != null)
                        {
                            dR = getEventParams();
                            dR.Hdc = GetDC(_hTipWnd);
                            RightButtonDown(this, dR);
                            ReleaseDC(_hTipWnd, dR.Hdc);
                        }
                        if (_bClickable)
                            m.Result = RETURN_TRUE;
                        else
                            base.WndProc(ref m);
                    }
                    break;
                case WM_RBUTTONDBLCLK:
                    if (m.HWnd == _hTipWnd)
                    {
                        if (RightButtonUp != null)
                        {
                            dR = getEventParams();
                            dR.Hdc = GetDC(_hTipWnd);
                            RightButtonDblClick(this, dR);
                            ReleaseDC(_hTipWnd, dR.Hdc);
                        }
                        if (_bClickable)
                            m.Result = RETURN_TRUE;
                        else
                            base.WndProc(ref m);
                    }
                    break;
                case WM_MOUSEWHEEL:
                    if (m.HWnd == _hTipWnd)
                    {
                        if (MouseWheel != null)
                        {
                            MouseWheel();
                        }
                    }
                    break;

                case WM_TIMER:
                    switch (m.WParam.ToInt32())
                    {
                        case HOVER_SIGNALED:
                            if (IsVisible())
                            {
                                if ((_bShowAlways) || (_bClickable))
                                {
                                    GetWindowRect(_hTipWnd, ref tR);
                                    GetCursorPos(ref pT);
                                    if (PtInRect(ref tR, pT))
                                        m.Result = RETURN_TRUE;
                                    else
                                        base.WndProc(ref m);
                                }
                                else
                                {
                                    base.WndProc(ref m);
                                }
                            }
                            else
                            {
                                base.WndProc(ref m);
                            }
                            break;
                        case FADER_SIGNALED: //<-vista only
                            if (IsVisible())
                            {
                                if ((_bShowAlways) || (_bClickable))
                                {
                                    GetWindowRect(_hTipWnd, ref tR);
                                    GetCursorPos(ref pT);
                                    if (PtInRect(ref tR, pT))
                                        m.Result = RETURN_TRUE;
                                    else
                                        base.WndProc(ref m);
                                }
                                else if (_eCustomStyle != TipStyle.Default)
                                {
                                    if (!_bTimerActive)
                                    {
                                        startFadeTimer();
                                        m.Result = RETURN_TRUE;
                                    }
                                    else
                                    {
                                        m.Result = RETURN_TRUE;
                                    }
                                }
                                else
                                {
                                    base.WndProc(ref m);
                                }
                            }
                            break;
                        case TIMER_FADE:
                            _iSafeTimer += 1;
                            if (_iSafeTimer > (_iFadeDelay / 50))
                                stopFadeTimer();
                            else
                                tipFade();
                            break;
                        default:
                            base.WndProc(ref m);
                            break;
                    }
                    break;

                case WM_SETFOCUS:
                    if (!_bCanFocus)
                    {
                        if (_hParentWnd != IntPtr.Zero)
                            SetFocus(_hParentWnd);
                        if (_bClickable)
                        {
                            if (closeButtonHitTest())
                                SendMessage(_hTipWnd, WM_LBUTTONUP, 0, 0);
                        }
                    }
                    else
                    {
                        base.WndProc(ref m);
                    }
                    break;

                case WM_STYLECHANGED:
                    if (_eCustomStyle == TipStyle.Default)
                        SendMessage(_hTipWnd, TTM_SETTIPBKCOLOR, ColorTranslator.ToWin32(Color.LightYellow), 0); //<-added for xp
                    base.WndProc(ref m);
                    break;

                /*case WM_NCPAINT:
                    break;
                case WM_DESTROY:
                    break;
                case WM_ACTIVATEAPP:
                    break;
                 case WM_ACTIVATE:
                    break;
                case WM_KILLFOCUS:
                    break;
                 case WM_IME_NOTIFY:
                    break;
                 case WM_IME_SETCONTEXT:
                    break;
                 case WM_NCACTIVATE:
                    break;
                case WM_STYLECHANGING:
                    break;
                case WM_WINDOWPOSCHANGING:
                    break;
                case WM_WINDOWPOSCHANGED:
                    break;
                case WM_NCCALCSIZE:
                    break;
                // undocumented?
                case 0x410: // effects show/timer
                    break;
                case 0x418: // format
                    break;
                case 0x421: // title
                    break;
                case 0x407: //show/timer
                    break;*/

                default:
                    //Debug.Print(m.Msg.ToString());
                    base.WndProc(ref m);
                    break;
            }
        }
Example #36
0
 public static extern IntPtr EndPaint(IntPtr hWnd, ref PAINTSTRUCT lpPaint);
Example #37
0
        static void Main(string[] args)
        {
            var manager = new D3DManager();

            var windowProc = new WNDPROC((Win32API.HWND _hwnd, WM uMsg, Win32API.WPARAM wParam, Win32API.LPARAM lParam) =>
            {
                if (ImGui.ImGui_ImplWin32_WndProcHandler(_hwnd.Value, (uint)uMsg, wParam.Value, lParam.Value) != IntPtr.Zero)
                {
                    return(1);
                }

                switch (uMsg)
                {
                case WM.DESTROY:
                    manager.Dispose();
                    User32.PostQuitMessage(0);
                    return(0);

                case WM.RESIZE:
                    // manager.Resize(lParam.LowWord, lParam.HiWord);
                    s_width  = lParam.LowWord;
                    s_height = lParam.HiWord;
                    return(0);

                case WM.PAINT:
                    {
                        PAINTSTRUCT ps = default;
                        var hdc        = User32.BeginPaint(_hwnd, ref ps);
                        User32.EndPaint(_hwnd, ref ps);
                        return(0);
                    }

                case WM.MOUSEMOVE:
                    {
                        s_mouse.X = lParam.LowWord;
                        s_mouse.Y = lParam.HiWord;
                        return(0);
                    }

                case WM.LBUTTONDOWN:
                    {
                        // User32.SetCapture(_hwnd);
                        s_mouse.Buttons |= ButtonFlags.Left;
                        return(0);
                    }

                case WM.LBUTTONUP:
                    {
                        s_mouse.Buttons &= ~ButtonFlags.Left;
                        if (s_mouse.Buttons == 0)
                        {
                            // User32.ReleaseCapture();
                        }
                        return(0);
                    }

                case WM.MBUTTONDOWN:
                    {
                        // SetCapture(hWnd);
                        s_mouse.Buttons |= ButtonFlags.Middle;
                        return(0);
                    }

                case WM.MBUTTONUP:
                    {
                        s_mouse.Buttons &= ~ButtonFlags.Middle;
                        if (s_mouse.Buttons == 0)
                        {
                            // ReleaseCapture();
                        }
                        return(0);
                    }

                case WM.RBUTTONDOWN:
                    {
                        // SetCapture(hWnd);
                        s_mouse.Buttons |= ButtonFlags.Right;
                        return(0);
                    }

                case WM.RBUTTONUP:
                    {
                        s_mouse.Buttons &= ~ButtonFlags.Right;
                        if (s_mouse.Buttons == 0)
                        {
                            // ReleaseCapture();
                        }
                        return(0);
                    }

                case WM.MOUSEWHEEL:
                    {
                        s_clearWheel = false;
                        var d        = wParam.HiWord;
                        if (d > 0)
                        {
                            s_mouse.Wheel = 1;
                        }
                        else if (d < 0)
                        {
                            s_mouse.Wheel = -1;
                        }
                        else
                        {
                            s_mouse.Wheel = 0;
                        }
                        return(0);
                    }
                }

                return(User32.DefWindowProcW(_hwnd, uMsg, wParam, lParam));
            });
            var ptr = Marshal.GetFunctionPointerForDelegate(windowProc);

            var windowClass = new WNDCLASSEXW();

            windowClass.cbSize        = Marshal.SizeOf(typeof(WNDCLASSEXW));
            windowClass.style         = CS.HREDRAW | CS.VREDRAW;
            windowClass.lpfnWndProc   = ptr;
            windowClass.cbClsExtra    = 0;
            windowClass.cbWndExtra    = 0;
            windowClass.lpszClassName = WINDOW_CLASS;
            var register = User32.RegisterClassExW(ref windowClass);

            if (register == 0)
            {
                Console.WriteLine("fail to RegisterClassExW");
                return;
            }

            var hwnd = User32.CreateWindowExW(
                0,
                WINDOW_CLASS,
                "SharpImGui",
                WS.OVERLAPPEDWINDOW,
                32, 32,
                640, 480,
Example #38
0
 public static extern bool EndPaint(IntPtr hWnd, ref PAINTSTRUCT lpPaint);
 internal static extern IntPtr BeginPaint(IntPtr hwnd, ref PAINTSTRUCT ps);
        protected override void WndProc(ref Message m)
        {
            PAINTSTRUCT pntStrct = new PAINTSTRUCT();
            switch (m.Msg)
            {
                case WM_PAINT:
                    if (!_bPainting)
                    {
                        _bPainting = true;
                        // start painting engine
                        BeginPaint(m.HWnd, ref pntStrct);
                        drawTabControl();
                        ValidateRect(m.HWnd, ref pntStrct.rcPaint);
                        // done
                        EndPaint(m.HWnd, ref pntStrct);

                        _bPainting = false;
                    }
                    else
                    {
                        base.WndProc(ref m);
                    }
                    break;

                case WM_MOUSEMOVE:
                    // only necessary if vertically aligned..
                    drawTabControl();
                    base.WndProc(ref m);
                    break;

                case WM_MOUSELEAVE:
                    drawTabControl();
                    base.WndProc(ref m);
                    break;

                default:
                    base.WndProc(ref m);
                    break;
            }
        }
Example #41
0
		internal override PaintEventArgs PaintEventStart(ref Message msg, IntPtr handle, bool client) {
			IntPtr		hdc;
			PAINTSTRUCT	ps;
			PaintEventArgs	paint_event;
			RECT		rect;
			Rectangle	clip_rect;
			Hwnd		hwnd;

			clip_rect = new Rectangle();
			rect = new RECT();
			ps = new PAINTSTRUCT();

			hwnd = Hwnd.ObjectFromHandle(msg.HWnd);
			
			if (client) {
				if (Win32GetUpdateRect(msg.HWnd, ref rect, false)) {
					if (handle != msg.HWnd) {
						// We need to validate the window where the paint message
						// was generated, otherwise we'll never stop getting paint 
						// messages.
						Win32GetClientRect (msg.HWnd, out rect);
						Win32ValidateRect (msg.HWnd, ref rect);
						hdc = Win32GetDC (handle);
					} else {
						hdc = Win32BeginPaint (handle, ref ps);
						rect = ps.rcPaint;
					}
				} else {
					hdc = Win32GetDC(handle);
				}
				clip_rect = rect.ToRectangle ();
			} else {
				hdc = Win32GetWindowDC (handle);

				// HACK this in for now
				Win32GetWindowRect (handle, out rect);
				clip_rect = new Rectangle (0, 0, rect.Width, rect.Height);
			}

			// If we called BeginPaint, store the PAINTSTRUCT,
			// otherwise store hdc, so that PaintEventEnd can know
			// whether to call EndPaint or ReleaseDC.
			if (ps.hdc != IntPtr.Zero) {
				hwnd.drawing_stack.Push (ps);
			} else {
				hwnd.drawing_stack.Push (hdc);
			}
			
			Graphics dc = Graphics.FromHdc(hdc);
			hwnd.drawing_stack.Push (dc);

			paint_event = new PaintEventArgs(dc, clip_rect);

			return paint_event;
		}
Example #42
0
 protected void CustomProc(ref Message m)
 {
     switch (m.Msg)
     {
         case WM_PAINT:
             {
                 PAINTSTRUCT ps = new PAINTSTRUCT();
                 if (!_bPainting)
                 {
                     _bPainting = true;
                     BeginPaint(m.HWnd, ref ps);
                     PaintThis(ps.hdc, ps.rcPaint);
                     EndPaint(m.HWnd, ref ps);
                     _bPainting = false;
                     base.WndProc(ref m);
                 }
                 else
                 {
                     base.WndProc(ref m);
                 }
                 break;
             }
         case WM_CREATE:
             {
                 GetFrameSize();
                 FrameChanged();
                 m.Result = MSG_HANDLED;
                 base.WndProc(ref m);
                 break;
             }
         case WM_NCCALCSIZE:
             {
                 if (m.WParam != IntPtr.Zero && m.Result == IntPtr.Zero)
                 {
                     if (_bExtendIntoFrame)
                     {
                         NCCALCSIZE_PARAMS nc = (NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(NCCALCSIZE_PARAMS));
                         nc.rect0.Top -= (_tMargins.cyTopHeight > CaptionHeight ? CaptionHeight : _tMargins.cyTopHeight);
                         nc.rect1 = nc.rect0;
                         Marshal.StructureToPtr(nc, m.LParam, false);
                         m.Result = (IntPtr)WVR_VALIDRECTS;
                     }
                     base.WndProc(ref m);
                 }
                 else
                 {
                     base.WndProc(ref m);
                 }
                 break;
             }
         case WM_SYSCOMMAND:
             {
                 UInt32 param;
                 if (IntPtr.Size == 4)
                     param = (UInt32)(m.WParam.ToInt32());
                 else
                     param = (UInt32)(m.WParam.ToInt64());
                 if ((param & 0xFFF0) == SC_RESTORE)
                 {
                     this.Height = _iStoreHeight;
                 }
                 else if (this.WindowState == FormWindowState.Normal)
                 {
                     _iStoreHeight = this.Height;
                 }
                 base.WndProc(ref m);
                 break;
             }
         case WM_NCHITTEST:
             {
                 if (m.Result == (IntPtr)HIT_CONSTANTS.HTNOWHERE)
                 {
                     IntPtr res = IntPtr.Zero;
                     if (DwmDefWindowProc(m.HWnd, (uint)m.Msg, m.WParam, m.LParam, ref res))
                         m.Result = res;
                     else
                         m.Result = (IntPtr)HitTest();
                 }
                 else
                     base.WndProc(ref m);
                 break;
             }
         case WM_DWMCOMPOSITIONCHANGED:
         case WM_ACTIVATE:
             {
                 DwmExtendFrameIntoClientArea(this.Handle, ref _tMargins);
                 m.Result = MSG_HANDLED;
                 base.WndProc(ref m);
                 break;
             }
         default:
             {
                 base.WndProc(ref m);
                 break;
             }
     }
 }
Example #43
0
		private extern static bool Win32EndPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
Example #44
0
        // Actual rendering is here
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case WM_ERASEBKGND:
                    return;
                case WM_PAINT:
                    PAINTSTRUCT paintStruct = new PAINTSTRUCT();
                    IntPtr screenHdc = BeginPaint(m.HWnd, ref paintStruct);

                    if (Tasks != null)
                    {
                        using (var screen = Graphics.FromHdc(screenHdc))
                        {
                            screen.Clear(BackColor);

                            Int32 width = Width;
                            Int32 height = Height;

                            var pointOutline = new Pen(Color.Black, 1);
                            var pointOutlineSelected = new Pen(Color.Orange, 2);
                            var pointFill = new SolidBrush(Color.MediumPurple);
                            var pointFillCurrent = new SolidBrush(Color.Red);

                            var visitedLinkPen = new Pen(Color.DarkSlateBlue, 4);
                            var activeLinkPen = new Pen(Color.HotPink, 2);

                            if (Tasks.Count > 0)
                            {
                                // Draw Visited Links
                                if (Path.Count > 1)
                                {
                                    Int32 i = 0;
                                    DataPoint c = Path[i];
                                    do
                                    {
                                        i++;

                                        DataPoint n = Path[i];

                                        Int32 x0 = (Int32) (c.Location.X * width);
                                        Int32 y0 = (Int32) (c.Location.Y * height);
                                        Int32 x1 = (Int32) (n.Location.X * width);
                                        Int32 y1 = (Int32) (n.Location.Y * height);

                                        screen.DrawLine(visitedLinkPen, x0, y0, x1, y1);

                                        c = n;

                                    } while (i < Path.Count - 1);
                                }

                                // Draw Tasks
                                foreach (var t in Tasks)
                                {
                                    Int32 x = (Int32) (t.Location.X * width);
                                    Int32 y = (Int32) (t.Location.Y * height);

                                    var outlinePen = t.Equals(SelectedTask) ? pointOutlineSelected : pointOutline;
                                    var fillBrush = pointFill;

                                    screen.FillEllipse(fillBrush, x - TaskPointRadius, y - TaskPointRadius,
                                                       2 * TaskPointRadius, 2 * TaskPointRadius);
                                    screen.DrawEllipse(outlinePen, x - TaskPointRadius, y - TaskPointRadius,
                                                       2 * TaskPointRadius, 2 * TaskPointRadius);
                                }
                            }
                            else
                            {
                                screen.DrawString("Shift+Click to add tasks", new Font(Font.FontFamily, 12, FontStyle.Bold), new SolidBrush(Color.DarkGray), 10, 10);
                            }

                            // Draw Border
                            screen.DrawRectangle(pointOutline, 0, 0, width - 1, height - 1);
                        }
                    }

                    EndPaint(m.HWnd, ref paintStruct);
                    return;
                default:
                    base.WndProc(ref m);
                    break;
            }
        }
 private static extern bool EndPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
        /// <summary>
        ///  A custom windows procedure that processes events for the splash screen
        ///  window.  the WM_CREATE, WM_DESTROY, WM_TIMER, and WM_PAINT messages are handled
        ///  specifically.
        /// </summary>
        /// <param name="hwnd">The handle of the window.</param>
        /// <param name="msg">The windows message identifier.</param>
        /// <param name="wParam">The *Word* Message parameters.</param>
        /// <param name="lParam">The *Long* Message parameters.</param>
        /// <returns>A return value adequate to the message sent.</returns>
        protected virtual int WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam)
        {
            switch (msg)
            {
                case WM_CREATE:
                    if ((_transparencyKey.IsEmpty == false) && IsLayeringSupported())
                    {
                        SetLayeredWindowAttributes(hwnd, ColorTranslator.ToWin32(_transparencyKey), 0, LWA_COLORKEY);
                    }

                    if (_minimumDuration > 0)
                    {
                        _timer = SetTimer(hwnd, 1, _minimumDuration, IntPtr.Zero);
                    }
                    break;
                case WM_DESTROY:
                    PostQuitMessage(0);
                    break;
                case WM_ERASEBKGND:
                    return 1;
                case WM_PAINT:
                {
                    PAINTSTRUCT ps = new PAINTSTRUCT();
                    IntPtr hdc = BeginPaint(hwnd, ref ps);

                    if (hdc != IntPtr.Zero)
                    {
                        Graphics g = Graphics.FromHdcInternal(hdc);
                        g.DrawImage(_image, 0, 0, _width, _height);
                        if (_customizer != null)
                        {
                            _customizer(new SplashScreenSurface(g, new Rectangle(0, 0, _width - 1, _height - 1)));
                        }
                        g.Dispose();
                    }

                    EndPaint(hwnd, ref ps);
                }
                    return 0;
                case WM_TIMER:
                    KillTimer(hwnd, _timer);
                    _timer = 0;
                    _minimumDurationComplete = true;

                    if (_waitingForTimer)
                    {
                        PostMessage(hwnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
                    }
                    return 0;
            }
            return DefWindowProc(hwnd, msg, wParam, lParam);
        }
Example #47
0
 public static extern IntPtr BeginPaint(IntPtr hWnd, ref PAINTSTRUCT paintStruct);
        // Actual rendering is here
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case WM_ERASEBKGND:
                    return;
                case WM_PAINT:
                    PAINTSTRUCT paintStruct = new PAINTSTRUCT();
                    IntPtr screenHdc = BeginPaint(m.HWnd, ref paintStruct);

                    if (effect.Texture != null)
                    {
                        Bitmap f = effect.Render(null); // no need to supply new texture since image is statis. render current texture to bitmap
                        using (Graphics screen = Graphics.FromHdc(screenHdc))
                        {
                            screen.DrawImage(f, this.ClientRectangle); // Draw current texture to bitmap
                        }

                    }

                    EndPaint(m.HWnd, ref paintStruct);
                    return;
                default:
                    base.WndProc(ref m);
                    break;
            }
        }
Example #49
0
        /// <summary>Occurs when a Windows message is dispatched.</summary>
        /// <param name="message">Message to process.</param>
        /// <remarks>Overrides WM_PAINT, WM_ERASEBKGND.</remarks>
        protected override void WndProc(ref System.Windows.Forms.Message m)
        {
            const int WM_PAINT = 0x000F;
            const int WM_PRINTCLIENT = 0x0318;
            const int WM_ERASEBKGND = 0x0014;
            const int WM_MOUSEHOVER = 0x02A1;

            const int WM_NOTIFY = 0x004E;

            NMHDR nm1;
            bool messageProcessed = false;
            switch (m.Msg)
            {
                case (int)7: // WM_SETFOCUS
                    //try { base.WndProc(ref m); } // skip immediate parent to avoid focus problems
                    //catch{}
                    m.Result = IntPtr.Zero;
                    messageProcessed = true;
                    break;

                // case (int)WindowsMessage.WM_REFLECT + (int)WindowsMessage.WM_NOTIFY:
                case (int)(0x0400 + 0x1c00 + WM_NOTIFY):
                    m.Result = IntPtr.Zero;
                    nm1 = (NMHDR)m.GetLParam(typeof(NMHDR));
                    switch (nm1.code)
                    {
                        case (int)ListViewNotificationCodes.LVN_ITEMCHANGED:
                            messageProcessed = true;
                            break;

                        case (int)ListViewNotificationCodes.LVN_GETDISPINFOW:
                            OnDispInfoNotice(ref m, false);
                            messageProcessed = true;
                            break;

                        // ignore dragging as we are virtual and ListView doesnt like it.
                        case (int)ListViewNotificationCodes.LVN_BEGINDRAG:
                            OnBeginDrag(ref m);
                            messageProcessed = true;
                            break;

                        case (int)ListViewNotificationCodes.LVN_BEGINRDRAG:
                            OnBeginDrag(ref m);
                            messageProcessed = true;
                            break;

                        case (int)NotificationCodes.NM_CUSTOMDRAW:
                            m.Result = new IntPtr((int)OnCustomDraw(ref m));
                            messageProcessed = true;
                            break;

                        case (int)ListViewNotificationCodes.LVN_ODSTATECHANGED:
                            {
                                messageProcessed = true;
                                NMLVODSTATECHANGE lvod = (NMLVODSTATECHANGE)m.GetLParam(typeof(NMLVODSTATECHANGE));
                                int num1 = lvod.uOldState & (int)ListViewItemStates.LVIS_SELECTED;
                                int num2 = lvod.uNewState & (int)ListViewItemStates.LVIS_SELECTED;
                                if (num2 == num1)
                                    return;
                                this.OnSelectedIndexChanged(EventArgs.Empty);
                                break;
                            }

                        default:
                            break;
                    }
                    break;

                case WM_NOTIFY:
                    nm1 = (NMHDR)m.GetLParam(typeof(NMHDR));
                    if (nm1.code == (int)NotificationCodes.NM_RCLICK)
                    {
                        IntPtr header = (IntPtr)SendMessage(Handle, (int)ListViewMessages.LVM_GETHEADER, IntPtr.Zero, IntPtr.Zero);
                        uint curpos = GetMessagePos();
                        Point ptheader = PointToClient(new Point((int)(short)curpos, (int)curpos >> 16));
                        HDHITTESTINFO hdhti = new HDHITTESTINFO();
                        hdhti.pt = ptheader;
                        SendMessage(header, HeaderMessageCodes.HDM_HITTEST, IntPtr.Zero, ref hdhti);
                        OnColumnRightClick(new ColumnClickEventArgs(hdhti.iItem));
                    }
                    else if (nm1.code == (int)HeaderNotificationCodes.HDN_ITEMCLICKW)
                    {
                        if (OnCustomSort(ref m))
                        {
                            m.Result = IntPtr.Zero;
                            messageProcessed = true;
                        }
                    }
                    break;

                case WM_ERASEBKGND:
                    //removes flicker
                    return;

                case WM_MOUSEHOVER:
                    messageProcessed = true;
                    break;

                case WM_PAINT:
                    // The designer host does not call OnResize()
                    if (internalGraphics == null)
                        OnResize(EventArgs.Empty);

                    //Set up
                    RECT updateRect = new RECT();
                    if (GetUpdateRect(m.HWnd, ref updateRect, false) == 0)
                        break;

                    PAINTSTRUCT paintStruct = new PAINTSTRUCT();
                    IntPtr screenHdc = BeginPaint(m.HWnd, ref paintStruct);
                    using (Graphics screenGraphics = Graphics.FromHdc(screenHdc))
                    {

                        //Draw Internal Graphics
                        internalGraphics.Clear(this.BackColor);
                        IntPtr hdc = internalGraphics.GetHdc();
                        Message printClientMessage = Message.Create(Handle, WM_PRINTCLIENT, hdc, IntPtr.Zero);
                        DefWndProc(ref printClientMessage);
                        internalGraphics.ReleaseHdc(hdc);

                        //Add the missing OnPaint() call
                        OnPaint(new PaintEventArgs(internalGraphics, Rectangle.FromLTRB(
                            updateRect.left,
                            updateRect.top,
                            updateRect.right,
                            updateRect.bottom)));

                        //Draw Screen Graphics
                        screenGraphics.DrawImage(internalBitmap, 0, 0);
                    }

                    //Tear down
                    EndPaint(m.HWnd, ref paintStruct);
                    return;

                default:
                    break;
            }
            if (!messageProcessed)
            {
                try { base.WndProc(ref m); }
                catch { }
            }
        }
Example #51
0
 public static extern IntPtr BeginPaint(IntPtr hwnd, out PAINTSTRUCT lpPaint);
Example #52
0
 public static extern IntPtr BeginPaint(IntPtr hWnd, ref PAINTSTRUCT paintStruct);
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case WM_ERASEBKGND:
                    return;
                case WM_PAINT:
                    PAINTSTRUCT paintStruct = new PAINTSTRUCT();
                    IntPtr screenHdc = BeginPaint(m.HWnd, ref paintStruct);

                    Bitmap f = RenderRawFrame();
                    f = effect.Render(f);

                    using (Graphics screen = Graphics.FromHdc(screenHdc))
                    {
                        screen.DrawImage(f, this.ClientRectangle);
                    }
                    EndPaint(m.HWnd, ref paintStruct);
                    return;
                default:
                    base.WndProc(ref m);
                    break;
            }
        }
Example #54
0
        protected override void WndProc(ref Message m)
        {
            switch(m.Msg)
            {
                case WM_ERASEBKGND:
                case WM_PAINT:
                    if (Width == 0 || Height == 0)
                        return;

                    //Buffer vorbereiten:
                    if (buffer == null)
                    {
                        buffer = new Bitmap(Width, Height);
                    }
                    if (buffer.Width != Width || buffer.Height != Height)
                    {
                        buffer.Dispose();//!!!
                        buffer = new Bitmap(Width, Height);
                    }
                    //Hdc besorgen:
                    IntPtr hdc = m.WParam;
                    PAINTSTRUCT ps=new PAINTSTRUCT();
                    bool callEndPaint = false ;
                    Rectangle drawingRegion;
                    if (hdc == IntPtr.Zero)
                    {
                        hdc = BeginPaint(Handle, out ps);
                        callEndPaint = true;
                        drawingRegion=ps.rcPaint;
                    }
                    else
                    {
                        drawingRegion=ClientRectangle;
                    }
                    if (hdc == IntPtr.Zero)
                    { return; }
                    //auf Buffer zeichnen:
                    using (Graphics ownGx = Graphics.FromImage(buffer))
                    {
                        IntPtr ownHdc=ownGx.GetHdc();
                        Message newM = new Message();
                        newM.Msg=m.Msg;
                        newM.HWnd = Handle;
                        newM.WParam=ownHdc;
                        newM.LParam=m.LParam;
                        DefWndProc(ref newM);
                        ownGx.ReleaseHdc(ownHdc);
                        //man kann hier den Buffer beliebig manipulieren.
                        if (m.Msg == WM_PAINT) OnPaint(new PaintEventArgs(ownGx, drawingRegion));
                        else OnPaintBackground(new PaintEventArgs(ownGx, drawingRegion));
                    }
                    //Buffer zeichnen:
                    if(m.Msg==WM_PAINT)
                    {
                        using (Graphics gx = Graphics.FromHdc(hdc))
                        {
                            gx.DrawImage(buffer, drawingRegion, drawingRegion, GraphicsUnit.Pixel);
                        }
                    }
                    //Aufräumen:
                    if (callEndPaint)
                    { EndPaint(Handle, ref ps); }
                    m.Result = IntPtr.Zero;
                    return;
                default:
                    base.WndProc(ref m);
                    return;
            }
        }
Example #55
0
        protected override void WndProc(ref Message m)
        {
            try
            {
                switch (m.Msg)
                {
                case WM.WM_PAINT:
                    if (!_bPainting)
                    {
                        PAINTSTRUCT ps = new PAINTSTRUCT();

                        _bPainting = true;
                        NativeMethods.BeginPaint(m.HWnd, ref ps);
                        DrawScrollBar(m.HWnd, _maskControl.Handle);
                        NativeMethods.ValidateRect(m.HWnd, ref ps.rcPaint);
                        NativeMethods.EndPaint(m.HWnd, ref ps);
                        _bPainting = false;

                        m.Result = Result.TRUE;
                    }
                    else
                    {
                        base.WndProc(ref m);
                    }
                    break;

                case SBM.SBM_SETSCROLLINFO:
                    DrawScrollBar(m.HWnd, _maskControl.Handle, true, false);
                    base.WndProc(ref m);
                    break;

                case WM.WM_STYLECHANGED:
                    DrawScrollBar(m.HWnd, _maskControl.Handle, false, true);
                    base.WndProc(ref m);
                    break;

                case WM.WM_LBUTTONDOWN:
                    _lastMouseDownHistTest = ScrollBarHitTest(m.HWnd);
                    DrawScrollBar(m.HWnd, _maskControl.Handle);
                    base.WndProc(ref m);
                    break;

                case WM.WM_LBUTTONUP:
                case WM.WM_MOUSEMOVE:
                    DrawScrollBar(m.HWnd, _maskControl.Handle);
                    base.WndProc(ref m);
                    break;

                case WM.WM_MOUSELEAVE:
                    DrawScrollBar(m.HWnd, _maskControl.Handle);
                    base.WndProc(ref m);
                    break;

                case WM.WM_WINDOWPOSCHANGED:
                    WINDOWPOS pos = (WINDOWPOS)Marshal.PtrToStructure(
                        m.LParam, typeof(WINDOWPOS));
                    bool hide = (pos.flags & SWP.SWP_HIDEWINDOW) != 0;
                    bool show = (pos.flags & SWP.SWP_SHOWWINDOW) != 0;
                    if (hide)
                    {
                        _maskControl.SetVisibale(false);
                    }
                    else if (show)
                    {
                        _maskControl.SetVisibale(true);
                    }
                    _maskControl.CheckBounds(m.HWnd);
                    base.WndProc(ref m);
                    break;

                default:
                    base.WndProc(ref m);
                    break;
                }
            }
            catch
            {
            }
        }
Example #56
0
	public static extern IntPtr BeginPaint(IntPtr hwnd, ref PAINTSTRUCT ps);
Example #57
0
 public static extern bool EndPaint(IntPtr hWnd, ref PAINTSTRUCT paintStruct);
Example #58
0
            protected override void WndProc(ref Message m)
            {
                PAINTSTRUCT tPaint = new PAINTSTRUCT();
                switch (m.Msg)
                {
                    case WM_PAINT:
                        if (Parent.ToolStripStyle == ToolStripType.System)
                        {
                            base.WndProc(ref m);
                        }
                        else
                        {
                            if (!_bPainting)
                            {
                                _bPainting = true;
                                // start painting engine
                                BeginPaint(m.HWnd, ref tPaint);
                                drawCombo(_comboBox, _bMoved);
                                // done
                                EndPaint(m.HWnd, ref tPaint);
                                _bPainting = false;
                            }
                            else
                            {
                                base.WndProc(ref m);
                            }
                        }
                        break;

                    case WM_MOUSEMOVE:
                        _bMoved = true;
                        base.WndProc(ref m);
                        break;

                    case WM_MOUSELEAVE:
                        _bMoved = false;
                        base.WndProc(ref m);
                        break;

                    default:
                        base.WndProc(ref m);
                        break;
                }
            }