Пример #1
0
        private void RenderStyle(ref Message m)
        {
            base.WndProc(ref m);

            if (!Natives.CanRender())
            {
                return;
            }

            int partId = Natives.EP_EDITTEXT;

            int stateId;

            if (this.Enabled)
            {
                stateId = this.ReadOnly ? Natives.ETS_READONLY : Natives.ETS_NORMAL;
            }
            else
            {
                stateId = Natives.ETS_DISABLED;
            }

            RECT windowRect;

            Natives.GetWindowRect(this.Handle, out windowRect);
            windowRect.Right  -= windowRect.Left;
            windowRect.Bottom -= windowRect.Top;
            windowRect.Top     = 0;
            windowRect.Left    = 0;

            IntPtr hDC = Natives.GetWindowDC(this.Handle);

            RECT clientRect = windowRect;

            clientRect.Left   += this._border.Left;
            clientRect.Top    += this._border.Top;
            clientRect.Right  -= this._border.Right;
            clientRect.Bottom -= this._border.Bottom;

            Natives.ExcludeClipRect(hDC, clientRect.Left, clientRect.Top, clientRect.Right, clientRect.Bottom);

            IntPtr hTheme = Natives.OpenThemeData(this.Handle, "EDIT");

            if (Natives.IsThemeBackgroundPartiallyTransparent(hTheme, Natives.EP_EDITTEXT, Natives.ETS_NORMAL) != 0)
            {
                Natives.DrawThemeParentBackground(this.Handle, hDC, ref windowRect);
            }


            Natives.DrawThemeBackground(hTheme, hDC, partId, stateId, ref windowRect, IntPtr.Zero);
            Natives.CloseThemeData(hTheme);
            Natives.ReleaseDC(this.Handle, hDC);
            m.Result = IntPtr.Zero;
        }
Пример #2
0
        private void CalculateSize(ref Message m)
        {
            base.WndProc(ref m);

            if (!Natives.CanRender())
            {
                return;
            }

            Natives.NCCALCSIZE_PARAMS par = new Natives.NCCALCSIZE_PARAMS();

            RECT windowRect;

            if (m.WParam == IntPtr.Zero)
            {
                windowRect = (RECT)Marshal.PtrToStructure(m.LParam, typeof(RECT));
            }
            else
            {
                par        = (Natives.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(Natives.NCCALCSIZE_PARAMS));
                windowRect = par.rgrc0;
            }

            RECT   contentRect;
            IntPtr hDC    = Natives.GetWindowDC(this.Handle);
            IntPtr hTheme = Natives.OpenThemeData(this.Handle, "EDIT");

            if (Natives.GetThemeBackgroundContentRect(hTheme, hDC, Natives.EP_EDITTEXT, Natives.ETS_NORMAL, ref windowRect, out contentRect) == Natives.S_OK)
            {
                contentRect.Inflate(-1, -1);
                this._border = new Margins(contentRect.Left - windowRect.Left,
                                           contentRect.Top - windowRect.Top,
                                           windowRect.Right - contentRect.Right,
                                           windowRect.Bottom - contentRect.Bottom);


                if (m.WParam == IntPtr.Zero)
                {
                    Marshal.StructureToPtr(contentRect, m.LParam, false);
                }
                else
                {
                    par.rgrc0 = contentRect;
                    Marshal.StructureToPtr(par, m.LParam, false);
                }

                m.Result = new IntPtr(Natives.WVR_REDRAW);
            }

            Natives.CloseThemeData(hTheme);
            Natives.ReleaseDC(this.Handle, hDC);
        }