主窗口指针保存在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);