Dleone

Dleone

  • NA
  • 3
  • 0

Non-Client Drawing (WM_NCPAINT) Problem

Dec 9 2004 8:42 AM
I am inheriting from a textbox and creating some extra non-client space (using WM_NCCALCSIZE) on the right side. During WM_NCPAINT, I am drawing a button in the extra non-client space. Everything works fine, until I change the form's opacity to anything other than 100%. This is causing the extra non-client space to be come invalid or undrawable. If I run the form with opacity being 100%, the control I am designing looks fine, however if I change the opacity to less than 100%, my button area becomes black. Even if (while the form is still running), I change the opacity back to 100%, my button area always remains black. What is happening to the non-client space that I allocated after the form's opacity is changed? Is there something that I am missing or leaving out? Any help would greatly be appreciated. Thanks. Here is the code for WM_NCPAINT & WM_NCCALCSIZE: '------------------------------------------------ 'WM_NCPAINT Processing 'Let the base class do it's thing. MyBase.WndProc(m) 'Grab a pointer to the control window's device context. Dim hdc As IntPtr = NativeMethods.GetWindowDC(m.HWnd) 'Dim hdc As IntPtr = NativeMethods.GetDCEx(m.HWnd, m.WParam, 1 Or &H20 Or &H10000) 'Create a graphics object from the window's device context. Dim g As Graphics = Graphics.FromHdc(hdc) 'Create the display and bounds rectangles for the button. Me.btnNC.DisplayRectangle = New Rectangle(Me.Bounds.Width - (Me.BUTTON_WIDTH + 2), Me.BUTTON_START_Y, Me.BUTTON_WIDTH, Me.Bounds.Height - (Me.BUTTON_START_Y * 2)) Me.btnNC.Bounds = New Rectangle(Me.Bounds.X + (Me.Bounds.Width - (Me.BUTTON_WIDTH + 2)), Me.Bounds.Y + Me.BUTTON_START_Y, Me.BUTTON_WIDTH, Me.Bounds.Height - (Me.BUTTON_START_Y * 2)) 'Draw a normal button. ControlPaint.DrawButton(g, Me.btnNC.DisplayRectangle, ButtonState.Normal) 'Dispose the graphics object. g.Dispose() 'Release the window's device context. NativeMethods.ReleaseDC(m.HWnd, hdc) Return '------------------------------------------------ 'WM_NCCALCSIZE Processing 'Let the base class do it's thing. MyBase.WndProc(m) 'Make some space in the non-client area to draw the button. If m.WParam.ToInt32 = 1 Then Dim p As NCCALCSIZE_PARAMS = Marshal.PtrToStructure(m.LParam, GetType(NCCALCSIZE_PARAMS)) p.rgrc0.right -= (Me.BUTTON_WIDTH - 1) Marshal.StructureToPtr(p, m.LParam, True) Else Dim rect As RECT = Marshal.PtrToStructure(m.LParam, GetType(RECT)) rect.Right -= (Me.BUTTON_WIDTH - 1) Marshal.StructureToPtr(rect, m.LParam, True) End If Return

Answers (2)