CMainFrame* pMainFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
CChildFxFrame* pChildFxFrame = (CChildFxFrame*)pMainFrame->GetActiveFrame();
CFxView* pView = (CFxView*)pMainFrame->GetActiveView();
HWND hwnd = pView->GetSafeHwnd();
在线程中执行,上面代码中pView为NULL,解决方法:
App.cpp中,
//创建子窗口
CMainFrame* pFrame = STATIC_DOWNCAST(CMainFrame, m_pMainWnd);
CChildFxFrame* pChild = (CChildFxFrame*)pFrame->CreateNewChild(
RUNTIME_CLASS(CChildFxFrame), IDR_DdckFxTYPE, m_hMDIMenuFx, m_hMDIAccelFx);
pFrame->m_pFxView = pChild->m_fxView;
View.cpp中,
创建线程:
HANDLE hThread = CreateThread(NULL, 0, OpenXML, (LPVOID)this, 0, 0);
CloseHandle(hThread);
线程中调用:
CMainFrame* pMainFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
CFxView *pView = pMainFrame->m_pFxView;