如何得到单视图MFC窗口的HDC
发布网友
发布时间:2022-05-13 06:37
我来回答
共1个回答
热心网友
时间:2023-11-26 01:14
通过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;
}