Solved

CEdit Read-Only question

Posted on 2001-06-19
5
552 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 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

14 Experts available now in Live!

Get 1:1 Help Now