Пример #1
0
        private static IntPtr WndProc(IntPtr hWnd, uint message, IntPtr wParam, IntPtr lParam)
        {
            switch (message)
            {
            case Win32.WM_SIZE:
            {
                return(IntPtr.Zero);
            }

            case Win32.WM_PAINT:
            {
                Win32.PAINTSTRUCT ps = new Win32.PAINTSTRUCT();

                IntPtr hDC        = Win32.BeginPaint(hWnd, out ps);
                var    dimensions = GetWindowDimensions(hWnd);
                Win32.StretchDIBits(hDC, 0, 0, WindowWidth, WindowHeight, 0, 0, dimensions.Width, GlobalOffscreenBuffer.Height, GlobalOffscreenBuffer.Memory, ref GlobalOffscreenBuffer.Info, 0, (uint)TernaryRasterOperations.SRCCOPY);
                Win32.EndPaint(hWnd, ref ps);

                return(IntPtr.Zero);
            }

            case Win32.WM_DESTROY:
            {
                IsRunning = false;
                Win32.PostQuitMessage(0);
                return(IntPtr.Zero);
            }

            default:
            {
                return(Win32.DefWindowProc(hWnd, message, wParam, lParam));
            }
            }
        }
Пример #2
0
        protected bool OnPaint(IntPtr hWnd)
        {
            var ps = new Win32.PAINTSTRUCT();

            if (OffScreenGraphics == null)
            {
                return(false);
            }

            var hdc    = Win32.BeginPaint(hWnd, ref ps);
            var hdcMem = OffScreenGraphics.GetHdc();

            try
            {
                using (Gdi g = Gdi.FromHdc(hdc, ps.rcPaint))
                {
                    using (Gdi gMem = Gdi.FromHdc(hdcMem, Rectangle.Empty))
                    {
                        Rectangle rect = ps.rcPaint;

                        try
                        {
                            DrawScreenOn(gMem, rect, _currentScrollPosition);
                        }
                        catch (COMException ex)
                        {
                            throw;
                        }
                        catch (Exception)
                        {
                            throw;
                        }

                        g.BitBlt(rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top, gMem, rect.Left, rect.Top,
                                 TernaryRasterOperations.SRCCOPY);
                    }
                }
            }
            finally
            {
                OffScreenGraphics.ReleaseHdc(hdcMem);
                Win32.EndPaint(hWnd, ref ps);
            }

            return(true);
        }
Пример #3
0
        bool OnPaint(IntPtr hWnd)
        {
            if (CurrentTransition == null)
            {
                return(false);
            }

            var ps = new Win32.PAINTSTRUCT();

            IntPtr hdc = Win32.BeginPaint(hWnd, ref ps);

            IntPtr hdcMem = _offScreenGraphics.GetHdc();

            using (Gdi g = Gdi.FromHdc(hdc, ps.rcPaint))
            {
                using (Gdi gMem = Gdi.FromHdc(hdcMem, Rectangle.Empty))
                {
                    Rectangle rect = ps.rcPaint;

                    try
                    {
                        CurrentTransition.DrawScreenOn(gMem, ps.rcPaint);
                    }
                    catch (Exception)
                    {
                        throw;
                    }

                    g.BitBlt(rect.Left, rect.Top, rect.Width, rect.Height, hdcMem, rect.Left, rect.Top,
                             TernaryRasterOperations.SRCCOPY);
                }
            }

            _offScreenGraphics.ReleaseHdc(hdcMem);
            Win32.EndPaint(hWnd, ref ps);
            return(true);
        }
Пример #4
0
		protected override void WndProc(ref Message m)
		{
			switch(m.Msg)
			{
				//Do all painting in WM_PAINT to reduce flicker.
				case (int)Msgs.WM_ERASEBKGND:
					return;

				case (int)Msgs.WM_PAINT:

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

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

					using(Graphics screenGraphics = Graphics.FromHdc(screenHdc)) 
					{
						// Get the area to be updated.
						Rectangle clipRect = paintStruct.rcPaint;

						// 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);
						if (width > 0 && 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 printClienteMessage = Message.Create(m.HWnd, (int)Msgs.WM_PRINTCLIENT, hdc, IntPtr.Zero);  
									DefWndProc(ref printClienteMessage);
									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);
							}
						}
					}

					User32.EndPaint(m.HWnd, ref paintStruct);
					return;
	
				case (int)Msgs.WM_SIZE:
					// Repaint on every resize.
					MdiClient.Invalidate();
					break;
					

				case (int)Msgs.WM_NCCALCSIZE:
					// If AutoScroll is set to false, hide the scrollbars when the control
					// calculates its non-client area.
					if(!AutoScroll)
                        User32.ShowScrollBar(m.HWnd, (int)Fwk.Controls.Win32.DocpanelEnums.ScrollBars.SB_BOTH, 0 /*false*/);
					break;
			}
		
			base.WndProc(ref m);
		}
Пример #5
0
		protected void OnWM_PAINT(ref Message m)
		{
			// Paint message occurs after the window is created and we have
			// entered the message loop. So this is a good place to handle focus
			if (_grabFocus)
				GrabTheFocus();

			Win32.PAINTSTRUCT ps = new Win32.PAINTSTRUCT();

			// Have to call BeginPaint whenever processing a WM_PAINT message
			IntPtr hDC = WindowsAPI.BeginPaint(m.HWnd, ref ps);

			Win32.RECT rectRaw = new Win32.RECT();

			// Grab the screen rectangle of the window
			WindowsAPI.GetWindowRect(this.Handle, ref rectRaw);

			// Convert to a client size rectangle
			Rectangle rectWin = new Rectangle(0, 0,
				rectRaw.right - rectRaw.left,
				rectRaw.bottom - rectRaw.top);

			// Create a graphics object for drawing
			using(Graphics g = Graphics.FromHdc(hDC))
			{
				// Create bitmap for drawing onto
				using (Bitmap memoryBitmap = new Bitmap(rectWin.Width, rectWin.Height))
				{
				using(Graphics h = Graphics.FromImage(memoryBitmap))
				{
					// Draw the background area
					DrawBackground(h, rectWin);

					// Draw the actual menu items
					DrawAllCommands(h);
				}

				// Blit bitmap onto the screen
				g.DrawImageUnscaled(memoryBitmap, 0, 0);
			}
			}

			// Don't forget to end the paint operation!
			WindowsAPI.EndPaint(m.HWnd, ref ps);
		}
Пример #6
0
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
            //Do all painting in WM_PAINT to reduce flicker.
            case (int)Msgs.WM_ERASEBKGND:
                return;

            case (int)Msgs.WM_PAINT:

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

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

                using (Graphics screenGraphics = Graphics.FromHdc(screenHdc))
                {
                    // Get the area to be updated.
                    Rectangle clipRect = paintStruct.rcPaint;

                    // 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);
                    if (width > 0 && 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 printClienteMessage = Message.Create(m.HWnd, (int)Msgs.WM_PRINTCLIENT, hdc, IntPtr.Zero);
                                DefWndProc(ref printClienteMessage);
                                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);
                        }
                    }
                }

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

            case (int)Msgs.WM_SIZE:
                // Repaint on every resize.
                MdiClient.Invalidate();
                break;


            case (int)Msgs.WM_NCCALCSIZE:
                // If AutoScroll is set to false, hide the scrollbars when the control
                // calculates its non-client area.
                if (!AutoScroll)
                {
                    User32.ShowScrollBar(m.HWnd, (int)Fwk.Controls.Win32.DocpanelEnums.ScrollBars.SB_BOTH, 0 /*false*/);
                }
                break;
            }

            base.WndProc(ref m);
        }
Пример #7
0
        protected void OnWM_PAINT(ref Message m)
        {
            Win32.PAINTSTRUCT ps = new Win32.PAINTSTRUCT();

            // Have to call BeginPaint whenever processing a WM_PAINT message
            IntPtr hDC = User32.BeginPaint(m.HWnd, ref ps);

            Win32.RECT rectRaw = new Win32.RECT();

            // Grab the screen rectangle of the window
            User32.GetWindowRect(this.Handle, ref rectRaw);

            // Convert to a client size rectangle
            Rectangle rectWin = new Rectangle(0, 0,
                                              rectRaw.right - rectRaw.left,
                                              rectRaw.bottom - rectRaw.top);

            // Create a graphics object for drawing
            using(Graphics g = Graphics.FromHdc(hDC))
            {
                // Create bitmap for drawing onto
                Bitmap memoryBitmap = new Bitmap(rectWin.Width, rectWin.Height);

                using(Graphics h = Graphics.FromImage(memoryBitmap))
                {
                    // Draw the background area
                    DrawBackground(h, rectWin);

                    // Draw the actual menu items
                    DrawAllCommands(h);
                }

                // Blit bitmap onto the screen
                g.DrawImageUnscaled(memoryBitmap, 0, 0);
            }

            // Don't forget to end the paint operation!
            User32.EndPaint(m.HWnd, ref ps);
        }
Пример #8
0
 public static extern bool EndPaint(IntPtr hwnd, ref Win32.PAINTSTRUCT lpPaint);
Пример #9
0
 public static extern IntPtr BeginPaint(IntPtr hwnd, ref Win32.PAINTSTRUCT lpPaint);
Пример #10
0
        /// <summary>
        /// Overrides <see cref="M:System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message@)"/>.
        /// </summary>
        /// <param name="m">The Windows <see cref="T:System.Windows.Forms.Message"/> to process.</param>
        protected override void WndProc(ref Message message)
        {
            const int WM_PAINT = 0x000F;
            const int WM_PRINTCLIENT = 0x0318;
            const int WM_ERASEBKGND = 0x0014;

            switch (message.Msg)
            {
                case WM_HSCROLL:
                case WM_VSCROLL:
                case WM_MOUSEWHEEL:
                    if (OnScrollBarChanged != null)
                    {
                        OnScrollBarChanged(this);
                    }
                    break;

                case WM_ERASEBKGND:
                    //removes flicker
                    return;

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

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

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

                        //Draw Internal Graphics
                        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
                    Win32.EndPaint(message.HWnd, ref paintStruct);
                    return;
            }
            base.WndProc(ref message);

        }