Exemplo n.º 1
0
            protected override void WndProc(ref Message m)
            {
                switch (m.Msg)
                {
                case 0x000F:                        //WM_PAINT

                    Win32.RECT update = new Win32.RECT();
                    if (Win32.GetUpdateRect(m.HWnd, ref update, false) == 0)
                    {
                        break;
                    }
                    //Fill the paintstruct
                    Win32.PAINTSTRUCT ps  = new Win32.PAINTSTRUCT();
                    IntPtr            hdc = Win32.BeginPaint(m.HWnd, ref ps);
                    //Create graphics object from the hdc
                    Graphics g = Graphics.FromHdc(hdc);
                    //Get the non-item rectangle
                    int        left     = 0;
                    Win32.RECT itemRect = new Win32.RECT();
                    for (int i = 0; i < parent.Columns.Count; i++)
                    {
                        //HDM_GETITEMRECT
                        Win32.SendMessage(m.HWnd, 0x1200 + 7, i, ref itemRect);
                        left += itemRect.right - itemRect.left;
                    }
                    //parent.headerHeight = itemRect.bottom-itemRect.top;
                    if (left >= ps.rcPaint.left)
                    {
                        left = ps.rcPaint.left;
                    }

                    Rectangle r = new Rectangle(left, ps.rcPaint.top,
                                                ps.rcPaint.right - left, ps.rcPaint.bottom - ps.rcPaint.top);
                    //		Rectangle r1 = new Rectangle(ps.rcPaint.left, ps.rcPaint.top,
                    //		ps.rcPaint.right-left, ps.rcPaint.bottom-ps.rcPaint.top);

                    g.FillRectangle(new SolidBrush(parent.BackColor), r);

                    /*//If we have a valid event handler - call it
                     * if(parent.DrawHeader != null)
                     *      parent.DrawHeader(new DrawHeaderEventArgs(g,r,
                     *              itemRect.bottom-itemRect.top));*/

                    //Now we have to check if we have owner-draw columns and fill
                    //the DRAWITEMSTRUCT appropriately
                    int counter = 0;
                    foreach (ColumnHeader mm in parent.Columns)
                    {
                        Win32.DRAWITEMSTRUCT dis = new Win32.DRAWITEMSTRUCT();
                        dis.ctrlType   = 100;                              //ODT_HEADER
                        dis.hwnd       = m.HWnd;
                        dis.hdc        = hdc;
                        dis.itemAction = 0x0001;                                //ODA_DRAWENTIRE
                        dis.itemID     = counter;
                        //Must find if some item is pressed
                        Win32.HDHITTESTINFO hi = new Win32.HDHITTESTINFO();
                        hi.pt.X = parent.PointToClient(MousePosition).X;
                        hi.pt.Y = parent.PointToClient(MousePosition).Y;
                        int hotItem = Win32.SendMessage(m.HWnd, 0x1200 + 6, 0, ref hi);
                        //If clicked on a divider - we don't have hot item
                        if (hi.flags == 0x0004 || hotItem != counter)
                        {
                            hotItem = -1;
                        }
                        if (hotItem != -1 && mouseDown)
                        {
                            dis.itemState = 0x0001;                                    //ODS_SELECTED
                        }
                        else
                        {
                            dis.itemState = 0x0020;
                        }
                        //HDM_GETITEMRECT
                        Win32.SendMessage(m.HWnd, 0x1200 + 7, counter, ref itemRect);
                        dis.rcItem = itemRect;
                        //Send message WM_DRAWITEM
                        Win32.SendMessage(parent.Handle, 0x002B, 0, ref dis);
                        counter++;
                    }
                    Win32.EndPaint(m.HWnd, ref ps);

                    break;

                case 0x0014:                        //WM_ERASEBKGND
                    //We don't need to do anything here in order to reduce flicker
                    //	if(parent.FullyCustomHeader)
                    break;

                case 0x0201:                        //WM_LBUTTONDOWN
                    mouseDown = true;
                    base.WndProc(ref m);
                    break;

                case 0x0202:                        //WM_LBUTTONUP
                    mouseDown = false;
                    base.WndProc(ref m);
                    break;

                case 0x1200 + 5:                      //HDM_LAYOUT
                    base.WndProc(ref m);
                    break;

                /*	case 0x0030://WM_SETFONT
                 *              if(parent.IncreaseHeaderHeight > 0)
                 *              {
                 *                      System.Drawing.Font f = new System.Drawing.Font(parent.Font.Name,
                 *                              parent.Font.SizeInPoints + parent.IncreaseHeaderHeight);
                 *                      m.WParam = f.ToHfont();
                 *              }
                 *              base.WndProc(ref m);
                 *              break;       */
                default:
                    base.WndProc(ref m);
                    break;
                }
            }
Exemplo n.º 2
0
        protected override void WndProc(ref Message message)
        {
            const int WM_PAINT       = 0x000F;
            const int WM_PRINTCLIENT = 0x0318;
            const int WM_ERASEBKGND  = 0x0014;
            const int WM_KEYDOWN     = 0x100;

            switch (message.Msg)
            {
            case WM_KEYDOWN:
                if ((int)message.WParam == 32) // Space
                {
                    // See if our current node allows checkboxes.
                    BetterTreeNode node = SelectedNode as BetterTreeNode;
                    if (node != null)
                    {
                        if (!node.ShowCheckbox)
                        {
                            return;
                        }
                    }
                }
                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);
                }
                Win32.EndPaint(message.HWnd, ref paintStruct);
                return;
            }
            base.WndProc(ref message);
        }