如何得到单视图MFC窗口的HDC
展开全部
通过App类来获取.
头文件定义:CmyView *GetmyView();
实现:
CmyView *CmyApp::GetmyView()
{
if(m_pDocManager)
{
POSITION pos1 = m_pDocManager->GetFirstDocTemplatePosition();
while (pos1)
{
CDocTemplate *pDocTemplate = m_pDocManager->GetNextDocTemplate(pos1);
if(pDocTemplate)
{
POSITION pos2 = pDocTemplate->GetFirstDocPosition();
while (pos2)
{
CDocument *pDoc = pDocTemplate->GetNextDoc(pos2);
if(pDoc)
{
POSITION pos3 = pDoc->GetFirstViewPosition();
while (pos3)
{
CView *pView = pDoc->GetNextView(pos3);
if(pView)
{
if(pView->IsKindOf(RUNTIME_CLASS(CmyView)))
return (CmyView*)pView;
}
}
}
}
}
}
}
return NULL;
}
头文件定义:CmyView *GetmyView();
实现:
CmyView *CmyApp::GetmyView()
{
if(m_pDocManager)
{
POSITION pos1 = m_pDocManager->GetFirstDocTemplatePosition();
while (pos1)
{
CDocTemplate *pDocTemplate = m_pDocManager->GetNextDocTemplate(pos1);
if(pDocTemplate)
{
POSITION pos2 = pDocTemplate->GetFirstDocPosition();
while (pos2)
{
CDocument *pDoc = pDocTemplate->GetNextDoc(pos2);
if(pDoc)
{
POSITION pos3 = pDoc->GetFirstViewPosition();
while (pos3)
{
CView *pView = pDoc->GetNextView(pos3);
if(pView)
{
if(pView->IsKindOf(RUNTIME_CLASS(CmyView)))
return (CmyView*)pView;
}
}
}
}
}
}
}
return NULL;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询