简体   繁体   中英

CEdit works in ComCtrl32 Version 5.82 but not with 6.10

I want port a MFC project to the current available resources.

I develop with Microsoft Visual Studio Community.

In the older project the Windows SDK Version is 10.0.15063.0

in the new project the Windows SDK Version is 10.0.17763.0

the older project uses ComCtrl32.dll Version 5.82

the new project uses ComCtrl32.dll Version 6.10

After the update with SetWindowTextW(textp) the used CEdit control shows a black control rectangle

If I move the cursor over the control it looks as expected.

ValEdit.h :

class ValEdit : public CEdit
{
public:
    ValEdit();
    virtual ~ValEdit();
    int ZeroMeansInactiv;

protected:

    afx_msg BOOL OnEraseBkgnd(CDC* pDC);
    afx_msg void OnUpdate();

    DECLARE_MESSAGE_MAP()

private:

    COLORREF    m_TextColor;

    HBRUSH m_hBackgroundBrush;
    HBRUSH m_hBackgrInactivBrush;

};

ValEdit.cpp :

ValEdit::ValEdit()
{
    ZeroMeansInactiv = 1;
    m_TextColor = Black;
    m_hBackgroundBrush = CreateSolidBrush(RGB(255, 255, 255));
    m_hBackgrInactivBrush = CreateSolidBrush(RGB(90, 90, 90));
}

ValEdit::~ValEdit()
{
}

BEGIN_MESSAGE_MAP(ValEdit, CEdit)
    ON_WM_ERASEBKGND()
    ON_CONTROL_REFLECT(EN_UPDATE, OnUpdate)
END_MESSAGE_MAP()

BOOL ValEdit::OnEraseBkgnd(CDC* pDC) 
{
    RECT rc;
    this->GetClientRect(&rc);

    SetMapMode(*pDC, MM_TEXT);
    FillRect(*pDC, &rc, !!ZeroMeansInactiv ? m_hBackgroundBrush : m_hBackgrInactivBrush );
    return TRUE;
}

void ValEdit::OnUpdate() 
{
    RedrawWindow();
}

Thank you for advice

Erhy

please, I need explanations!

I programmed the app step by step and found the code, which is responsible for the malfunction, that the CEdit control is not updated correctly.

HBRUSH CStyleToolkitDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
    if (nCtlColor == CTLCOLOR_STATIC)
    {
        // We handle this message only if we have set the region
        BOOL bHandled = m_bIsRgnSet;
        if (bHandled)
        {
            HDC hDC = pDC->GetSafeHdc();
            SetBkMode(hDC, TRANSPARENT);
            return (HBRUSH)GetStockObject(HOLLOW_BRUSH); //causes the malfunction
        }
    }
    return hbr;
}

If I exclude CEdit with

if (!pWnd->IsKindOf(RUNTIME_CLASS(CEdit)))
            return (HBRUSH)GetStockObject(HOLLOW_BRUSH);

the CEdit Control is updated as expected.

Thank you for discussion

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM