我要在MDI中得一个对话框中得一个Static 上创建一个CView改如何创建啊!

huanglaoxie1 2006-04-25 08:42:31
在MDI中,通过菜单弹出一个对话框,对话框上有一个Static控件,我想将我的一个CViewEx嵌入到Static中,我嵌入成功了,可是当在CViewEx一单击,就出现地址错误!!这是怎么回事啊!
...全文
86 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
largedong 2006-04-25
  • 打赏
  • 举报
回复
77651128
huanglaoxie1 2006-04-25
  • 打赏
  • 举报
回复
是啊,我也我就添了这些代码,别的也没添啊,你有QQ或msn吗?我把我的工程传给你,你帮我看看吧!
largedong 2006-04-25
  • 打赏
  • 举报
回复
这部分代码没发现什么问题
huanglaoxie1 2006-04-25
  • 打赏
  • 举报
回复
// MyDLG.cpp : implementation file
//

#include "stdafx.h"
#include "MDI.h"
#include "MyDLG.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMyDLG dialog


CMyDLG::CMyDLG(CWnd* pParent /*=NULL*/)
: CResizingDialog(CMyDLG::IDD, pParent)
{
//{{AFX_DATA_INIT(CMyDLG)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}


void CMyDLG::DoDataExchange(CDataExchange* pDX)
{
CResizingDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyDLG)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CMyDLG, CResizingDialog)
//{{AFX_MSG_MAP(CMyDLG)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyDLG message handlers

CWnd* CMyDLG::CreateNewView(CCreateContext *pContext, CWnd *pParent, CRect &rect, int wID)
{
CWnd* pWnd = NULL;

if (pContext != NULL)
{
if (pContext->m_pNewViewClass != NULL)
{
pWnd = (CWnd*)pContext->m_pNewViewClass->CreateObject();
if (pWnd == NULL)
{
TRACE1("Error: Dynamic create of view %Fs failed\n", pContext->m_pNewViewClass->m_lpszClassName);
return NULL;
}
ASSERT(pWnd->IsKindOf(RUNTIME_CLASS(CWnd)));

if (!pWnd->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, rect, pParent, wID, pContext))
{
TRACE0("Error: couldn't create view \n");
return NULL;
}
// send initial notification message
//(CWnd*)pWnd->SendMessage(WM_INITIALUPDATE);
}
}
return pWnd;
}

BOOL CMyDLG::OnInitDialog()
{
CResizingDialog::OnInitDialog();

// TODO: Add extra initialization here
CCreateContext cc;
cc.m_pNewViewClass = RUNTIME_CLASS(CViewEx);
cc.m_pCurrentDoc = NULL;
cc.m_pNewDocTemplate = NULL;
cc.m_pLastView = NULL;
cc.m_pCurrentFrame = NULL;

m_pView = (CViewEx*)CreateNewView(&cc, this, CRect(0, 0, 0, 0), 0);
m_pView->OnInitialUpdate();
if (m_pView == NULL)
EndDialog(IDCANCEL);

// place the View in the view rectangle
CRect rect;
CStatic *s = (CStatic*)GetDlgItem(IDC_STATIC_VIEW);

s->GetWindowRect (&rect);
ScreenToClient(rect);
m_pView->MoveWindow(&rect);
s->ShowWindow(SW_HIDE);

return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}

ViewEx.cpp
// ViewEx.cpp : implementation file
//

#include "stdafx.h"
#include "MDI.h"
#include "ViewEx.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CViewEx

IMPLEMENT_DYNCREATE(CViewEx, CView)

CViewEx::CViewEx()
{
}

CViewEx::~CViewEx()
{
}


BEGIN_MESSAGE_MAP(CViewEx, CView)
//{{AFX_MSG_MAP(CViewEx)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CViewEx drawing

void CViewEx::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
// TODO: add draw code here
}

/////////////////////////////////////////////////////////////////////////////
// CViewEx diagnostics

#ifdef _DEBUG
void CViewEx::AssertValid() const
{
CView::AssertValid();
}

void CViewEx::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CViewEx message handlers


largedong 2006-04-25
  • 打赏
  • 举报
回复
风格没设对?
你把 创建部分和单击响应的代码贴出来

15,978

社区成员

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

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