MFC多线程截取html页面图片的问题

来源:互联网 发布:网络视听许可证照租赁 编辑:程序博客网 时间:2024/06/03 06:33
我使用MFC调用HTML的Url获取页面,然后将页面截取图片进行保存
在我的主进程中测试是成功的,后来我将其放入进程中处理,却不行了

我是用它启动线程的,

[code=c]
hHandle = ::CreateThread(NULL, 0, ThreadFun, (LPVOID)pParam, 0, NULL);
[/code]
线程函数中调用它生成图片
[code=c]
m_pHTMLImage->CreateImage(szBuf, szPath, CSize(800,600), CSize(800,600));
[/code]
程序问题出在该函数中的这两句
[code=c]
if (m_pBrowser->Navigate2(&vUrl, &vFlags, &vNull, &vPostData, &vNull) == S_OK)
//We have to pump messages to ensure the event handler (DocumentComplete)
//is called.
//调用这句代码的作用是产生线程阻塞,直到DocumentComplete函数被高用,
//防止页面还没加载完就生成
RunModalLoop();
[/code]
程序在进入RunModalLoop()中停住了,跟踪进入该函数,发现是在系统文件vc\atlmfc\src\mfc\wincore.cpp的函数int CWnd::RunModalLoop(DWORD dwFlags)获取消息时停住,应该是无法获取正确消息导致,不知道怎么处理
[code=c]
do
{
ASSERT(ContinueModal());


// pump message, but quit on WM_QUIT
if (!AfxPumpMessage())
//程序是在这里停住的,我网上百度了一下,有的是这样的if (!AfxGetThread()->PumpMessage()) 
//好像是线程安全的意思,难道我的调用出错了??还是我的系统有问题????
//网上描述:《http://www.cnblogs.com/dubingsky/archive/0001/01/01/1511299.html》
{
AfxPostQuitMessage(0);
return -1;
}


// show the window when certain special messages rec'd
if (bShowIdle &&
(pMsg->message == 0x118 || pMsg->message == WM_SYSKEYDOWN))
{
ShowWindow(SW_SHOWNORMAL);
UpdateWindow();
bShowIdle = FALSE;
}


if (!ContinueModal())
goto ExitModal;


// reset "no idle" state after pumping "normal" message
if (AfxIsIdleMessage(pMsg))
{
bIdle = TRUE;
lIdleCount = 0;
}


} while (::PeekMessage(pMsg, NULL, NULL, NULL, PM_NOREMOVE));


[/code]

希望高手不吝指教,感激不尽!!



没有分了,发在这里,哎....
原创粉丝点击