Re: How to change the color of the title bar in c#? by Jonny
Jonny
Mon Aug 04 07:16:22 CDT 2003
Sorry I made a mistake, you should intercept the WM_NCPAINT
not WM_PAINT.
regards,
Jonny
"Jonny" <jonnyyu@pub.xaonline.com> wrote in message
news:OUJXN%23nWDHA.1900@TK2MSFTNGP10.phx.gbl...
> hello, Jack,
> You may try set system color to your own when the window is
> activated,and
> restore the original color when you app's window is deactivated. the
example
> code is like this:
>
> [DllImport("user32.dll")]
> private static extern Int32 GetSysColor(Int32 Index);
> [DllImport("user32.dll")]
> private static extern bool SetSysColors(int cElements,Int32[]
> lpaElements,Int32[] lpaRgbValues);
> private const int COLOR_ACTIVECAPTION = 2;
> private int old_color ;
> private static int[] element = new int[]{COLOR_ACTIVECAPTION};
> private static int[] rgb = null;
> private static int[] rgb_old = null;
>
> private void Form1_Activated(object sender, System.EventArgs e)
> {
> if(rgb == null)
> {
> old_color = GetSysColor(COLOR_ACTIVECAPTION);
> rgb = new int[]{Color.White.ToArgb() & 0x00ffffff};
> }
> bool b = SetSysColors(1,element,rgb);
> }
>
> private void Form1_Deactivate(object sender, System.EventArgs e)
> {
> if (rgb_old == null)
> rgb_old = new int[] {old_color};
> bool b = SetSysColors(1,element,rgb_old);
> }
>
> But as you can see, it's not efficient because the system will broadcast
> WM_SYSCOLORCHANGE message and send WM_PAINT to all affected windows, maybe
> it's performance is acceptable when there are only a few top-level
windows.
> You should intercept the WM_PAINT msg and draw the title bar by yourself
if
> you want better performance.
>
> Note WM_NCPAINT only draw the frame of the window, if you want to draw the
> title bar you should intercept the WM_PAINT.
>
> Best regards,
>
> Jonny Yu
>
> "Jack Charbonneau" <john@3dweb.com> wrote in message
> news:01c701c35a09$fe3e09f0$a401280a@phx.gbl...
> > I need to cange the color of the title bar depending on
> > the state of my application. It seems the only way to do
> > this is to intercept the WM_NCPAINT message and take
> > responsiblility for drawing the entire bar - close box,
> > maximize box, etc.
> >
> > Isn't there some way I can just tell the OS to change the
> > color without all this extra work?
> >
> >
>
>