0

在我的应用程序中,我必须在运行时更改编辑框的字体、字体大小、背景颜色属性。当用户选择特定字体时,它的颜色应该会更新并在编辑框中可见。我正在尝试通过使用 CColorDialog 、 CFontDialog 来做到这一点。有什么有效的方法吗???我可以使用 Visual Studio 环境中的属性栏来更改设置,我们曾经在开发环境中更改属性。

4

1 回答 1

1

您可以在以 CEdit 作为父类的类中捕获 WM_CTLCOLOR 消息,然后将 CDC 对象更改为您的内容。
例如 :

HBRUSH CMyEdit::CtlColor(CDC* pDC, UINT nCtlColor) 
{
    HBRUSH hBrush;
    hBrush = (HBRUSH)m_myBrush; // An handle on a brush which was created with your background color for the edit
    pDC->SetBkColor(RGB(0, 0, 0)); // Color for the text background
    pDC->SetTextColor(RGB(255, 255, 255)); // Color for the text

    // More changes on the pDC like changing the font, etc...
    return hBrush;
}
于 2013-02-18T12:38:54.203 回答