CEditView Background Color & Font Color :: MFC

This is a discussion on CEditView Background Color & Font Color :: MFC within the Windows Programming forums, part of the Platform Specific Boards category; Hi. Is it possible to change the background color and font color of a CEditView window? Please explain. Thanks, Kuphryn...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348

    CEditView Background Color & Font Color :: MFC

    Hi.

    Is it possible to change the background color and font color of a CEditView window? Please explain.

    Thanks,
    Kuphryn

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    70
    You can do it by subclassing your edit box.

    It is basically providing the new window procedure for the
    edit box, processing some messages inside it and calling the original window procedure for the messages you do not process. In MFC, it must be something alike, because MFC does not the things which can't be done by standard API techniques. It just conceals the core things and makes it harder to understand the backgrounds.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Okay. Thanks.

    Kuphryn

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Look at the 'OnCtlColor' function for your CEditView which should provide the capability you are after. You must return a brush handle (HBRUSH) from the function which is used to colour the background; you can also set other properties such as text colour with the CDC* provided to the function. You should use DeleteObject on any HBRUSH you create for this.

    The win32 API analogue is a whole bunch of colour msgs, each specific to the control type: WM_CTLCOLORBTN (which doesn't do much),WM_CTLCOLOREDIT,WM_CTLCOLORLISTBOX,WM_CTLCOL ORSCROLLBAR,WM_CTLCOLORSTATIC. The process is the same: create an HBRUSH, return it in response to the msg and DeleteObject on it when done.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Thanks.

    Kuphryn

  6. #6
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Thanks.

    I added a handler for =WM_CTLCOLOR. Is here the solution.

    -----
    HBRUSH CMyEditView::CtlColor(CDC* pDC, UINT /*nCtlColor*/)
    {

    // m_BkColor is whatever background color you want to change to. You will make changes to m_BkColor by the time Windows
    // repaints

    pDC->SetBkColor(m_BkColor);

    // m_FontColor is the text color

    pDC->SetTextColor(m_FontColor);

    // Return a handle to a CBrush. m_BkBrush is a local variable initialized to RGB(255, 255, 255)

    return static_cast<HBRUSH>(m_BkBrush.GetSafeHandle());
    }
    -----

    Special thanks to Joseph M. Newcomer of MSDN Newsgroup for pointing out "reflected" messages.

    Kuphryn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. DirectX | Drawing text
    By gavra in forum Game Programming
    Replies: 4
    Last Post: 06-08-2009, 01:23 AM
  2. font size and background
    By Saimadhav in forum C++ Programming
    Replies: 4
    Last Post: 07-31-2008, 07:16 AM
  3. problem with my font manager
    By hannibar in forum C Programming
    Replies: 1
    Last Post: 03-07-2006, 08:03 AM
  4. destroywindow() problem
    By algi in forum Windows Programming
    Replies: 6
    Last Post: 03-27-2005, 11:40 PM
  5. char copy
    By variable in forum C Programming
    Replies: 8
    Last Post: 02-06-2005, 10:18 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21