主窗口上有一个文本框。
需要实现:
当鼠标位置在主窗口上时,文本框的字体颜色为默认的黑色
当鼠标的位置在CStatic上时,文本框的字体颜色为红色
哪位能给出可行的代码

解决方案 »

  1.   

    我觉得,处理下mousemove,设个标志位,如果标志位没有置,就改变字体颜色
    一点时间没有收到mousemove就把字体置为黑
      

  2.   

    上面有口误
    主窗口上有一个文本框。
    需要实现:
    当鼠标位置在 主窗口 上时,CStatic 的字体颜色为默认的 黑色
    当鼠标的位置在 CStatic 上时,CStatic 的字体颜色为 红色。
      

  3.   

    http://www.codeproject.com/KB/miscctrl/hyperlink.aspx
      

  4.   

    BOOL CTest::PreTranslateMessage(MSG* pMsg) 
    {
    // TODO: Add your specialized code here and/or call the base class
    if(pMsg->message== WM_MOUSEMOVE)
    {
    CPoint pt=pMsg->pt;
            CRect rc;
    m_Haha.GetWindowRect(&rc);
    // if(rc.PtInRect(pt))
    {// in picture
    if(!m_bRedStatic) m_Haha.Invalidate();
    m_bRedStatic=TRUE;
    afxDump << pt << "\n";
    }
    else
    {
    if(m_bRedStatic) m_Haha.Invalidate();
    m_bRedStatic=FALSE;
    }
    }

    return CDialog::PreTranslateMessage(pMsg);
    }
    //
    HBRUSH CTest::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    {
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

    // TODO: Change any attributes of the DC here
    if(nCtlColor==CTLCOLOR_STATIC)

    if(m_bRedStatic)
    {
       pDC->SetTextColor(RGB(255,0,0));// bk of text
    }
    else
    {
       pDC->SetTextColor(RGB(0,0,0));// bk of text
    }
       return (HBRUSH)::GetStockObject(WHITE_BRUSH);//all
    }
    // TODO: Return a different brush if the default is not desired
    return hbr;
    }