J
jwallison
(Framework 1.1)
I have an IE BandObject that is derived from : UserControl,
IObjectWithSite, IDeskBand, IDockingWindow, IOleWindow, IInputObject
This control uses DrawThemeParentBackground( this.Handle, hdc, ref rect)
to get the parent IE rebar control's gradient background to be drawn under
XP.
Everything was drawing "fine", up until the point that I added a ToolBar (or
a PictureBox, or...) to my bandObject that was docked Left . The Layout is
fine - Z-Order correct, etc. -this is only a painting problem related to
OnPaintBackground in this class, from all that I can see
Now, everything has gone to hell - the background isn't being painted
correctly on EITHER a standard toolbar (docked Left) OR a ToolBar-derived
class docked Fill. It's CRAZY - even the DIRECTION that MouseOver occurs in
(right-to-left, the background paints fine, left-to-right, the background
paints each button black in what appears to be the size of the first item in
the BandObject - the ToolBar or PictureBox that is docked Left.
This seems like it should be fairly straightforward, but there seems to be
some kind of interaction between UxTheme and (docking?) I am mucking with
the DisplayRectangle of the BandObject (shrinking the width to allow for a
small button on the rigt side of the control (a LOT smaller than the area
that isn't painting the background correctly). Any pointers would be greatly
appreciated -
My OnPaintbackground() is implemented as follows:
protected override void OnPaintBackground(PaintEventArgs pevent) /*
XP Visual Style, only */
{
rect = new RECT(pevent.ClipRectangle);
try
{
IntPtr hdc = pevent.Graphics.GetHdc();
int ret = DigitalCollimation.Win32.DrawThemeParentBackground(
this.Handle, hdc, ref rect );
pevent.Graphics.ReleaseHdc( hdc);
}
catch (Exception ex)
{
Trace.WriteLine( ex.Message + "\r\nat: " + ex.StackTrace
,"OnPaintBackground()");
}
}
DrawThemeParentBackground() is defined as follows:
[DllImport( "uxtheme.dll")]
public static extern /* HRESULT */ int DrawThemeParentBackground(
IntPtr hwnd, IntPtr hdc, ref RECT prc );
RECT is defined as follows:
[StructLayout( LayoutKind.Sequential)]
public struct RECT
{
public Int32 Left;
public Int32 Top;
public Int32 Right;
public Int32 Bottom;
public int Width
{
get
{
return Right - Left;
}
}
public int Height
{
get
{
return Bottom - Top;
}
}
public RECT( int left, int top, int right, int bottom)
{
this.Left = left;
this.Top = top;
this.Right = right;
this.Bottom = bottom;
}
public RECT( Rectangle rc)
{
Left = rc.Left;
Top = rc.Top;
Right = rc.Left + rc.Width;
Bottom = rc.Top + rc.Height;
}
public static implicit operator RECT( Rectangle rc )
{
return new RECT( rc.Left, rc.Top, rc.Left + rc.Width, rc.Top +
rc.Height );
}
public static implicit operator Rectangle( RECT rc )
{
return new Rectangle( rc.Left, rc.Top, rc.Left + rc.Width, rc.Top +
rc.Height );
}
public override string ToString()
{
// TODO: change this to use String.Format?
return "{ " + Left + ", " + Top + ", " + Right + ", " + Bottom + " }";
}
}
I have an IE BandObject that is derived from : UserControl,
IObjectWithSite, IDeskBand, IDockingWindow, IOleWindow, IInputObject
This control uses DrawThemeParentBackground( this.Handle, hdc, ref rect)
to get the parent IE rebar control's gradient background to be drawn under
XP.
Everything was drawing "fine", up until the point that I added a ToolBar (or
a PictureBox, or...) to my bandObject that was docked Left . The Layout is
fine - Z-Order correct, etc. -this is only a painting problem related to
OnPaintBackground in this class, from all that I can see

Now, everything has gone to hell - the background isn't being painted
correctly on EITHER a standard toolbar (docked Left) OR a ToolBar-derived
class docked Fill. It's CRAZY - even the DIRECTION that MouseOver occurs in
(right-to-left, the background paints fine, left-to-right, the background
paints each button black in what appears to be the size of the first item in
the BandObject - the ToolBar or PictureBox that is docked Left.
This seems like it should be fairly straightforward, but there seems to be
some kind of interaction between UxTheme and (docking?) I am mucking with
the DisplayRectangle of the BandObject (shrinking the width to allow for a
small button on the rigt side of the control (a LOT smaller than the area
that isn't painting the background correctly). Any pointers would be greatly
appreciated -
My OnPaintbackground() is implemented as follows:
protected override void OnPaintBackground(PaintEventArgs pevent) /*
XP Visual Style, only */
{
rect = new RECT(pevent.ClipRectangle);
try
{
IntPtr hdc = pevent.Graphics.GetHdc();
int ret = DigitalCollimation.Win32.DrawThemeParentBackground(
this.Handle, hdc, ref rect );
pevent.Graphics.ReleaseHdc( hdc);
}
catch (Exception ex)
{
Trace.WriteLine( ex.Message + "\r\nat: " + ex.StackTrace
,"OnPaintBackground()");
}
}
DrawThemeParentBackground() is defined as follows:
[DllImport( "uxtheme.dll")]
public static extern /* HRESULT */ int DrawThemeParentBackground(
IntPtr hwnd, IntPtr hdc, ref RECT prc );
RECT is defined as follows:
[StructLayout( LayoutKind.Sequential)]
public struct RECT
{
public Int32 Left;
public Int32 Top;
public Int32 Right;
public Int32 Bottom;
public int Width
{
get
{
return Right - Left;
}
}
public int Height
{
get
{
return Bottom - Top;
}
}
public RECT( int left, int top, int right, int bottom)
{
this.Left = left;
this.Top = top;
this.Right = right;
this.Bottom = bottom;
}
public RECT( Rectangle rc)
{
Left = rc.Left;
Top = rc.Top;
Right = rc.Left + rc.Width;
Bottom = rc.Top + rc.Height;
}
public static implicit operator RECT( Rectangle rc )
{
return new RECT( rc.Left, rc.Top, rc.Left + rc.Width, rc.Top +
rc.Height );
}
public static implicit operator Rectangle( RECT rc )
{
return new Rectangle( rc.Left, rc.Top, rc.Left + rc.Width, rc.Top +
rc.Height );
}
public override string ToString()
{
// TODO: change this to use String.Format?
return "{ " + Left + ", " + Top + ", " + Right + ", " + Bottom + " }";
}
}