WebBrowser Control (MFC) 在 Windows 7 和 Vista 中以单独的线程创建,但在 Windows XP 中工作
我在主线程中有 CWnd,并且在单独的线程中创建了带有 WebBrower 控件的 CWnd。 这是必要的,因为 Web 浏览器导航到运行 javascript 的 URL,这会阻止 Web 浏览器。因此,我在单独的线程中使用 WebBrowser 控件来防止 GUI 线程挂起。我还在应用程序的主线程中完成了此操作:
CCustomOccManager *pMgr = new CCustomOccManager();
AfxEnableControlContainer(pMgr);
这是为了将 WebBrowser 控件扩展到我的“window.external”接口。
单独的线程机制在 Windows 7 和 Vista 中运行良好。但在 Windows XP 中我得到了 MFC 断言。
这是我的代码:
m_WndMain.CreateEx(WS_EX_TOPMOST | WS_EX_TOOLWINDOW, m_mainWndClass, NULL, WS_POPUP, m_pArgs->m_WindowRect, NULL, 0);
m_WndMain.ShowWindow(SW_SHOW);
m_WndMain.UpdateWindow();
CRect clientRect;
m_WndMain.GetClientRect(&clientRect);
/* !!! CreateControl FAILS IN WINDOWS XP (=ASSERT)!!! */
m_CtrlBrowser.CreateControl(CLSID_WebBrowser, NULL, WS_VISIBLE | WS_CHILD, clientRect, &m_WndMain, AFX_IDW_PANE_FIRST);
.....
MFC Assert(第925行内部调用第305行):
wincore.cpp, LINE 925
-----------------------------------
CHandleMap* pMap = afxMapHWND();
ASSERT(pMap != NULL); <--- pMap is NULL, ASSERT is raised
wincore.cpp, LINE 305
-----------------------------------
AFX_MODULE_THREAD_STATE* pState = AfxGetModuleThreadState();
...some code
pState->m_pmapHWND; <--- m_pmapHWND is NULL!
因此“m_pmapHWND”在Windows XP中为NULL。但在 Vista 和 7 中它不是 NULL。
在 Windows XP 下,如果我在主线程中创建 WebBrowser 控件,它就可以工作。
那么问题出在哪里呢?不同的 MFC 版本或 Windows XP 问题?
I have CWnd in main thread, and a CWnd with a WebBrower control created in a seperate thread.
This is necessary, because the WebBrowser navigates to urls which have javascripts running which will block the WebBrowser. So I with the WebBrowser control in a seperate thread I prevent the GUI Thread vom hang. Also I have done this in main thread in my application:
CCustomOccManager *pMgr = new CCustomOccManager();
AfxEnableControlContainer(pMgr);
That's for extending the WebBrowser control to my on "window.external" interface.
The seperate thread mechanism works fine in Windows 7 and Vista. But in Windows XP I get MFC asserts.
That's my code:
m_WndMain.CreateEx(WS_EX_TOPMOST | WS_EX_TOOLWINDOW, m_mainWndClass, NULL, WS_POPUP, m_pArgs->m_WindowRect, NULL, 0);
m_WndMain.ShowWindow(SW_SHOW);
m_WndMain.UpdateWindow();
CRect clientRect;
m_WndMain.GetClientRect(&clientRect);
/* !!! CreateControl FAILS IN WINDOWS XP (=ASSERT)!!! */
m_CtrlBrowser.CreateControl(CLSID_WebBrowser, NULL, WS_VISIBLE | WS_CHILD, clientRect, &m_WndMain, AFX_IDW_PANE_FIRST);
.....
MFC Assert (Line 925 internally calls Line 305):
wincore.cpp, LINE 925
-----------------------------------
CHandleMap* pMap = afxMapHWND();
ASSERT(pMap != NULL); <--- pMap is NULL, ASSERT is raised
wincore.cpp, LINE 305
-----------------------------------
AFX_MODULE_THREAD_STATE* pState = AfxGetModuleThreadState();
...some code
pState->m_pmapHWND; <--- m_pmapHWND is NULL!
So "m_pmapHWND" is NULL in Windows XP. But it's not NULL in Vista and 7.
Under Windows XP, if I create the WebBrowser Control in the main thread, it works.
So what's the problem? Different MFC versions or a Windows XP issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我调试了MFC,发现COM必须在新创建的线程中初始化。
因此,在线程 startroutine 中,我
首先执行 a 操作,一切正常。
有趣的是,Windows 7 和 Vista 下不需要,只有 XP 才需要。
I have debugged the MFC and found out, that COM has to be initialized in the newly created thread.
So in the thread startroutine I'm doing a
at first and everything works.
Interesting that this isn't needed under Windows 7 and Vista, only XP.