CView1继承CFormView,CView2继承CView类我想通过在视图1CView1里通过按一个按扭然后在CView2里实现绘图功能CView1.cpp有关内容如下#include "CView2.h"
void CView1::OnButton1()
{
// TODO: Add your control notification handler code here
CView2 *view=(CView2*)GetDocument();
view->Do();//执行CView2的绘图功能
}CView2.cpp的有关内容如下
{
void CView2::Do()
{
CDC *dc=GetDC();
dc->Rectangle(10,10,100,100);
ReleaseDC(dc);
//AfxMessageBox(_T("hello!"));
}如果CView2::Do()里只保留AfxMessageBox("...")那么程序可以正常运行,但是如果用了CDC *dc=GetDC()运行时就会弹出一个错误对话框,不知这个是什么道理啊?以下是具体代码下载,文件很小,下起来很快,望大家看看.并且有什么好的传递方法请指教。
www.fox-nice.com/milozy/FormTest.rar
void CView1::OnButton1()
{
// TODO: Add your control notification handler code here
CView2 *view=(CView2*)GetDocument();
view->Do();//执行CView2的绘图功能
}CView2.cpp的有关内容如下
{
void CView2::Do()
{
CDC *dc=GetDC();
dc->Rectangle(10,10,100,100);
ReleaseDC(dc);
//AfxMessageBox(_T("hello!"));
}如果CView2::Do()里只保留AfxMessageBox("...")那么程序可以正常运行,但是如果用了CDC *dc=GetDC()运行时就会弹出一个错误对话框,不知这个是什么道理啊?以下是具体代码下载,文件很小,下起来很快,望大家看看.并且有什么好的传递方法请指教。
www.fox-nice.com/milozy/FormTest.rar
这是什么语句啊?
GetDocument返回文档类型指针,怎么可以转换成CView2呢??
{
// TODO: Add your control notification handler code here
CFormExpDoc *pDoc=(CFormExpDoc*)GetDocument();
pDoc->m_choose=1;
pDoc->UpdateAllViews(this);
}
一般的消息是按照从子 -> 父直接一步步传递的。
而wm_command消息的传递顺序是:view ->document ->doctemplate ->frame ->app
#include "MainFrm.h"Button函数中:
CMainFrame *pMainFrame = (CMainFrame *)AfxGetMainWnd();
CView2 *pView = (CView2 *)pMainFrame->m_wndSplitter.GetPane(0, 1);
pView->Do();