MFC-窗口指针
作者:互联网
内容转载自https://www.bilibili.com/video/BV1AT4y137gS?p=24
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); }
标签:MFC,窗口,pMainWnd,pWnd,CWnd,0x%,指针 来源: https://www.cnblogs.com/nxopen2018/p/13999645.html