none
如何用事件实现在网页加载完成后,执行后面的代码 RRS feed

  • 问题

  • void   CTestNavigateView::OnNewWebPage()  
    {
                    //   TODO:   Add   your   command   handler   code   here
                    Navigate2(_T( "http://192.168.34.120/DMS/index.jsp "));
                    m_NavigateEvent.Lock();                
                    MessageBox( "Hello   DMS ");                  
    }

    void   CTestNavigateView::OnDocumentComplete(LPCTSTR   lpszURL)  
    {
    //   TODO:   Add   your   specialized   code   here   and/or   call   the   base   class
    m_NavigateEvent.SetEvent();  
    CHtmlView::OnDocumentComplete(lpszURL);
    }
    OnNewWebPage()是一个工具栏按钮的执行函数,我想在Navigate2(_T( "http://192.168.34.120/DMS/index.jsp "));加载完页面后再执行MessageBox( "Hello   DMS ");     所以在中间用一个event变量锁定。然后希望在
    CTestNavigateView::OnDocumentComplete   中将event解锁从而达到目的。但是在实际执行时,并没有跳转到OnDocumentComplete   中执行解锁,而是一直停在m_NavigateEvent.Lock();     这一句了。谁能告诉我为什么没有跳到OnDocumentComplete   中呢?
    如果没有m_NavigateEvent.Lock();     这一句,网页和消息框是可以正常打开的,但网页还没加载完,消息框就弹出来了。
    如果用多线程要怎么实现?我试过,没有成功。

    我想用CEvent来实现,应该是要用多线程了。两个进程访问同一个CEvent变量,一个进程加锁,另一个进程解锁。可是为啥调用了Navigate2就是不能跳到OnDocumentComplete()中呢?应该怎么写?

    2010年12月2日 12:59

答案

  • 您好,

    欢迎您来到MSDN中文论坛!

    关于第一个问题,您可以参考一下文档

    http://support.microsoft.com/kb/180366

    关于第二个问题,我建议您能把错误信息一同发出来,这样有利于我们帮您找出错误。

    另外,每个帖子尽量只提出一个问题以方便大家查阅,如果您一个帖子提出了2个问题,第二个问题其他的用户可能就看不到。希望您下次能注意

    Regards!

    Jesse


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • 已标记为答案 frank985 2010年12月8日 12:37
    2010年12月6日 9:20
    版主

全部回复

  • 另一段代码,数字转换的,看看有什么bug吗?

    BOOL CConversionDlg::PreTranslateMessage(MSG* pMsg)
    {
        // TODO: Add your specialized code here and/or call the base class
        if( pMsg->hwnd == GetDlgItem(IDC_EDIT_INPUT)->m_hWnd )
            {
                    if(pMsg->message == WM_KEYDOWN  && pMsg->wParam == VK_RETURN )
                    {
                            PostMessage(WM_ENTER_NUMBER, 0, 0);
                    }
            }


        return CDialog::PreTranslateMessage(pMsg);
    }

    DWORD CConversionDlg::OnInputNumber()
    {        
            return 0;
    }

    void CConversionDlg::OnChangeEditInput()
    {
        // TODO: If this is a RICHEDIT control, the control will not
        // send this notification unless you override the CDialog::OnInitDialog()
        // function and call CRichEditCtrl().SetEventMask()
        // with the ENM_CHANGE flag ORed into the mask.
        
        // TODO: Add your control notification handler code here
            int i=0;
            int j=0;
            int k=0;
            CString csInputString;

            //SendMessage(WM_KEYDOWN, VK_END,0);
            UpdateData();
            //m_csConvertedRst = m_csInputNumber;
            m_ctlEdit.GetWindowText(csInputString);
            csInputString.Replace(" ", "");
            csInputString.TrimLeft(_T("0"));
            m_csConvertedRst.Empty();

            int iInputLength = csInputString.GetLength();
            CString csConvertInputString=csInputString;
            for(i=iInputLength-4; i>=0; i=i-4)
            {
                    csConvertInputString.Insert(i-j," ");
                    j++;
            }
            csConvertInputString.TrimLeft();

            int iQuotient  = iInputLength / 4;
            int iRemainder = iInputLength % 4;

            int iDataLength=0;
            if(iRemainder == 0)
            {
                    iDataLength = iQuotient;
            }
            else
            {
                    iDataLength = iQuotient+1;
            }


            CHAR4* pChar4 = new CHAR4[iDataLength];
            ZeroMemory(pChar4, iDataLength*sizeof(CHAR4));

            CStringArray csArr;

            int iTmp=0;
            for(i=0; i<iDataLength; i++)
            {
                    for(j=0; j<4; j++)
                    {
                            iTmp = iInputLength - i*4 -(3-j)-1;
                            if(iTmp<0)
                            {
                                    continue;
                            }
                            pChar4[i][j] = csInputString[iTmp];
                    }
            }


            //i=iDataLength;
            
            CString csPostfix;
            CString csLitfix;
            CString csOneSection;
            int iSecLength=0;
            for(i=iDataLength-1; i>=0; i--)
            {
                    csOneSection="";
                    csPostfix="";
                    for(j=0; j<4; j++)
                    {
                            csLitfix="";
                            if(pChar4[i][j] == 0)
                            {
                                    continue;
                            }
                            switch(j)
                            {
                            case 0:
                                    if(pChar4[i][j] != '0')
                                    {
                                            csLitfix="ǧ";
                                    }

                                    break;

                            case 1:
                                    if(pChar4[i][j] != '0')
                                    {
                                            csLitfix="°Ù";
                                    }

     
                                    break;

                            case 2:
                                    if(pChar4[i][j] != '0')
                                    {
                                            csLitfix="Ê®";
                                    }
     
                                    break;

                            case 3:
                                    break;
                            default:
                                    break;
                            }

                            switch( pChar4[i][j] )
                            {
                            case '0':
                                    csOneSection += "Áã";
                                    break;

                            case '1':
                                    csOneSection += "Ò»";
                                    break;

                            case '2':
                                    csOneSection += "¶þ";
                                    break;

                            case '3':
                                    csOneSection += "Èý";
                                    break;

                            case '4':
                                    csOneSection += "ËÄ";
                                    break;

                            case '5':
                                    csOneSection += "Îå";
                                    break;

                            case '6':
                                    csOneSection += "Áù";
                                    break;

                            case '7':
                                    csOneSection += "Æß";
                                    break;

                            case '8':
                                    csOneSection += "°Ë";
                                    break;


                            case '9':
                                    csOneSection += "¾Å";
                                    break;

                            default:
                                    break;
                            }

                            csOneSection += csLitfix;

                    }

                    csOneSection.Replace("ÁãÁãÁãÁã","Áã");
                    csOneSection.Replace("ÁãÁãÁã","Áã");
                    csOneSection.Replace("ÁãÁã","Áã");
                    CString csRight = csOneSection.Right(2);
                    if(csRight.Compare("Áã")  == 0)
                    {
                            csOneSection = csOneSection.Left(csOneSection.GetLength()-2);
                    }

                    
                    if(i%2==1)
                    {
                            csPostfix = "Íò ";
                    }
                    else
                    {
                            iSecLength = i/2;
                            for(k=0; k<iSecLength; k++)
                            {
                                    csPostfix += "ÒÚ";
                            }
                    }

                    if(!csOneSection.IsEmpty())
                    {
                            csOneSection += csPostfix;
                    }
                    csArr.Add(csOneSection);                
            }

            for(i=0; i<csArr.GetSize(); i++ )
            {
                    m_csConvertedRst += csArr[i];    
                    if( (csArr[i].Right(2)).Compare("ÒÚ") == 0 )
                    {
                            m_csConvertedRst += "\n";
                    }
            }

            if(m_csConvertedRst == "" && iInputLength>0)
            {
                    m_csConvertedRst = "Áã";
            }

            //m_csInputNumber = csConvertInputString;
            
            UpdateData(FALSE);
            //UpdateWindow();    
            delete[] pChar4;
     
    }

     

    2010年12月5日 23:59
  • 您好,

    欢迎您来到MSDN中文论坛!

    关于第一个问题,您可以参考一下文档

    http://support.microsoft.com/kb/180366

    关于第二个问题,我建议您能把错误信息一同发出来,这样有利于我们帮您找出错误。

    另外,每个帖子尽量只提出一个问题以方便大家查阅,如果您一个帖子提出了2个问题,第二个问题其他的用户可能就看不到。希望您下次能注意

    Regards!

    Jesse


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • 已标记为答案 frank985 2010年12月8日 12:37
    2010年12月6日 9:20
    版主
  •  

    您好,

     

    您的问题已经解决了么?

    如果已经解决了,请您把您认为正确的或者有建议性的回复标记为答复。

    如果没有解决,请继续更新一些与该问题有关的信息,以便我们能及时给您帮助。

     

    Best regards,

    Jesse


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    2010年12月8日 7:38
    版主
  • 谢谢!
    2010年12月8日 12:37