How to change editbox's background color when it is set to read-only?
-
When I set the editbox to read-only, its backgroud color will be gray. Can I set it to another color? Thanks in advance.
-
When I set the editbox to read-only, its backgroud color will be gray. Can I set it to another color? Thanks in advance.
Try to chenge the backcolor with the Erase Background message.... Best Regards Carlos Antollini. Sonork ID 100.10529 cantollini
-
When I set the editbox to read-only, its backgroud color will be gray. Can I set it to another color? Thanks in advance.
You can!! :) handle the WM_CTLCOLOR message and check if the handle of the window passed to the handler function is equal to the handle of the editbox whose colour you want to change. Then set the handle hbr to the brush you want to use as your background. Call SetBkColor() to change the background colour used when painting your text. Look up WM_CTLCOLOR in MSDN!! hope this helps Adam. "I spent a lot of my money on booze, birds and fast cars. The rest I just squandered" George Best.
-
You can!! :) handle the WM_CTLCOLOR message and check if the handle of the window passed to the handler function is equal to the handle of the editbox whose colour you want to change. Then set the handle hbr to the brush you want to use as your background. Call SetBkColor() to change the background colour used when painting your text. Look up WM_CTLCOLOR in MSDN!! hope this helps Adam. "I spent a lot of my money on booze, birds and fast cars. The rest I just squandered" George Best.
I have tried to handle the WM_CTLCOLOR message, but failed. When the editbox is set to read-only, it will not send the WM_CTLCOLOR to its parent window. Anyway, thanks a lot.
-
I have tried to handle the WM_CTLCOLOR message, but failed. When the editbox is set to read-only, it will not send the WM_CTLCOLOR to its parent window. Anyway, thanks a lot.
Hmm.. I am doing the same... the following code paints a white background in IDC_USER and IDC_KEY which are read only (I didn't want them to be gray) and paints everything else with a blue background. They are Enabled though (i.e. EnableWindow(TRUE)).
HBRUSH CCncloginDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) { HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); HWND hWnd=pWnd->GetSafeHwnd(); // TODO: Change any attributes of the DC here if(nCtlColor==CTLCOLOR_EDIT || hWnd==GetDlgItem(IDC_USER)->GetSafeHwnd() || hWnd==GetDlgItem(IDC_KEY)->GetSafeHwnd()) { pDC->SetBkColor(RGB(255,255,255)); hbr=(HBRUSH)m_brBrush; } else { pDC->SetBkColor(RGB(128,128,200)); hbr=(HBRUSH)m_brBrush2; } // TODO: Return a different brush if the default is not desired return hbr; }
Sounds mysterious! If you work out what's up then post it. I would be interested to hear what it was. :) Adam. "I spent a lot of my money on booze, birds and fast cars. The rest I just squandered" George Best.