实例1.2:获得应用程序主窗口指针

    主窗口指针保存在CWinThread::m_pMainWnd中,可以先调用AfxGetApp函数获得应用程序的指针,然后通过应用程序的指针获得其主窗口的指针。

	//获得应用程序指针
	CMy1_2App* pApp = (CMy1_2App*)AfxGetApp();
	//获得主窗口指针
	CWnd* pMainWnd = pApp->m_pMainWnd;
	CString strText = _T("");
	strText.Format("pMainWnd = 0x%x\nthis = 0x%x\n", pMainWnd, this);
	AfxMessageBox(strText);

 

posted @ 2012-01-20 16:23  獨孤劒  阅读(386)  评论(0编辑  收藏  举报