注册 登录
编程论坛 VC.NET论坛

为什么不能动态创建

rxgmoral 发布于 2006-02-17 12:46, 1119 次点击

为什么不能动态创建
写了一个继承CStatic的CmStatic类,为什么不能动态创建?代码如下
<<<<<<<<<CmStatic.h>>>>>>>>
#pragma once
class CmStatic :public CStatic
{
public:
DECLARE_MESSAGE_MAP()
afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
};

<<<<<<<<CmStatic.Cpp>>>>>>
#include "stdafx.h"
#include "CmStatic.h"
BEGIN_MESSAGE_MAP(CmStatic, CStatic)
ON_WM_LBUTTONDBLCLK()
END_MESSAGE_MAP()

void CmStatic::OnLButtonDblClk(UINT nFlags, CPoint point)
{
AfxMessageBox(_T("rrr"));
CStatic::OnLButtonDblClk(nFlags, point);
}

*************调用***********
<<<<<<<<<CmFrameWnd.h>>>>>>>>>
#pragma once
#include "CmStatic.h"
class CmFrameWnd :public CFrameWnd
{
public:
CmFrameWnd();
CmStatic *m_button;
DECLARE_MESSAGE_MAP()
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnPaint();
};

<<<<<<<<<CmFrameWnd.Cpp>>>>>>>>>
#include "stdafx.h"
#include "CmFrameWnd.h"

BEGIN_MESSAGE_MAP(CmFrameWnd, CFrameWnd)
ON_WM_PAINT()
ON_WM_CREATE()
END_MESSAGE_MAP()

void CmFrameWnd::OnPaint()
{
CPaintDC dc(this);
}

int CmFrameWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
m_button->Create(_T("Text"),WS_VISIBLE|SS_NOTIFY,CRect(0,0,40,40),this->GetParent(), 1231);
//这里运行报错,但是编译没有报错,为什么?????
return 0;
}

[此贴子已经被作者于2006-2-17 12:50:02编辑过]

1 回复
#2
柳儿2006-02-28 10:59
报什么错阿?
1