控件子类化的问题!!!!
我用CStatic做基类在工程中新插入了一个CHyperlinkStatic类,就是想模仿网页上的那种超链接邮件地址,我在该类中处理了WM_MOUSEMOVE消息,然后将AboutDialog中的某个文本框映射为CHyperlinkStatic类,但当鼠标移过的时候却没有动静,我又测试了其它的诸如WM_LBUTTONDOWN的消息也没有响应。然而,我直接在constructor函数中加入测试语句的话又有响应,真搞不懂是为什么?
我把代码大致贴出来,请大侠帮我分析一下!
CHyperlinkStatic.h:
#if !defined(AFX_HYPERLINKSTATIC_H__09998C61_5522_408A_A670_A815C41FA0FD__INCLUDED_)
#define AFX_HYPERLINKSTATIC_H__09998C61_5522_408A_A670_A815C41FA0FD__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// HyperlinkStatic.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CHyperlinkStatic window
class CHyperlinkStatic : public CStatic
{
// Construction
public:
CHyperlinkStatic();
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CHyperlinkStatic)
//}}AFX_VIRTUAL
// Implementation
public:
void SetEMail(CString strEMail);
virtual ~CHyperlinkStatic();
// Generated message map functions
protected:
//{{AFX_MSG(CHyperlinkStatic)
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
CString m_strEMail;
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_HYPERLINKSTATIC_H__09998C61_5522_408A_A670_A815C41FA0FD__INCLUDED_)
CHyperlinkStatic.cpp:
// HyperlinkStatic.cpp : implementation file
//
#include "stdafx.h"
#include "book.h"
#include "HyperlinkStatic.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CHyperlinkStatic
CHyperlinkStatic::CHyperlinkStatic()
{
MessageBox("constructor");
}
CHyperlinkStatic::~CHyperlinkStatic()
{
}
BEGIN_MESSAGE_MAP(CHyperlinkStatic, CStatic)
//{{AFX_MSG_MAP(CHyperlinkStatic)
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDOWN()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHyperlinkStatic message handlers
void CHyperlinkStatic::SetEMail(CString strEMail)
{
m_strEMail = strEMail;
}
void CHyperlinkStatic::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
MessageBox("mousemove"); //测试用而已
CStatic::OnMouseMove(nFlags, point);
}
void CHyperlinkStatic::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
MessageBox("l_button down");
CStatic::OnLButtonDown(nFlags, point);
}
book.cpp:(about dialog)
#include "HyperlinkStatic.h"
....
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
CHyperlinkStatic m_hlsJackie;
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
public:
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
virtual BOOL OnInitDialog();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
};
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
DDX_Control(pDX, IDC_STATIC_JACKIE, m_hlsJackie);
//}}AFX_DATA_MAP
}