注册 登录
编程论坛 VC++/MFC

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

zkj_tz 发布于 2013-06-09 11:08, 521 次点击
我使用MFC调用HTML的Url获取页面,然后将页面截取图片进行保存
在我的主进程中测试是成功的,后来我将其放入进程中处理,却不行了
我是用它启动线程的,

hHandle = ::CreateThread(NULL, 0, ThreadFun, (LPVOID)pParam, 0, NULL);

线程函数中调用它生成图片

m_pHTMLImage->CreateImage(szBuf, szPath, CSize(800,600), CSize(800,600));

程序问题出在该函数中的这两句
程序代码:

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();

程序在进入RunModalLoop()中停住了,跟踪进入该函数,发现是在系统文件vc\atlmfc\src\mfc\wincore.cpp的函数int CWnd::RunModalLoop(DWORD dwFlags)获取消息时停住,应该是无法获取正确消息导致,不知道怎么处理
程序代码:

do
{
    ASSERT(ContinueModal());

    // pump message, but quit on WM_QUIT
    if (!AfxPumpMessage())
//程序是在这里停住的,我网上百度了一下,有的是这样的if (!AfxGetThread()->PumpMessage())
//好像是线程安全的意思,难道我的调用出错了??还是我的系统有问题????
//网上描述:《<span style="color: #008000; text-decoration: underline;">http://[/color]
    {
        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));



真心求教,希望高手不吝指教,感激不尽!!
1 回复
#2
zkj_tz2013-06-09 13:14
怎么就没有人呢?
自己先顶一下
1