帮忙看下继承CStatic后的OnSetCursor和STN_CLICKED为什么无效?该如何处理
帮忙看下继承CStatic后的OnSetCursor和STN_CLICKED为什么无效?
// 头文件
#pragma once
#include <afxwin.h>
#define WMT_TIMER 101
class CInheritText : public CStatic
{
public:
CInheritText(void);
~CInheritText(void);
DECLARE_MESSAGE_MAP()
afx_msg void OnClicked();
afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
afx_msg void OnTimer(UINT_PTR nIDEvent);
afx_msg void OnPaint();
void SetDefaultCursor();
private:
HCURSOR m_hLinkCursor;
HCURSOR m_hPrevCursor;
};
// CPP 文件
#include "StdAfx.h "
#include "InheritText.h "
CInheritText::CInheritText(void)
{
m_hLinkCursor = NULL;
m_hPrevCursor = NULL;
SetDefaultCursor();
}
CInheritText::~CInheritText(void)
{
}
BEGIN_MESSAGE_MAP(CInheritText, CStatic)
ON_CONTROL_REFLECT(STN_CLICKED, &CInheritText::OnClicked)
ON_WM_SETCURSOR()
ON_WM_TIMER()
ON_WM_PAINT()
END_MESSAGE_MAP()
void CInheritText::OnClicked()
{
AfxMessageBox(_T( "Clicked "));
}
BOOL CInheritText::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
if (m_hLinkCursor)
{
::SetCursor(m_hLinkCursor);
return TRUE;
}
return FALSE;
}
void CInheritText::OnTimer(UINT_PTR nIDEvent)
{
if ( nIDEvent == WMT_TIMER )
{
// Get the mouse position
CPoint pointMouse;
GetCursorPos(&pointMouse);
ScreenToClient(&pointMouse);
CRect rect;
GetClientRect(&rect);
if (rect.PtInRect(pointMouse))
{
if (m_hLinkCursor)
{
m_hPrevCursor = ::SetCursor(m_hLinkCursor);
}
}
// Transform into client coordinates
ScreenToClient(&pointMouse);
}
CStatic::OnTimer(nIDEvent);
}
void CInheritText::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// Do not call CStatic::OnPaint() for painting messages
SetTimer(WMT_TIMER,100,NULL);
}
// The following appeared in Paul DiLascia 's Jan 1998 MSJ articles.
// It loads a "hand " cursor from the winhlp32.exe module
void CInheritText::SetDefaultCursor()
{
if (m_hLinkCursor == NULL) // No cursor handle - load our own
{
// Get the windows directory
CString strWndDir;
GetWindowsDirectory(strWndDir.GetBuffer(MAX_PATH), MAX_PATH);
strWndDir.ReleaseBuffer();
strWndDir += _T( "\\winhlp32.exe ");/*MSG0*/
// This retrieves cursor #106 from winhlp32.exe, which is a hand pointer
// 头文件
#pragma once
#include <afxwin.h>
#define WMT_TIMER 101
class CInheritText : public CStatic
{
public:
CInheritText(void);
~CInheritText(void);
DECLARE_MESSAGE_MAP()
afx_msg void OnClicked();
afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
afx_msg void OnTimer(UINT_PTR nIDEvent);
afx_msg void OnPaint();
void SetDefaultCursor();
private:
HCURSOR m_hLinkCursor;
HCURSOR m_hPrevCursor;
};
// CPP 文件
#include "StdAfx.h "
#include "InheritText.h "
CInheritText::CInheritText(void)
{
m_hLinkCursor = NULL;
m_hPrevCursor = NULL;
SetDefaultCursor();
}
CInheritText::~CInheritText(void)
{
}
BEGIN_MESSAGE_MAP(CInheritText, CStatic)
ON_CONTROL_REFLECT(STN_CLICKED, &CInheritText::OnClicked)
ON_WM_SETCURSOR()
ON_WM_TIMER()
ON_WM_PAINT()
END_MESSAGE_MAP()
void CInheritText::OnClicked()
{
AfxMessageBox(_T( "Clicked "));
}
BOOL CInheritText::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
if (m_hLinkCursor)
{
::SetCursor(m_hLinkCursor);
return TRUE;
}
return FALSE;
}
void CInheritText::OnTimer(UINT_PTR nIDEvent)
{
if ( nIDEvent == WMT_TIMER )
{
// Get the mouse position
CPoint pointMouse;
GetCursorPos(&pointMouse);
ScreenToClient(&pointMouse);
CRect rect;
GetClientRect(&rect);
if (rect.PtInRect(pointMouse))
{
if (m_hLinkCursor)
{
m_hPrevCursor = ::SetCursor(m_hLinkCursor);
}
}
// Transform into client coordinates
ScreenToClient(&pointMouse);
}
CStatic::OnTimer(nIDEvent);
}
void CInheritText::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// Do not call CStatic::OnPaint() for painting messages
SetTimer(WMT_TIMER,100,NULL);
}
// The following appeared in Paul DiLascia 's Jan 1998 MSJ articles.
// It loads a "hand " cursor from the winhlp32.exe module
void CInheritText::SetDefaultCursor()
{
if (m_hLinkCursor == NULL) // No cursor handle - load our own
{
// Get the windows directory
CString strWndDir;
GetWindowsDirectory(strWndDir.GetBuffer(MAX_PATH), MAX_PATH);
strWndDir.ReleaseBuffer();
strWndDir += _T( "\\winhlp32.exe ");/*MSG0*/
// This retrieves cursor #106 from winhlp32.exe, which is a hand pointer