Esempio n. 1
0
        /// <summary>
        /// Processes Windows messages
        /// </summary>
        /// <param name="m">The Windows Message to process</param>
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);

            if (!this.visualStylesEnabled || this.BorderStyle != BorderStyle.Fixed3D)
            {
                return;
            }

            if (m.Msg == (int)WindowMessageFlags.WM_PRINT)
            {
                if ((m.LParam.ToInt32() & (int)WmPrintFlags.PRF_NONCLIENT) == (int)WmPrintFlags.PRF_NONCLIENT)
                {
                    // open theme data
                    IntPtr hTheme = UxTheme.OpenThemeData(this.Handle, UxTheme.WindowClasses.TreeView);

                    if (hTheme != IntPtr.Zero)
                    {
                        // get the part and state needed
                        int partId  = (int)UxTheme.Parts.TreeView.TreeItem;
                        int stateId = (int)UxTheme.PartStates.TreeItem.Normal;

                        RECT rect = new RECT();
                        rect.right  = this.Width;
                        rect.bottom = this.Height;

                        RECT clipRect = new RECT();

                        // draw the left border
                        clipRect.left   = rect.left;
                        clipRect.top    = rect.top;
                        clipRect.right  = rect.left + 2;
                        clipRect.bottom = rect.bottom;
                        UxTheme.DrawThemeBackground(hTheme, m.WParam, partId, stateId, ref rect, ref clipRect);

                        // draw the top border
                        clipRect.left   = rect.left;
                        clipRect.top    = rect.top;
                        clipRect.right  = rect.right;
                        clipRect.bottom = rect.top + 2;
                        UxTheme.DrawThemeBackground(hTheme, m.WParam, partId, stateId, ref rect, ref clipRect);

                        // draw the right border
                        clipRect.left   = rect.right - 2;
                        clipRect.top    = rect.top;
                        clipRect.right  = rect.right;
                        clipRect.bottom = rect.bottom;
                        UxTheme.DrawThemeBackground(hTheme, m.WParam, partId, stateId, ref rect, ref clipRect);

                        // draw the bottom border
                        clipRect.left   = rect.left;
                        clipRect.top    = rect.bottom - 2;
                        clipRect.right  = rect.right;
                        clipRect.bottom = rect.bottom;
                        UxTheme.DrawThemeBackground(hTheme, m.WParam, partId, stateId, ref rect, ref clipRect);
                    }

                    UxTheme.CloseThemeData(hTheme);
                }
            }
        }
Esempio n. 2
0
        private void OnBtnPaint(object sender, System.Windows.Forms.PaintEventArgs e)
        {
            IntPtr hTheme = UxTheme.OpenThemeData(this.Handle, "COMBOBOX");

            // Makes sure Windows XP is running and
            //  a .manifest file exists for the EXE.
            if (Environment.OSVersion.Version.Major >= 5
                & Environment.OSVersion.Version.Minor > 0
                & System.IO.File.Exists(Application.ExecutablePath + ".manifest")
                & (hTheme != IntPtr.Zero))
            {
                //Grab DC
                IntPtr hDC = e.Graphics.GetHdc();

                int state = UxTheme.CBXS_NORMAL;
                switch (this.m_state)
                {
                case State.Hot:
                    state = UxTheme.CBXS_HOT;
                    break;

                case State.Pressed:
                    state = UxTheme.CBXS_PRESSED;
                    break;

                case State.Disabled:
                    state = UxTheme.CBXS_DISABLED;
                    break;

                default:
                    break;
                }

                try
                {
                    RECT r = new RECT(e.ClipRectangle.Left, e.ClipRectangle.Right, e.ClipRectangle.Top, e.ClipRectangle.Bottom);

                    //Render button
                    UxTheme.DrawThemeBackground(hTheme, hDC, UxTheme.CP_DROPDOWN, state, r, null);
                }
                finally
                {
                    //Release DC
                    e.Graphics.ReleaseHdc(hDC);
                    UxTheme.CloseThemeData(hTheme);
                }
            }
            else
            {
                ButtonState state = ButtonState.Normal;
                switch (this.m_state)
                {
                case State.Pressed:
                    state = ButtonState.Pushed;
                    break;

                case State.Disabled:
                    state = ButtonState.Inactive;
                    break;

                default:
                    break;
                }

                ControlPaint.DrawComboButton(e.Graphics, e.ClipRectangle, state);
            }
        }