private void OnWMNCCalcSize(ref Message m)
 {
     if (!this.EnableNCModification)
     {
         base.WndProc(ref m);
     }
     else if (m.WParam == new IntPtr(1))
     {
         NativeMethods.NCCALCSIZE_PARAMS nccalcsizeParams = new NativeMethods.NCCALCSIZE_PARAMS();
         NativeMethods.NCCALCSIZE_PARAMS structure        = (NativeMethods.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(NativeMethods.NCCALCSIZE_PARAMS));
         Padding ncMetrics = this.GetNCMetrics();
         structure.rgrc[0].top    += ncMetrics.Top;
         structure.rgrc[0].left   += ncMetrics.Left;
         structure.rgrc[0].right  -= ncMetrics.Right;
         structure.rgrc[0].bottom -= ncMetrics.Bottom;
         Marshal.StructureToPtr((object)structure, m.LParam, true);
         m.Result = IntPtr.Zero;
     }
     else
     {
         base.WndProc(ref m);
         NativeMethods.RECT rect      = new NativeMethods.RECT();
         NativeMethods.RECT structure = (NativeMethods.RECT)Marshal.PtrToStructure(m.LParam, typeof(NativeMethods.RECT));
         Padding            ncMetrics = this.GetNCMetrics();
         structure.top    += ncMetrics.Top;
         structure.left   += ncMetrics.Left;
         structure.right  -= ncMetrics.Right;
         structure.bottom -= ncMetrics.Bottom;
         Marshal.StructureToPtr((object)structure, m.LParam, true);
         m.Result = IntPtr.Zero;
     }
 }
        private void WmNCCalcSize(ref Message m)
        {
            // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowmessages/wm_nccalcsize.asp
            // http://groups.google.pl/groups?selm=OnRNaGfDEHA.1600%40tk2msftngp13.phx.gbl

            if (m.WParam == NativeMethods.FALSE)
            {
                NativeMethods.RECT ncRect   = (NativeMethods.RECT)m.GetLParam(typeof(NativeMethods.RECT));
                Rectangle          proposed = ncRect.Rect;

                Log(MethodInfo.GetCurrentMethod(), string.Format("### Client Rect [0] = ({0},{1}) x ({2},{3})",
                                                                 proposed.Left, proposed.Top, proposed.Width, proposed.Height));

                OnNonClientAreaCalcSize(ref proposed, true);
                ncRect = NativeMethods.RECT.FromRectangle(proposed);

                Marshal.StructureToPtr(ncRect, m.LParam, false);
            }
            else if (m.WParam == NativeMethods.TRUE)
            {
                NativeMethods.NCCALCSIZE_PARAMS ncParams = (NativeMethods.NCCALCSIZE_PARAMS)m.GetLParam(typeof(NativeMethods.NCCALCSIZE_PARAMS));
                Rectangle proposed = ncParams.rectProposed.Rect;

                Log(MethodInfo.GetCurrentMethod(), string.Format("### Client Rect [1] = ({0},{1}) x ({2},{3})",
                                                                 proposed.Left, proposed.Top, proposed.Width, proposed.Height));

                OnNonClientAreaCalcSize(ref proposed, true);
                ncParams.rectProposed = NativeMethods.RECT.FromRectangle(proposed);

                Marshal.StructureToPtr(ncParams, m.LParam, false);
            }
            m.Result = IntPtr.Zero;
        }
        /// <summary>
        /// Calculates the size of the window frame and client area of the RichTextBox
        /// </summary>
        void WmNccalcsize(ref Message m)
        {
            base.WndProc(ref m);

            if (!this.RenderWithVisualStyles())
            {
                return;
            }

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

            NativeMethods.RECT windowRect;

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

            NativeMethods.RECT contentRect;

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

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

            if (NativeMethods.GetThemeBackgroundContentRect(hTheme, hDC, NativeMethods.EP_EDITTEXT, NativeMethods.ETS_NORMAL
                                                            , ref windowRect
                                                            , out contentRect) == NativeMethods.S_OK)
            {
                contentRect.Inflate(-1, -1);

                this.borderRect = new NativeMethods.RECT(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(NativeMethods.WVR_REDRAW);
            }

            NativeMethods.CloseThemeData(hTheme);

            NativeMethods.ReleaseDC(this.Handle, hDC);
        }
Exemple #4
0
        private void OnWMNCCalcSize(ref Message m)
        {
            if (m.WParam == new IntPtr(1))
            {
                NativeMethods.NCCALCSIZE_PARAMS ncCalcSizeParams = new NativeMethods.NCCALCSIZE_PARAMS();
                ncCalcSizeParams = (NativeMethods.NCCALCSIZE_PARAMS)
                                   Marshal.PtrToStructure(m.LParam, typeof(NativeMethods.NCCALCSIZE_PARAMS));

                Padding calculatedClientMargin = this.ClientMargin;

                //This code fixes the issue with the wrong positioning of a MDI child when
                //composition is off and the child is maximized.
                if (this.Form.IsMdiChild && this.IsMaximized &&
                    !DWMAPI.IsCompositionEnabled)
                {
                    ncCalcSizeParams.rgrc[0].top = -SystemInformation.FixedFrameBorderSize.Height;
                }

                ncCalcSizeParams.rgrc[0].top    += calculatedClientMargin.Top;
                ncCalcSizeParams.rgrc[0].left   += calculatedClientMargin.Left;
                ncCalcSizeParams.rgrc[0].right  -= calculatedClientMargin.Right;
                ncCalcSizeParams.rgrc[0].bottom -= calculatedClientMargin.Bottom;

                Marshal.StructureToPtr(ncCalcSizeParams, m.LParam, true);

                m.Result = IntPtr.Zero;
            }
            else
            {
                this.CallBaseWndProc(ref m);

                NativeMethods.RECT ncCalcSizeParams = new NativeMethods.RECT();
                ncCalcSizeParams = (NativeMethods.RECT)
                                   Marshal.PtrToStructure(m.LParam, typeof(NativeMethods.RECT));


                Padding calculatedClientMargin = this.ClientMargin;

                //This code fixes the issue with the wrong positioning of a MDI child when
                //composition is off and the child is maximized.
                if (this.Form.IsMdiChild && this.IsMaximized &&
                    !DWMAPI.IsCompositionEnabled)
                {
                    ncCalcSizeParams.top = -SystemInformation.FixedFrameBorderSize.Height;
                }

                ncCalcSizeParams.top    += calculatedClientMargin.Top;
                ncCalcSizeParams.left   += calculatedClientMargin.Left;
                ncCalcSizeParams.right  -= calculatedClientMargin.Right;
                ncCalcSizeParams.bottom -= calculatedClientMargin.Bottom;

                Marshal.StructureToPtr(ncCalcSizeParams, m.LParam, true);
                m.Result = IntPtr.Zero;
            }
        }
Exemple #5
0
        private void OnWMNCCalcSize(ref System.Windows.Forms.Message m)
        {
            if (!this.EnableNCModification)
            {
                base.WndProc(ref m);
                return;
            }

            if (m.WParam == new IntPtr(1))
            {
                NativeMethods.NCCALCSIZE_PARAMS ncCalcSizeParams = new NativeMethods.NCCALCSIZE_PARAMS();
                ncCalcSizeParams = (NativeMethods.NCCALCSIZE_PARAMS)
                                   Marshal.PtrToStructure(m.LParam, typeof(NativeMethods.NCCALCSIZE_PARAMS));

                Padding calculatedClientMargin = this.GetNCMetrics();

                ncCalcSizeParams.rgrc[0].top    += calculatedClientMargin.Top;
                ncCalcSizeParams.rgrc[0].left   += calculatedClientMargin.Left;
                ncCalcSizeParams.rgrc[0].right  -= calculatedClientMargin.Right;
                ncCalcSizeParams.rgrc[0].bottom -= calculatedClientMargin.Bottom;

                Marshal.StructureToPtr(ncCalcSizeParams, m.LParam, true);

                m.Result = IntPtr.Zero;
            }
            else
            {
                base.WndProc(ref m);

                NativeMethods.RECT ncCalcSizeParams = new NativeMethods.RECT();
                ncCalcSizeParams = (NativeMethods.RECT)
                                   Marshal.PtrToStructure(m.LParam, typeof(NativeMethods.RECT));


                Padding calculatedClientMargin = this.GetNCMetrics();

                ncCalcSizeParams.top    += calculatedClientMargin.Top;
                ncCalcSizeParams.left   += calculatedClientMargin.Left;
                ncCalcSizeParams.right  -= calculatedClientMargin.Right;
                ncCalcSizeParams.bottom -= calculatedClientMargin.Bottom;

                Marshal.StructureToPtr(ncCalcSizeParams, m.LParam, true);
                m.Result = IntPtr.Zero;
            }
        }
Exemple #6
0
        private void OnWMNCCalcSize(ref System.Windows.Forms.Message m)
        {
            if (m.WParam == new IntPtr(1))
            {
                NativeMethods.NCCALCSIZE_PARAMS ncCalcSizeParams = new NativeMethods.NCCALCSIZE_PARAMS();
                ncCalcSizeParams = (NativeMethods.NCCALCSIZE_PARAMS)
                                   Marshal.PtrToStructure(m.LParam, typeof(NativeMethods.NCCALCSIZE_PARAMS));


                int horizontalScrollHeight = this.HorizontalScroll.Visible ? SystemInformation.HorizontalScrollBarHeight : 0;
                int verticalScrollWidth    = this.VerticalScroll.Visible ? SystemInformation.VerticalScrollBarWidth : 0;

                ncCalcSizeParams.rgrc[0].top    += 0;
                ncCalcSizeParams.rgrc[0].left   += this.parentPanel.RootElement.RightToLeft ? -verticalScrollWidth : 0;
                ncCalcSizeParams.rgrc[0].right  += this.parentPanel.RootElement.RightToLeft ? 0 : verticalScrollWidth;
                ncCalcSizeParams.rgrc[0].bottom += horizontalScrollHeight;

                Marshal.StructureToPtr(ncCalcSizeParams, m.LParam, true);

                m.Result = IntPtr.Zero;
            }
            else
            {
                NativeMethods.RECT ncCalcSizeParams = new NativeMethods.RECT();
                ncCalcSizeParams = (NativeMethods.RECT)
                                   Marshal.PtrToStructure(m.LParam, typeof(NativeMethods.RECT));

                int horizontalScrollHeight = this.HorizontalScroll.Visible ? SystemInformation.HorizontalScrollBarHeight : 0;
                int verticalScrollWidth    = this.VerticalScroll.Visible ? SystemInformation.VerticalScrollBarWidth : 0;

                ncCalcSizeParams.top    += 0;
                ncCalcSizeParams.left   += this.parentPanel.RootElement.RightToLeft ? -verticalScrollWidth : 0;
                ncCalcSizeParams.right  += this.parentPanel.RootElement.RightToLeft ? 0 : verticalScrollWidth;
                ncCalcSizeParams.bottom += horizontalScrollHeight;

                Marshal.StructureToPtr(ncCalcSizeParams, m.LParam, true);
                m.Result = IntPtr.Zero;
            }

            base.WndProc(ref m);
        }
Exemple #7
0
 private void WmNCCalcSize(ref Message m)
 {
     if (m.WParam == NativeMethods.FALSE)
     {
         NativeMethods.RECT ncRect   = (NativeMethods.RECT)m.GetLParam(typeof(NativeMethods.RECT));
         Rectangle          proposed = ncRect.Rect;
         RecalcNonClientArea(ref proposed);
         ncRect = NativeMethods.RECT.FromRectangle(proposed);
         Marshal.StructureToPtr(ncRect, m.LParam, false);
     }
     else if (m.WParam == NativeMethods.TRUE)
     {
         NativeMethods.NCCALCSIZE_PARAMS ncParams =
             (NativeMethods.NCCALCSIZE_PARAMS)m.GetLParam(typeof(NativeMethods.NCCALCSIZE_PARAMS));
         Rectangle proposed = ncParams.rectProposed.Rect;
         RecalcNonClientArea(ref proposed);
         ncParams.rectProposed = NativeMethods.RECT.FromRectangle(proposed);
         Marshal.StructureToPtr(ncParams, m.LParam, false);
     }
     m.Result = IntPtr.Zero;
 }
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
            case NativeMethods.WindowsMessage.WM_NCACTIVATE:
                if (m.WParam == IntPtr.Zero)
                {
                    m.Result = NativeMethods.MESSAGE_HANDLED;
                }
                InvalidateWindow();
                break;

            case NativeMethods.WindowsMessage.WM_SETCURSOR:
            case NativeMethods.WindowsMessage.WM_ACTIVATEAPP:
            case NativeMethods.WindowsMessage.WM_SIZE:
            case NativeMethods.WindowsMessage.WM_MOVE:
            {
                base.WndProc(ref m);
                InvalidateWindow();
            }
            break;

            case NativeMethods.WindowsMessage.WM_NCUAHDRAWCAPTION:
            case NativeMethods.WindowsMessage.WM_NCUAHDRAWFRAME:
            {
                InvalidateWindow();
            }
            break;

            case NativeMethods.WindowsMessage.WM_NCPAINT:
                if (NativeMethods.IsWindowVisible(FormHandle))
                {
                    DrawWindow(m.WParam);
                    m.Result = NativeMethods.MESSAGE_HANDLED;
                }
                break;

            case NativeMethods.WindowsMessage.WM_NCCALCSIZE:
                if (m.WParam != IntPtr.Zero)
                {
                    NativeMethods.NCCALCSIZE_PARAMS ncsize = (NativeMethods.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(NativeMethods.NCCALCSIZE_PARAMS));
                    NativeMethods.WINDOWPOS         wp     = (NativeMethods.WINDOWPOS)Marshal.PtrToStructure(ncsize.lppos, typeof(NativeMethods.WINDOWPOS));
                    // store original frame sizes
                    if (!_bStoreSize)
                    {
                        _bStoreSize     = true;
                        _iCaptionHeight = ncsize.rect2.Top - ncsize.rect0.Top;
                        _iFrameHeight   = ncsize.rect0.Bottom - ncsize.rect2.Bottom;
                        _iFrameWidth    = ncsize.rect2.Left - ncsize.rect0.Left;
                    }
                    if (!_bResetSize)
                    {
                        ncsize.rect0 = CalculateFrameSize(wp.x, wp.y, wp.cx, wp.cy);
                        ncsize.rect1 = ncsize.rect0;
                    }
                    Marshal.StructureToPtr(ncsize, m.LParam, false);
                    m.Result = (IntPtr)0x400;                            //WVR_VALIDRECTS;
                }
                else
                {
                    NativeMethods.RECT rc = (NativeMethods.RECT)m.GetLParam(typeof(NativeMethods.RECT));
                    rc = CalculateFrameSize(rc.Left, rc.Top, rc.Right - rc.Left, rc.Bottom - rc.Top);;
                    Marshal.StructureToPtr(rc, m.LParam, true);
                    m.Result = IntPtr.Zero;                            //MESSAGE_PROCESS;
                }

                base.WndProc(ref m);


                break;

            default:
                base.WndProc(ref m);
                break;
            }
        }
Exemple #9
0
		/// <summary>
		/// Calculates the size of the window frame and client area of the RichTextBox
		/// </summary>
		void WmNccalcsize(ref Message m)
		{
			// let the richtextbox control draw the scrollbar if necessary.
			base.WndProc(ref m);

			// we visual styles are not enabled and BorderStyle is not Fixed3D then we have nothing more to do.
			if(!this.RenderWithVisualStyles())
				return;
			
			// contains detailed information about WM_NCCALCSIZE message
			NativeMethods.NCCALCSIZE_PARAMS par = new NativeMethods.NCCALCSIZE_PARAMS();
			
			// contains the window frame RECT
			NativeMethods.RECT windowRect;

			if(m.WParam == IntPtr.Zero) // LParam points to a RECT struct
			{
				windowRect = (NativeMethods.RECT)Marshal.PtrToStructure(m.LParam, typeof(NativeMethods.RECT));
			}
			else // LParam points to a NCCALCSIZE_PARAMS struct
			{
				par =  (NativeMethods.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(NativeMethods.NCCALCSIZE_PARAMS));
				windowRect = par.rgrc0;
			}

			// contains the client area of the control
			NativeMethods.RECT contentRect;

			// get the DC
			IntPtr hDC = NativeMethods.GetWindowDC(this.Handle);

			// open theme data
			IntPtr hTheme = NativeMethods.OpenThemeData(this.Handle, "EDIT");

			// find out how much space the borders needs
			if(NativeMethods.GetThemeBackgroundContentRect(hTheme, hDC, NativeMethods.EP_EDITTEXT, NativeMethods.ETS_NORMAL
				, ref windowRect
				, out contentRect) == NativeMethods.S_OK)
			{
				// shrink the client area the make more space for containing text.
				contentRect.Inflate(-1, -1);

				// remember the space of the borders
				this.borderRect = new NativeMethods.RECT(contentRect.Left-windowRect.Left
					, contentRect.Top-windowRect.Top
					, windowRect.Right-contentRect.Right
					, windowRect.Bottom-contentRect.Bottom); 

				// update LParam of the message with the new client area
				if(m.WParam == IntPtr.Zero)
				{
					Marshal.StructureToPtr(contentRect, m.LParam, false);
				}
				else
				{
					par.rgrc0 = contentRect;
					Marshal.StructureToPtr(par, m.LParam, false);
				}

				// force the control to redraw it´s client area
				m.Result = new IntPtr(NativeMethods.WVR_REDRAW);
			}

			// release theme data handle
			NativeMethods.CloseThemeData(hTheme);

			// release DC
			NativeMethods.ReleaseDC(this.Handle, hDC);
		}
        /// <summary>
        /// Calculates the size of the window frame and client area of the RichTextBox
        /// </summary>
        void WmNccalcsize(ref Message m)
        {
            // let the richtextbox control draw the scrollbar if necessary.
            base.WndProc(ref m);

            // we visual styles are not enabled and BorderStyle is not Fixed3D then we have nothing more to do.
            if (!this.RenderWithVisualStyles())
            {
                return;
            }

            // contains detailed information about WM_NCCALCSIZE message
            NativeMethods.NCCALCSIZE_PARAMS par = new NativeMethods.NCCALCSIZE_PARAMS();

            // contains the window frame RECT
            NativeMethods.RECT windowRect;

            if (m.WParam == IntPtr.Zero) // LParam points to a RECT struct
            {
                windowRect = (NativeMethods.RECT)Marshal.PtrToStructure(m.LParam, typeof(NativeMethods.RECT));
            }
            else // LParam points to a NCCALCSIZE_PARAMS struct
            {
                par        = (NativeMethods.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(m.LParam, typeof(NativeMethods.NCCALCSIZE_PARAMS));
                windowRect = par.rgrc0;
            }

            // contains the client area of the control
            NativeMethods.RECT contentRect;

            // get the DC
            IntPtr hDC = NativeMethods.GetWindowDC(this.Handle);

            // open theme data
            IntPtr hTheme = NativeMethods.OpenThemeData(this.Handle, "EDIT");

            // find out how much space the borders needs
            if (NativeMethods.GetThemeBackgroundContentRect(hTheme, hDC, NativeMethods.EP_EDITTEXT, NativeMethods.ETS_NORMAL
                                                            , ref windowRect
                                                            , out contentRect) == NativeMethods.S_OK)
            {
                // shrink the client area the make more space for containing text.
                contentRect.Inflate(-1, -1);

                // remember the space of the borders
                this.borderRect = new NativeMethods.RECT(contentRect.Left - windowRect.Left
                                                         , contentRect.Top - windowRect.Top
                                                         , windowRect.Right - contentRect.Right
                                                         , windowRect.Bottom - contentRect.Bottom);

                // update LParam of the message with the new client area
                if (m.WParam == IntPtr.Zero)
                {
                    Marshal.StructureToPtr(contentRect, m.LParam, false);
                }
                else
                {
                    par.rgrc0 = contentRect;
                    Marshal.StructureToPtr(par, m.LParam, false);
                }

                // force the control to redraw it磗 client area
                m.Result = new IntPtr(NativeMethods.WVR_REDRAW);
            }

            // release theme data handle
            NativeMethods.CloseThemeData(hTheme);

            // release DC
            NativeMethods.ReleaseDC(this.Handle, hDC);
        }