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

Thread: Static Control

  1. #1
    Join Date
    Apr 1999
    Posts
    1

    Static Control

    There is plenty of information on placing and using controls on dialog boxes. I need to use them on the documnet. I have placed two scroll bars, a button and a static controls on the documnet window. My problem is this: When I try to color the text in the static control by overiding the WM_CTLCOLOR message it does not work. The code is as follows:
    HBRUSH MCtrl_DSCUStatic::CtlColor(CDC* pDC, UINT nCtlColor)
    {
    // TODO: Change any attributes of the DC here
    // THis is the reflected one
    CBrush hbr;

    hbr.CreateSolidBrush( RGB(100,100,100));

    pDC->SetTextColor(RGB(255,0,0));

    pDC->SetBkColor(RGB(255,0,0));
    pDC->MoveTo(0,0);
    pDC->LineTo(200,200);

    // TODO: Return a non-NULL brush if the parent's handler should not be called
    // return NULL;
    return hbr;
    }

    This function does get called and the line gets drawn then the text prints over the line but the color is still black. So far the only soultion I have is to overide the onpaint function. This basically defeats the purpose of using a static control. Any suggestions? I would also like any information on using controls on a doc window. There is absolutly no info on this! Thanks!

    Gil Fisher

  2. #2
    Join Date
    May 1999
    Location
    Toulouse, France
    Posts
    171

    Re: Static Control

    The problem is that your brush is destroyed when you exit the method (local variable). Use a member variable instead.

    HTH.

    K.

    Ash to ash and clay to clay, if the enemy doesn't get you, your own folk may.
    We're talking ****, 'cause life is a 'biz
    You know it is
    Everybody tryin' to get rich
    God ****!
    All I wanna do is live !

    KoRn, Children of the Korn

  3. #3
    Join Date
    May 1999
    Posts
    12

    Re: Static Control

    Your HBRUSH is a local variable, so it gets destroyed once your code jumps out of the function.
    Use a member variable say HBRUSH m_MyBrush;
    Create a brush whenever neccessary by calling CreateSolidBrush, and if you are creating a new brush THEN PLEASE MAKE SURE THAT YOU DESTROY THE OLD BRUSH by calling DeleteObject.

    If your color requirements are not changing then you may create a brush once only(in the very beginning ) and use it repeatedly, provided you have not done a DeleteObject on the brush anywhere.

    Regards
    Saurabh



  4. #4
    Join Date
    Jun 1999
    Posts
    1

    Re: Static Control

    I was able to change the text color of the CStatic controls on my view by overriding OnCtlColor() function, in which I call pDC->SetTextColor() when it's the right control. My problem is I was not able to use the same technique to change the text color of my CButtons controls ...


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