Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

CEdit Read-Only question

Posted on 2001-06-19
5
Medium Priority
?
581 Views
Last Modified: 2013-11-20
Hi,
I have a CEdit which I set to Read-Only mode.
But I want the color of the edit to remain white (and not gray).
How can I do it ?

Thanks,
Iris.
0
Comment
Question by:irisz
5 Comments
 

Expert Comment

by:Andrian
ID: 6209480
Use CStatic instead of CEdit(sunken) and you can color it after!
0
 

Author Comment

by:irisz
ID: 6209517
No, I need CEdit...
Can it be done in CEdit ?
0
 
LVL 42

Expert Comment

by:Meir Rivkin
ID: 6209556
u could use OnCtlColor to change the background of the CEdit color to white.
HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
     HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
     
     if (pWnd->GetDlgCtrlID() == IDC_MYEDIT)
         pDC->SetBkColor(RGB(255, 255, 255));
     
     return hbr;
}

0
 
LVL 1

Accepted Solution

by:
iProgram earned 80 total points
ID: 6210734
You can also don't set it to Read-Only mode.
Add this code:(Edit Box ID:IDC_EDIT_TEST)
BOOL CYourDlg::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->hwnd == GetDlgItem(IDC_EDIT_TEST)->GetSafeHwnd())
{
 if(pMsg->message == WM_KEYDOWN||pMsg->message ==WM_RBUTTONDOWN)
     return TRUE;
}
return CDialog::PreTranslateMessage(pMsg);
}

0
 

Expert Comment

by:foreversoft
ID: 6212744
HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
     HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

    if (pWnd->GetDlgCtrlID() == IDC_MYEDIT)        
    {                
        pDC->SetBkColor(RGB(255, 255, 255));

        COLORREF color = RGB(255, 255, 255);
        CBrush* back_brush = new CBrush(color);
        return (HBRUSH) (back_brush->m_hObject);
    }
     return hbr;
}
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question