简体   繁体   English

CEdit 适用于 ComCtrl32 版本 5.82 但不适用于 6.10

[英]CEdit works in ComCtrl32 Version 5.82 but not with 6.10

I want port a MFC project to the current available resources.我想将 MFC 项目移植到当前可用的资源中。

I develop with Microsoft Visual Studio Community.我使用 Microsoft Visual Studio 社区进行开发。

In the older project the Windows SDK Version is 10.0.15063.0在旧项目中,Windows SDK 版本为10.0.15063.0

in the new project the Windows SDK Version is 10.0.17763.0在新项目中,Windows SDK 版本为10.0.17763.0

the older project uses ComCtrl32.dll Version 5.82旧项目使用 ComCtrl32.dll 版本5.82

the new project uses ComCtrl32.dll Version 6.10新项目使用 ComCtrl32.dll 版本6.10

After the update with SetWindowTextW(textp) the used CEdit control shows a black control rectangle使用SetWindowTextW(textp)更新后,使用的CEdit控件显示黑色控件矩形

If I move the cursor over the control it looks as expected.如果我将光标移到控件上,它看起来像预期的那样。

ValEdit.h : 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.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.我一步一步编写了应用程序,发现导致故障的代码是CEdit控件没有正确更新。

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如果我排除 CEdit

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

the CEdit Control is updated as expected. CEdit 控件按预期更新。

Thank you for discussion谢谢讨论

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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