MFC中鼠标点击在静态文本框1中改变原有颜色,并改变另一个静态文本框2中的颜色

我在OnCtlColor中用createsolidbrush设置了静态文本框1和2的颜色,然后我想在鼠标点击静态文本框1时自身颜色变成静态文本框2的颜色,并将静态文本框2的颜色变成静态文本框
1的颜色(颜色互换)
鼠标点击事件应该怎么写
void CDialog11::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default

}

图片说明

可以在按钮点击中用一个变量flag保存切换状态,然后invalidate刷新按钮,然后按钮的OnCtlColor中根据flag,进行对应的颜色切换

图片说明

 void CQ680148Dlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
    // TODO: Add your message handler code here and/or call default
    if (point.x > m_rect.left && point.x < m_rect.right && point.y <m_rect.bottom && point.y > m_rect.top)
    {
        m_COLORREF = RGB(255, 0, 0);
    }
    Invalidate();
    CDialog::OnLButtonDown(nFlags, point);
}

HBRUSH CQ680148Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

    // TODO: Change any attributes of the DC here
    if (pWnd->GetDlgCtrlID() == IDC_STATIC1 || pWnd->GetDlgCtrlID() == IDC_STATIC2)
    {
        pDC->SetTextColor(m_COLORREF);
    }
    // TODO: Return a different brush if the default is not desired
    return hbr;
}

好像到处都是楼主的问题,而且都是这么简单的问题,看来楼主还是先打好基础把,基础太差了,要先努力打好基础了,多看看MFC的相关资料......二楼使用的工具好复古啊,现在都出到vs2017了,看来是有怀旧情节的一个人,哈哈,还有你这个功能的话,不需要用OnLButtonDown(UINT nFlags, CPoint point) 这个函数,CStatic控件本身有个鼠标左键点击函数afx_msg void OnLButtonDown(UINT nFlags, CPoint point);楼主还要用OnLButtonDown(UINT nFlags, CPoi监听整个窗口的左键点击,然后判断鼠标落点》不知道具体是想实现什么功能,为何要多此一举nt point)

先设置鼠标单击事件,设标志位记录状态0和1,点击按钮时切换状态,当状态为0时设为某种颜色,状态为1时为另一种颜色

BOOL CQ680148Dlg::OnInitDialog()
{
    CDialog::OnInitDialog();

    // Add "About..." menu item to system menu.

    // IDM_ABOUTBOX must be in the system command range.
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000);

    CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
        CString strAboutMenu;
        strAboutMenu.LoadString(IDS_ABOUTBOX);
        if (!strAboutMenu.IsEmpty())
        {
            pSysMenu->AppendMenu(MF_SEPARATOR);
            pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
        }
    }

    // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE);         // Set big icon
    SetIcon(m_hIcon, FALSE);        // Set small icon

    // TODO: Add extra initialization here
    GetDlgItem(IDC_STATIC1)->GetWindowRect(&m_rect);  
    ScreenToClient(&m_rect);
    m_COLORREF = GetSysColor(COLOR_BTNFACE);
    return TRUE;  // return TRUE  unless you set the focus to a control
}

HBRUSH CQ680148Dlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

    // TODO: Change any attributes of the DC here
    if (pWnd->GetDlgCtrlID() == IDC_STATIC1 || pWnd->GetDlgCtrlID() == IDC_STATIC2)
    {
        pDC->SetBkColor(m_COLORREF);
    }
    // TODO: Return a different brush if the default is not desired
    return hbr;
}