我这样编的(其中CSuperWordView继承于CRichEditView):
CWnd* pWnd=AfxGetMainWnd();
ASSERT_VALID(pWnd);
CView* pView=static_cast<CFrameWnd*>(pWnd)->GetActiveFrame()
->GetActiveView();
CSuperWordView* pView =(CSuperWordView*) pView; 但是ASSERT_VALID(pWnd)在调试过程中通不过。好像pWnd为NULL,如下:
void AFXAPI AfxAssertValidObject(const CObject* pOb,
LPCSTR lpszFileName, int nLine)
{
if (pOb == NULL)//就是这个了,pwnd为NULL,为什么了?这些代码我看不太懂???
{
TRACE0("ASSERT_VALID fails with NULL pointer.\n");
if (AfxAssertFailedLine(lpszFileName, nLine))
AfxDebugBreak();//调试时指向这里
return; // quick escape
}
因为我想在在别的对象(ToolBar,dialog。。)中访问活动View中的函数.
CWnd* pWnd=AfxGetMainWnd();
ASSERT_VALID(pWnd);
CView* pView=static_cast<CFrameWnd*>(pWnd)->GetActiveFrame()
->GetActiveView();
CSuperWordView* pView =(CSuperWordView*) pView; 但是ASSERT_VALID(pWnd)在调试过程中通不过。好像pWnd为NULL,如下:
void AFXAPI AfxAssertValidObject(const CObject* pOb,
LPCSTR lpszFileName, int nLine)
{
if (pOb == NULL)//就是这个了,pwnd为NULL,为什么了?这些代码我看不太懂???
{
TRACE0("ASSERT_VALID fails with NULL pointer.\n");
if (AfxAssertFailedLine(lpszFileName, nLine))
AfxDebugBreak();//调试时指向这里
return; // quick escape
}
因为我想在在别的对象(ToolBar,dialog。。)中访问活动View中的函数.
解决方案 »
- AfxGetMainWnd()返回值为空的问题
- 实现一个文件编译器(不使用控件),使用什么数据结构比较好?
- 百分求CSocket写Ftp客户端对服务器列表的例子
- 编译时出现这个错误,请教!
- 如何用Visual C++编程实现全屏幕显示?
- 谁能帮我讲一下CSocket类当收发大数据包时的处理!
- atl com 求救
- 请问各位大侠,IDirectDrawGammaControl需要哪个连接库?我找了几天,也没有找到!!!谢谢!!!
- 请问大家在做项目时是不是也用了很多别人做的类呢?
- DirectX 怎么用3D的 .was 文件 动画图片 创建 纹理?
- 怎样获得局域网中连接到服务器的所有计算机列表?包括IP 、域名、主机名和MAC地址?
- 菜鸟问什么是水晶报表?
->GetActiveView());
如果用一句话不行,分开写
CMainFrame *pFrame =
(CMainFrame*)AfxGetApp()->m_pMainWnd;
CHildFrame *pChild =
(CHildFrame*)pFrame->GetActiveFrame();
CView *pView = (CView*)pFrame->GetActiveView();
CDocTemplate* pTemplate;
POSITION pos,docpos,viewpos;
CDocument* pDoc=NULL;
CView *pView; pos=AfxGetApp()->GetFirstDocTemplatePosition();
pTemplate=AfxGetApp()->GetNextDocTemplate(pos);
docpos=pTemplate->GetFirstDocPosition(); //找到第一个文档模板
while(docpos)
{
pDoc=pTemplate->GetNextDoc(docpos);
viewpos=pDoc->GetFirstViewPosition();
while(viewpos!=NULL)
{
pView=pDoc->GetNextView(viewpos);
if(pView->IsKindOf(RUNTIME_CLASS(CMServerView)))
//CMServerView是我的视图类
{
CMServerView *cv1;
cv1=(CMServerView *)pView;
.....
}
}
}
用CMainFrame *pFrame =(CMainFrame*)AfxGetApp()->m_pMainWnd;
运行执行时出错(窗口不存在):ASSERT(::Iswindow(m_hwnd));
不过还有个问题,如何确认找到的View是不是活动VIEW了??(小弟为vc初学者,还有很多不知道)