请问如何实现当鼠标停在静态文本控件上时,字就马上改变颜色? 请问如何实现当鼠标停在静态文本控件上时,字就马上改变颜色? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 大概的思路:class CMyStatic : public CStatic{... //{{AFX_MSG(CMyStatic) afx_msg void OnPaint(); afx_msg void OnMouseMove(UINT nFlags, CPoint point); afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message); //}}AFX_MSG...};void CMyStatic::OnMouseMove(UINT nFlags, CPoint point) { //当鼠标第一次移进来时: if(...) { SetCapture( ); //设置颜色 m_colrText = RGB(...) } else { RECT r; GetWindowRect( &r ); if( !PtInRect( &r, point ) ) //当鼠标移到文本框外时 { ReleaseCapture(); //设置默认颜色 m_colrText = RGB(...) } }CStatic::OnMouseMove(nFlags, point);}void CMyStatic::OnPaint() { CPaintDC dc(this); // device context for painting // TODO: Add your message handler code here RECT r; GetClientRect( &r ); CString strText; GetWindowText( strText ); CFont * pOldFont = dc.SelectObject( GetFont() ); dc.SetBkMode(TRANSPARENT); dc.SetTextColor( (COLORREF)m_colrText ); dc.DrawText( strText, &r, DT_SINGLELINE | DT_LEFT | DT_VCENTER | DT_NOCLIP ); dc.SelectObject( pOldFont ); // Do not call CStatic::OnPaint() for painting messages} CPoint point; CRect rect; GetCursorPos(&point); m_hypermail.GetWindowRect(rect); if(rect.PtInRect(point)) { HCURSOR m_cursor = AfxGetApp()->LoadCursor(IDC_CURSOR1); SetCursor(m_cursor); m_hypermail.SetColor(RGB(255,0,0)); return TRUE; } else m_hypermail.SetColor(RGB(0,0,255));其中,m_hypermail响应了WM_CTLCOLOR消息。 VC+MAPX 如何实现打印地图 国内一知名公司的上机笔试题 用过TVisualFramework的请讲! VC2005始终不显示最近打开项目 求 YD-602磁卡读写器开发文档,及示例程序。 如何让ActiveX控件处理待机,休眠消息 如何实现当你把鼠标放在编辑框上是就会出现一个提示框 vc2010操作word2010 求一个好点子---------------------------------------- MFC 的~~~~ 能不能用键盘模拟方法输入#字符和,字符。比如用keybd_event等。能行就可以! 我在做一个字体安装程序,遇到问题! :) 请大家看看这段代码为什么不对?
class CMyStatic : public CStatic
{
... //{{AFX_MSG(CMyStatic)
afx_msg void OnPaint();
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
//}}AFX_MSG...
};
void CMyStatic::OnMouseMove(UINT nFlags, CPoint point)
{
//当鼠标第一次移进来时:
if(...)
{
SetCapture( );
//设置颜色
m_colrText = RGB(...)
}
else
{
RECT r;
GetWindowRect( &r );
if( !PtInRect( &r, point ) ) //当鼠标移到文本框外时
{
ReleaseCapture(); //设置默认颜色
m_colrText = RGB(...)
} }
CStatic::OnMouseMove(nFlags, point);
}void CMyStatic::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
RECT r;
GetClientRect( &r );
CString strText;
GetWindowText( strText ); CFont * pOldFont = dc.SelectObject( GetFont() );
dc.SetBkMode(TRANSPARENT);
dc.SetTextColor( (COLORREF)m_colrText );
dc.DrawText( strText, &r, DT_SINGLELINE | DT_LEFT | DT_VCENTER | DT_NOCLIP ); dc.SelectObject( pOldFont );
// Do not call CStatic::OnPaint() for painting messages
}
CRect rect;
GetCursorPos(&point);
m_hypermail.GetWindowRect(rect);
if(rect.PtInRect(point))
{
HCURSOR m_cursor = AfxGetApp()->LoadCursor(IDC_CURSOR1);
SetCursor(m_cursor);
m_hypermail.SetColor(RGB(255,0,0));
return TRUE;
}
else m_hypermail.SetColor(RGB(0,0,255));
其中,m_hypermail响应了WM_CTLCOLOR消息。