c++ - 围绕案例 CTLCOLOR_STATIC : 的混淆

标签 c++ mfc

我正在为我们的系统更新一些旧代码,但我不明白为什么在静态情况下检查编辑控件有效。

代码如下:

switch(nCtlColor)
{
case CTLCOLOR_STATIC:
    {
        if( ((pWnd->GetDlgCtrlID() == IDC_EDIT_SP_FROM) || (pWnd->GetDlgCtrlID() == IDC_EDIT_SP_TO)) && 
            (m_RadioDateSelection == 0) )
        {
            pDC->SetBkColor(g_crSectionLTBlue);
            hbr = g_cbSectionLTBlue;
            break;
        }

        pDC->SetTextColor(g_crBlack);
        hbr = g_cbSectionLTBlue;
        pDC->SetBkColor(g_crSectionLTBlue);
    }
    break;

case CTLCOLOR_LISTBOX:
    pDC->SetTextColor(g_crBlack);
    pDC->SetBkColor(g_crWhite);
    hbr = (HBRUSH)GetStockObject(WHITE_BRUSH);
    break;

case CTLCOLOR_EDIT: case CTLCOLOR_MSGBOX:
    pDC->SetTextColor(g_crBlack);
    pDC->SetBkColor(g_crWhite);
    hbr = (HBRUSH)GetStockObject(WHITE_BRUSH);      
    break;
}

注意在 CTLCOLOR_STATIC 中检查了 IDC_EDIT 控件。 我的问题是,如果它是一个编辑控件,它甚至不应该被检查,它永远不应该通过检查,因此编辑控件的背景永远不应该变成蓝色。此外,在静态情况下,颜色在任何情况下都不会设置为白色。但是,当前检查有效,当 radio 设置为 0 时,两个框都是蓝色的,否则它们会变成白色。在我的静态情况下,bkcolor 从未设置为白色,那么为什么它会正确切换而不是始终为蓝色,或者如果它将其视为编辑并将其设置为白色,为什么 bkcolor 不始终为白色?

是否应该能够在静态情况下检查编辑控件?

最佳答案

根据 MSDN :

A static control, or an edit control that is read-only or disabled, sends the WM_CTLCOLORSTATIC message to its parent window when the control is about to be drawn.

关于c++ - 围绕案例 CTLCOLOR_STATIC : 的混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29657113/

相关文章:

c++ - pcl_ros::transformPointCloud 的向量化

C++ Qt : Static builds and external dylibs

c++ - thrust::sort 对某些值进行了错误排序

mfc - 如何使用 COleDropTarget 为提升的 MFC 应用程序启用拖放

c++ - C++ 编译器使用什么类型的程序集?

android - 为 iOS 和 Android 编译 C++ 代码 (Xcode)。这是真的吗?

c++ - 覆盖 OnFileOpen 和 OnFileSave 函数 - 注册表未更新?

windows-7 - Visual Studio 2012 MFC 向导生成带有航空的应用程序故障

c++ - CStatic 控件中的字母间距?

c++ - 使用 MFC 中的 CDatabase 连接到 oracle 服务器