控件子类化的问题!!!!

jacky1019 2003-04-21 03:22:13
我用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
}

...全文
68 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jacky1019 2003-04-21
  • 打赏
  • 举报
回复
多谢两位了!
So1o 2003-04-21
  • 打赏
  • 举报
回复
或者在Style里加上 SS_NOTIFY
feiniaoliang 2003-04-21
  • 打赏
  • 举报
回复
在你的rc中,单击你的静态控件,右键选择属性,选中Styles中的Notify!

ok,你的问题解决了~~~~~~~~

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧