工控编程吧
标题:
上位机MFC如何获取视窗指针
[打印本页]
作者:
qq263946146
时间:
2019-7-26 11:19
标题:
上位机MFC如何获取视窗指针
视窗可以很方便通过函数获取GetActiveView。 CMy123View* pView = (CMy123View*)GetActiveView();
if (pView == NULL)
{
return;
}
CRect rect;
pView->GetClientRect(rect);
CString strText = _T("");
strText.Format(_T("在框架中获得当前视图指针:0x%08X"), pView);
CDC* pDC = pView->GetDC();
pDC->SetTextAlign(TA_CENTER);
pDC->TextOut(rect.Width() / 2, rect.Height() / 2, strText);
如果 是多文档程序的话,还得通过子框架的GetActiveView获取
//获得当前子框架
CMDIChildWnd* pChildFrame = (CMDIChildWnd*)GetActiveFrame();
if (pChildFrame == NULL)
{
return;
}
//获得当前视图
CDemoView* pView = (CDemoView*)pChildFrame->GetActiveView();
if (pView == NULL)
{
return;
}
CRect rect;
pView->GetClientRect(rect);
CString strText = _T("");
strText.Format(_T("在框架中获得当前视图指针:0x%08X"), pView);
CDC* pDC = pView->GetDC();
pDC->SetTextAlign(TA_CENTER);
pDC->TextOut(rect.Width() / 2, rect.Height() / 2, strText);
欢迎光临 工控编程吧 (https://www.gkbc8.com/)
Powered by Discuz! X3.4