CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 2002
    Location
    Mumbai,India
    Posts
    567

    Edit Box?????or Static text control

    How can i make the background color of static text box to white................
    or
    why when i set my edit text box property to read only.its background color changes to windows color.....and not remains white
    please help me...........
    thanks
    Vishal

  2. #2
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815

    Re: Edit Box?????or Static text control

    Originally posted by VishalNikiSharma
    why when i set my edit text box property to read only.its background color changes to windows color.....and not remains white
    To indicate that the control is read-only. That's by design, and users expect it to be like that.

  3. #3
    Join Date
    Sep 2002
    Posts
    924
    Search the forum for the how-to. Doing this with Static Controls, and with Edit Controls, has been asked previously. You should be able to find the answer you are looking for including examples.

    Search for CStatic color or CEdit color, and you should get lots of relevant hits.

  4. #4
    Join Date
    Jan 2004
    Location
    Altos
    Posts
    168

    Talking

    If u r using MFC derive a class from CEdit and override the WM_CHAR message handler. so that whenever there is some keypress the msg is not forwarded. To the control. So ur control will be readonly AWA with whitebackground. or u can try to create user drawn controls.
    "I came"
    "I saw"
    "I conquered"

  5. #5
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Originally posted by Cyber Bandit
    If u r using MFC derive a class from CEdit and override the WM_CHAR message handler. so that whenever there is some keypress the msg is not forwarded. To the control. So ur control will be readonly AWA with whitebackground. or u can try to create user drawn controls.
    Sorry but that is not necessary and definitely not the right way to do it.

  6. #6
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: Edit Box?????or Static text control

    Originally posted by VishalNikiSharma
    How can i make the background color of static text box to white................
    or
    why when i set my edit text box property to read only.its background color changes to windows color.....and not remains white
    Well...although I agree with gstercken not to change the default windows behaviour, you can change it by writing your own edit control derived from 'CEdit'.

    React on the 'WM_CTLCOLOR_REFLECT' message. Inside the handler 'CtlColor()' you can check whether the field is read-only...
    Code:
    if((GetStyle() & ES_READONLY) == ES_READONLY)
    {
      // Edit field is read only
    }

  7. #7
    Join Date
    Jan 2004
    Location
    Altos
    Posts
    168
    Originally posted by Andreas Masur
    Sorry but that is not necessary and definitely not the right way to do it.
    Hey andreas can u explain why the path which suggested that is overriding the WM_CHAR not the right way.
    "I came"
    "I saw"
    "I conquered"

  8. #8
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652
    Originally posted by Cyber Bandit
    Hey andreas can u explain why the path which suggested that is overriding the WM_CHAR not the right way.
    Simply, because you are trying to solve problem A by using a workaround which is usually be used for a problem B.

    In other words you eliminate a standard procedure for solving a problem which is not related to this procedure at all.

  9. #9
    Join Date
    Apr 2002
    Location
    Mumbai,India
    Posts
    567
    Hi
    I am not using mfc.i am using atl .............
    vishal

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