Пример #1
0
 internal static extern IntPtr BeginPaint(IntPtr hwnd, ref PI.PAINTSTRUCT ps);
Пример #2
0
 internal static extern bool EndPaint(IntPtr hwnd, ref PI.PAINTSTRUCT ps);
Пример #3
0
            private void WmPaint(ref Message m)
            {
                IntPtr hdc;
                PI.PAINTSTRUCT ps = new PI.PAINTSTRUCT();

                // Do we need to BeginPaint or just take the given HDC?
                if (m.WParam == IntPtr.Zero)
                    hdc = PI.BeginPaint(Handle, ref ps);
                else
                    hdc = m.WParam;

                // Create bitmap that all drawing occurs onto, then we can blit it later to remove flicker
                Rectangle realRect = CommonHelper.RealClientRectangle(Handle);

                // No point drawing when one of the dimensions is zero
                if ((realRect.Width > 0) && (realRect.Height > 0))
                {
                    IntPtr hBitmap = PI.CreateCompatibleBitmap(hdc, realRect.Width, realRect.Height);

                    // If we managed to get a compatible bitmap
                    if (hBitmap != IntPtr.Zero)
                    {
                        try
                        {
                            // Must use the screen device context for the bitmap when drawing into the
                            // bitmap otherwise the Opacity and RightToLeftLayout will not work correctly.
                            PI.SelectObject(_screenDC, hBitmap);

                            // Easier to draw using a graphics instance than a DC!
                            using (Graphics g = Graphics.FromHdc(_screenDC))
                            {
                                // Ask the view element to layout in given space, needs this before a render call
                                using (ViewLayoutContext context = new ViewLayoutContext(this, _kryptonListBox.Renderer))
                                {
                                    context.DisplayRectangle = realRect;
                                    _drawPanel.Layout(context);
                                }

                                using (RenderContext context = new RenderContext(this, _kryptonListBox, g, realRect, _kryptonListBox.Renderer))
                                    _drawPanel.Render(context);

                                // Replace given DC with the screen DC for base window proc drawing
                                IntPtr beforeDC = m.WParam;
                                m.WParam = _screenDC;
                                DefWndProc(ref m);
                                m.WParam = beforeDC;

                                if (Items.Count == 0)
                                    using (RenderContext context = new RenderContext(this, _kryptonListBox, g, realRect, _kryptonListBox.Renderer))
                                        _drawPanel.Render(context);
                            }

                            // Now blit from the bitmap from the screen to the real dc
                            PI.BitBlt(hdc, 0, 0, realRect.Width, realRect.Height, _screenDC, 0, 0, PI.SRCCOPY);

                            // When disabled with no items the above code does not draw the backround!
                            if (Items.Count == 0)
                                using (Graphics g = Graphics.FromHdc(hdc))
                                    using (RenderContext context = new RenderContext(this, _kryptonListBox, g, realRect, _kryptonListBox.Renderer))
                                        _drawPanel.Render(context);
                        }
                        finally
                        {
                            // Delete the temporary bitmap
                            PI.DeleteObject(hBitmap);
                        }
                    }
                }

                // Do we need to match the original BeginPaint?
                if (m.WParam == IntPtr.Zero)
                    PI.EndPaint(Handle, ref ps);
            }