MFC-窗口指针_控件


MFC-窗口指针_窗口句柄_02




void CMFCApplication10Dlg::OnBnClickedButton1() {     // TODO:  在此添加控件通知处理程序代码      //得到当前窗口句柄     HWND hWnd = GetSafeHwnd();      //由窗口句柄得到窗口指针     CWnd* pWnd = CWnd::FromHandle(hWnd);      //打印窗口地址(地址用16进制显示)     CString s;     s.Format("pWnd = 0x%X\nthis = 0x%X\n", pWnd, this);     AfxMessageBox(s); }




void CMFCApplication10Dlg::OnBnClickedButton2() {     // TODO:  在此添加控件通知处理程序代码      //得到应用程序指针     CMFCApplication10App* pApp = (CMFCApplication10App*)AfxGetApp();      //获得主窗口的指针     CWnd* pMainWnd = pApp->m_pMainWnd;      //打印主窗口的地址     CString s;     s.Format("pMainWnd = 0x%X\nthis = 0x%X", pMainWnd, this);     AfxMessageBox(s); }