CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: coloring window

  1. #1
    Join Date
    Apr 1999
    Location
    romania
    Posts
    43

    coloring window

    I have a dialog based application in VC++5.0
    I use mfc.
    I have to change the entire window color at a button click e.g.
    I use OnCtlColor but the frames (thick borders)remains unchanged, in the same gray color.

    Please help me.


  2. #2
    Join Date
    Sep 1999
    Location
    Europe / Austria / Innsbruck
    Posts
    442

    Re: coloring window

    You must paint the borders of a window in the function OnNcPaint(), because the borders don't belong to the windows client area and OnCtlColor only works for the client area.


  3. #3
    Join Date
    Apr 1999
    Location
    romania
    Posts
    43

    Re: coloring window

    I've implemented OnNcPaint() but the frames are becaming transparent.
    How should look the implementation?
    I've tried
    CPaintDC dc(this); // device context for painting
    CBrush ncbrush;
    ncbrush.CreateSolidBrush(RGB(255,255,0));
    dc.FillRect(NULL, &ncbrush);


    but it doesn't vork.
    thank you.


  4. #4
    Join Date
    Sep 1999
    Location
    Europe / Austria / Innsbruck
    Posts
    442

    Re: coloring window

    You must use CWindowDC instead of CPaintDC. CPaintDC may only be used in OnPaint. And you must give the rectangle to paint in for the FillRect function.

    CWindowDC dc(this);
    CBrush brush;
    CRect rc;
    brush.CreateSolidBrush(RGB(255, 255, 0));
    GetWindowRect(&rc); // paint whole non-client area in desired color
    rc.OffsetRect(-rc.left, -rc.top);
    dc.FillRect(&rc, &brush);
    // you must also draw the caption bar yourself...






Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured