Solved

CEdit Read-Only question

Posted on 2001-06-19
5
554 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:sedgwick
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 20 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Whole sheet autoscrub still needed 19 48
VBA "SendKeys" Syntax for Multiple Keystrokes 7 103
tripleUp challenge 7 73
wordcount challenge 11 106
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

914 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now