2

I would like to have a CEdit control, background-painted half-length or in any other portion of its length.

I have implemented the following code

    HBRUSH CMyView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
    {
        HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);
    
        if (nCtlColor == CTLCOLOR_EDIT)
        {
    
            if (pWnd->GetDlgCtrlID() == IDC_MY_NORMAL_PERCENT_BOX)
            {
                // Set the text color to red
                pDC->SetTextColor(RGB(255, 0, 0));
    
                CRect rc;
                // Get the client area of the edit control
                m_CTV_Normal_Percent_Box_Ctrl.GetClientRect(&rc);
                m_CTV_Normal_Percent_Box_Ctrl.ScreenToClient(&rc);
                // Apply the device context to the client area of the edit control
                pDC->Rectangle(0, 0, rc.Width()/2, rc.Height());
    
                // Set the background mode for text to transparent 
                // so background will show thru.
                pDC->SetBkMode(TRANSPARENT);
    
                // Return handle to our CBrush object
                hbr = m_brush;
    
            }
        }

        return hbr;
    }

but this could not be achieved. Could anyone possibly assist?

This is what I would like to get

enter image description here

and this is what I get

enter image description here

Thanks in advance.

DevMat
  • 23
  • 6

0 Answers0