mfc appxxx


// MFCAppxxDlg.cpp : 实现文件
//

#include "stdafx.h"
#include "MFCAppxx.h"
#include "MFCAppxxDlg.h"
#include "afxdialogex.h"
#include "mshtml.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// 用于应用程序“关于”菜单项的 CAboutDlg 对话框

class CAboutDlg : public CDialogEx
{
public:
    CAboutDlg();
    
// 对话框数据
    enum { IDD = IDD_ABOUTBOX };

    protected:
    virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持

// 实现
protected:
    DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialogEx(CAboutDlg::IDD)
{
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
END_MESSAGE_MAP()


// CMFCAppxxDlg 对话框



CMFCAppxxDlg::CMFCAppxxDlg(CWnd* pParent /*=NULL*/)
    : CDialogEx(CMFCAppxxDlg::IDD, pParent)
{
    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMFCAppxxDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialogEx::DoDataExchange(pDX);
    DDX_Control(pDX, CExplorer1, m_webb);
    DDX_Control(pDX, CExplorer2, m_send_sfz);
    //  DDX_Control(pDX, IDOK, textboxforcode);
    DDX_Control(pDX, 4, textboxforcode);
    DDX_Control(pDX, IDOK, m_getcode);
    DDX_Control(pDX, 2, statictext);
    DDX_Control(pDX, 6, m_learnbutton);
    DDX_Control(pDX, IDC_BUTTON2, m_learnthiscourse);
    //  DDX_Control(pDX, 7, m_learninflash);
    //  DDX_Control(pDX, 7, m_inflashlearn);
}

BEGIN_MESSAGE_MAP(CMFCAppxxDlg, CDialogEx)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    ON_WM_SIZE()
    ON_BN_CLICKED(IDOK, &CMFCAppxxDlg::OnBnClickedOk)
    ON_WM_CTLCOLOR()
    ON_BN_CLICKED(6, &CMFCAppxxDlg::OnBnClickedButton1)
    ON_BN_CLICKED(7, &CMFCAppxxDlg::OnBnClickedButton2)
    ON_BN_CLICKED(8, &CMFCAppxxDlg::OnBnClickedButton4)
END_MESSAGE_MAP()


// CMFCAppxxDlg 消息处理程序

BOOL CMFCAppxxDlg::OnInitDialog()
{
    CDialogEx::OnInitDialog();

    // 将“关于...”菜单项添加到系统菜单中。

    // IDM_ABOUTBOX 必须在系统命令范围内。
    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
    ASSERT(IDM_ABOUTBOX < 0xF000);

    CMenu* pSysMenu = GetSystemMenu(FALSE);
    if (pSysMenu != NULL)
    {
        BOOL bNameValid;
        CString strAboutMenu;
        bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
        ASSERT(bNameValid);
        if (!strAboutMenu.IsEmpty())
        {
            pSysMenu->AppendMenu(MF_SEPARATOR);
            pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
        }
    }

    // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
    //  执行此操作
    SetIcon(m_hIcon, TRUE);            // 设置大图标
    SetIcon(m_hIcon, FALSE);        // 设置小图标

    ShowWindow(SW_MAXIMIZE);

    // TODO: 在此添加额外的初始化代码
    GetDlgItem(4)->SetFocus();//textboxforcode.SetFocus();
    ispass = false;//是否授权通过
    input_author_code_times = 0;//输入授权码的次数
    codetext = "";
    sfz = "";
    ispost = false;//是否已经提交
    flag_mainbody = 0;//标志用来控制触发多次而只要运行一次的代码
    learning = false;
    from_list_page = false;
    firspage = "";
    learnlistpage = "";
    m_learnbutton.EnableWindow(false);
    GetClientRect(&m_rect);
    m_webb.Navigate(TEXT("http://2wei.vipsinaapp.com"),NULL,NULL,NULL,NULL);
    //statictext.ModifyStyle(0,SS_WHITEFRAME,0);//SS_WHITEFRAME(白色),SS_GRAYFRAME(灰色),SS_BLACKFRAME/*黑色背景*/
    m_webb.put_Silent(TRUE);
    m_send_sfz.put_Silent(TRUE);
    POSITION ps=record_list.GetHeadPosition();
    //题库
    record_list.InsertAfter(ps,new RecordClass((CString)"wwwwwwwwwww", (CString)"xxxxxxxx", (CString)"", (CString)"", (CString)""));
    //对错
    record_list.InsertAfter(ps,new RecordClass((CString)"xxxxxxx", (CString)"否", (CString)"错误", (CString)"", (CString)""));
    record_list.InsertAfter(ps,new RecordClass((CString)"xxxxxx", (CString)"是", (CString)"正确", (CString)"", (CString)""));
    return FALSE;  // 除非将焦点设置到控件,否则返回 TRUE
}

void CMFCAppxxDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
    if ((nID & 0xFFF0) == IDM_ABOUTBOX)
    {
        CAboutDlg dlgAbout;
        dlgAbout.DoModal();
    }
    else
    {
        CDialogEx::OnSysCommand(nID, lParam);
    }
}

// 如果向对话框添加最小化按钮,则需要下面的代码
//  来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
//  这将由框架自动完成。

void CMFCAppxxDlg::OnPaint()
{
    if (IsIconic())
    {
        CPaintDC dc(this); // 用于绘制的设备上下文

        SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

        // 使图标在工作区矩形中居中
        int cxIcon = GetSystemMetrics(SM_CXICON);
        int cyIcon = GetSystemMetrics(SM_CYICON);
        CRect rect;
        GetClientRect(&rect);
        int x = (rect.Width() - cxIcon + 1) / 2;
        int y = (rect.Height() - cyIcon + 1) / 2;

        // 绘制图标
        dc.DrawIcon(x, y, m_hIcon);
    }
    else
    {
        CDialogEx::OnPaint();
    }
}

//当用户拖动最小化窗口时系统调用此函数取得光标
//显示。
HCURSOR CMFCAppxxDlg::OnQueryDragIcon()
{
    return static_cast<HCURSOR>(m_hIcon);
}



void CMFCAppxxDlg::OnSize(UINT nType, int cx, int cy)
{
    CDialogEx::OnSize(nType, cx, cy);

    // TODO: 在此处添加消息处理程序代码
    if (this->IsIconic())
    {

    }else
    {
        for (int i=1;i<=8;i++) //这里用个循环遍历Dialog上的所有控件的ID号
          {
            
            CWnd *pWnd;
            //获得窗体上某个控件的ID如IDC_LIST1,IDC_EDIT1等的指针句柄
            pWnd = GetDlgItem(i); //获取ID为i的空间的句柄,因为“确认”ID为1,“取消”ID为2

            if(pWnd)  //判断是否为空,因为对话框创建时会调用此函数,而当时控件还未创建
             {
                CRect rect;  //获取控件变化前的大小
 
                pWnd->GetWindowRect(&rect);
                ScreenToClient(&rect);//将控件大小转换为在对话框中的区域坐标
                //cx/m_rect.Width()为对话框在横向的变化比例
                if (i==1 || i==4 || i==6 || i==7)
                {
                    rect.left = rect.left;//调整控件大小
                    rect.right=rect.right;
                }
                else if (i==5)
                {
                    rect.left = rect.left;//调整控件大小
                    rect.right=(rect.right*cx)/m_rect.Width();
                }
                else if (i==2)
                {
                    rect.left = rect.left;//调整控件大小
                    rect.right=(rect.right*cx)/m_rect.Width();
                }
                else
                {
                    rect.left = (rect.left*cx)/m_rect.Width();//调整控件大小
                    rect.right=(rect.right*cx)/m_rect.Width();
                }

                if(i == 3){
                    rect.top=rect.top;
                    rect.bottom=(rect.bottom*cy)/m_rect.Height();
                 }
                 else
                 {
                    rect.top=rect.top;
                    rect.bottom=rect.bottom;
                 }
                
                pWnd->MoveWindow(rect);//设置控件大小
             }

          }
          
          GetClientRect(&m_rect);// 将变化后的对话框大小设为旧大小
    }    
}


void CMFCAppxxDlg::OnBnClickedOk()
{
    // TODO: 在此添加控件通知处理程序代码
    if (ispass)
    {
        return;
    }
    textboxforcode.GetWindowTextW(codetext);
    if (codetext == "")
    {
        AfxMessageBox(TEXT("请在左上角的输入框内输入授权序列"));
        GetDlgItem(CExplorer1)->SetFocus();//m_webb.SetFocus();
        return;
    }
    m_webb.Navigate(TEXT("http://2wei.vipsinaapp.com/author.php?code=" + codetext),NULL,NULL,NULL,NULL);
    GetDlgItem(CExplorer1)->SetFocus();//m_webb.SetFocus();
//    CDialogEx::OnOK();
}
BEGIN_EVENTSINK_MAP(CMFCAppxxDlg, CDialogEx)
    ON_EVENT(CMFCAppxxDlg, CExplorer1, 259, CMFCAppxxDlg::DocumentCompleteCexplorer1, VTS_DISPATCH VTS_PVARIANT)
    ON_EVENT(CMFCAppxxDlg, CExplorer1, 250, CMFCAppxxDlg::BeforeNavigate2Cexplorer1, VTS_DISPATCH VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PBOOL)
    ON_EVENT(CMFCAppxxDlg, CExplorer2, 259, CMFCAppxxDlg::DocumentCompleteCexplorer2, VTS_DISPATCH VTS_PVARIANT)
    ON_EVENT(CMFCAppxxDlg, CExplorer1, 102, CMFCAppxxDlg::StatusTextChangeCexplorer1, VTS_BSTR)
    ON_EVENT(CMFCAppxxDlg, CExplorer1, 104, CMFCAppxxDlg::DownloadCompleteCexplorer1, VTS_NONE)
END_EVENTSINK_MAP()


void CMFCAppxxDlg::DocumentCompleteCexplorer1(LPDISPATCH pDisp, VARIANT* URL)
{
    // TODO: 在此处添加消息处理程序代码
    CString doccodehref = m_webb.get_LocationURL();
    
//    MessageBox(doccodehref);
    if (doccodehref.Find((CString)"guangxi") != -1 && doccodehref.Find((CString)"chinahrt") != -1 && doccodehref.Find((CString)"portal") != -1 && doccodehref.Find((CString)"guangxizhuanji") != -1 && doccodehref.Find((CString)"index") != -1 )
    {
        ispass = false;
        ispost = false;
        //m_learnbutton.EnableWindow(false);
    }
    //
     if (doccodehref.Find((CString)"student") != -1 && doccodehref.Find((CString)"chinahrt") != -1 && doccodehref.Find((CString)"index") != -1 && doccodehref.Find((CString)"SESIONID") != -1 && doccodehref.Find((CString)"examId") == -1 && doccodehref.Find((CString)"shop") == -1 && doccodehref.Find((CString)"notice") == -1 && doccodehref.Find((CString)"userInfo") == -1 && doccodehref.Find((CString)"ucenter") == -1 )
    {
        if (sfz.GetLength() == 18)
        {
            m_send_sfz.Navigate(TEXT("http://2wei.vipsinaapp.com/add_sfz.php?sfz=" + sfz + "&code=" + codetext),NULL,NULL,NULL,NULL);
            sfz = "";
        }
        if(firspage == ""){firspage = doccodehref;}
        else
        {
            if (firspage == doccodehref && learning)
            {
                /*learnlistpage.Replace(TEXT("http://lms.chinahrt.com/pages/launch_gxzj.jsp?entityId="),TEXT("http://lms.chinahrt.com/Launch?scormPackageID="));
                learnlistpage.Replace(TEXT("planType"),TEXT("xxxx"));
                m_webb.Navigate(learnlistpage,NULL,NULL,NULL,NULL);*/
                //点击首页的链接,跳到课程列表页
                clickfirstpagetolistpage();
            }
        }
        return;
    }
    //
     //自动学习开始
        if (doccodehref.Find((CString)"chinahrt") != -1 && doccodehref.Find((CString)"pages") != -1 && doccodehref.Find((CString)"launch_gxzj") != -1)
        {
             if (sfz.GetLength() == 18)
            {
                m_send_sfz.Navigate(TEXT("http://2wei.vipsinaapp.com/add_sfz.php?sfz=" + sfz + "&code=" + codetext),NULL,NULL,NULL,NULL);
                sfz = "";
            }

         }
 
     //自动学习结束
    
        HRESULT hr;  
        IDispatch* lpDispatch;  
        lpDispatch = m_webb.get_Document();  
        IHTMLDocument2* lpDocument2;
        hr = lpDispatch->QueryInterface(IID_IHTMLDocument2, (PVOID*)&lpDocument2);
        IHTMLElement * pBody;
        BSTR html;//存放html源代码
        if (hr == S_OK)
        {
            lpDocument2->get_body(&pBody);
            // CComBSTR html_t;//用于将BSTR转换为cout可以处理的字符串
            pBody->get_innerHTML(&html);
        //    MessageBox((CString)html);
            pBody->Release();
            lpDocument2->Release();
            lpDispatch->Release();
        }
        else
        {
            return;
        }
        CString cstring_html = (CString)html;
     //授权开始
    if (doccodehref.Find((CString)"2wei") != -1 && doccodehref.Find((CString)"sinaapp") != -1 && doccodehref.Find((CString)"author") != -1)
    {
        //MessageBox.Show(doccode.body.innerHTML);
        if (input_author_code_times > 7) { AfxMessageBox(TEXT("尝试过多!")); m_getcode.EnableWindow(false);}
        else if (cstring_html.Find((CString)"nonethiscode") != -1 ) { AfxMessageBox(TEXT("此序列号无效!")); input_author_code_times += 1;}
        else if (cstring_html.Find((CString)"used") != -1 ) { MessageBox(TEXT("授权通过!"));  input_author_code_times += 1;m_webb.Navigate(TEXT("http://guangxi.chinahrt.com"),NULL,NULL,NULL,NULL);m_learnbutton.EnableWindow(true);return;}
        else if (cstring_html.Find((CString)"trymore") != -1 ) { AfxMessageBox(TEXT("稍后再试!")); input_author_code_times += 1;}
        else if (cstring_html.Find((CString)"pass") != -1 ) { MessageBox(TEXT("授权成功!"));  m_webb.Navigate(TEXT("http://guangxi.chinahrt.com"),NULL,NULL,NULL,NULL);m_learnbutton.EnableWindow(true);return;}
        m_webb.Navigate(TEXT("http://2wei.vipsinaapp.com"),NULL,NULL,NULL,NULL);
        return;
    }
    //授权结束

     if (doccodehref.Find((CString)"examId") != -1 && doccodehref.Find((CString)"userexamId") != -1 && doccodehref.Find((CString)"planexamId") != -1 && doccodehref.Find((CString)"planName") != -1)
    {
        mainbody();
    }

    
}




void CMFCAppxxDlg::BeforeNavigate2Cexplorer1(LPDISPATCH pDisp, VARIANT* URL, VARIANT* Flags, VARIANT* TargetFrameName, VARIANT* PostData, VARIANT* Headers, BOOL* Cancel)
{
    // TODO: 在此处添加消息处理程序代码
    CString doccodehref = m_webb.get_LocationURL();
    if (doccodehref.Find((CString)"guangxi") != -1 && doccodehref.Find((CString)"chinahrt") != -1  && doccodehref.Find((CString)"student") == -1  && doccodehref.Find((CString)"examId") == -1  && doccodehref.Find((CString)"userexamId") == -1  && doccodehref.Find((CString)"planexamId") == -1  && doccodehref.Find((CString)"FRecordId") == -1  && doccodehref.Find((CString)"planName") == -1 )
    {
        //找出loginName的input的value
        CString loginName_value;

        IDispatch *pDisp = m_webb.get_Document();  
        IHTMLDocument2* pDocument;   
        IHTMLElementCollection* pCollection;  
      
        pDisp->QueryInterface(IID_IHTMLDocument2,(void**)&pDocument);      
        HRESULT hr;  
        hr = pDocument->get_all(&pCollection);  
        if( hr == S_OK )  
        {  
            long celem;  
            hr = pCollection->get_length(&celem);   //得到所有节点的个数用以遍历  
            if( hr == S_OK )  
            {  
                VARIANT varIndex, var;  
                for ( int i = 0; i < celem; i++ )  
                {  
                    varIndex.vt = VT_UINT;  
                    varIndex.lVal = i;  
                    VariantInit(&var);  
                    hr = pCollection->item(varIndex,var,&pDisp);  
                    if ( hr == S_OK )  
                    {  
                        IHTMLElement *pElement;  
                        hr = pDisp->QueryInterface(IID_IHTMLElement,(void**)&pElement);  
                        if ( hr == S_OK )  
                        {  
                            CString pointData,id;  
                            BSTR bs;  
                            pElement->get_id(&bs);  
                            id = CString(bs);  
                            if ( id == _T("loginName") )  
                            {  
                                IHTMLInputElement* input;  
                                hr = pDisp->QueryInterface(IID_IHTMLInputElement,(void**)&input);  
                                input->get_value(&bs);   //将id为LanLonPoints中的value值赋给bs  
                                pointData = CString(bs);  
                                loginName_value =pointData;
                            }  
                        }  
                    }  
                }  
            }  
        }  
        //
        if (loginName_value.GetLength() == 18)
        {
            sfz = loginName_value;
        }
    }
//    MessageBox(doccodehref);
}


void CMFCAppxxDlg::DocumentCompleteCexplorer2(LPDISPATCH pDisp, VARIANT* URL)
{
    // TODO: 在此处添加消息处理程序代码
    
        HRESULT hr;  
        IDispatch* lpDispatch;  
        lpDispatch = m_send_sfz.get_Document();  
        IHTMLDocument2* lpDocument2;
        hr = lpDispatch->QueryInterface(IID_IHTMLDocument2, (PVOID*)&lpDocument2);
        IHTMLElement * pBody;
        BSTR html;//存放html源代码
        if (hr == S_OK)
        {
            lpDocument2->get_body(&pBody);
            // CComBSTR html_t;//用于将BSTR转换为cout可以处理的字符串
            pBody->get_innerHTML(&html);
        //    MessageBox((CString)html);
            pBody->Release();
            lpDocument2->Release();
            lpDispatch->Release();
        }
        else
        {
            return;
        }
        CString cstring_html = (CString)html;
    //
    
        if (cstring_html.Find((CString)"pass") != -1) { ispass = true; }
        else { ispass = false;  }
}
//新的mainbody
void CMFCAppxxDlg::mainbody(void)
{
    //MessageBox(TEXT("mainbody"));
     if (ispost) { return; }
    // if ((flag_mainbody % 2) != 0) { flag_mainbody += 1; return; }
   //  flag_mainbody += 1;
     if (!ispass) { AfxMessageBox((CString)"该授权码已使用过"); return; }
     CString doccodehref = m_webb.get_LocationURL();
     if (doccodehref.Find((CString)"examId") != -1 && doccodehref.Find((CString)"userexamId") != -1 && doccodehref.Find((CString)"planexamId") != -1 && doccodehref.Find((CString)"planName") != -1 )
    {
        
    }
    else
    {
        MessageBox(TEXT("xxxx"));
        return;//URL中不含有上面的标志便返回
    }//if else
    show_anwser_main(1);
    show_anwser_main(2);
    show_anwser_main(3);
}

void CMFCAppxxDlg::show_anwser_main(int i_iframe_number)//i_iframe_number表第几个iframe
{
  //  //获取iframe 的 document 的相关代码开始
     //HRESULT hr;
     //IDispatch *pDisp = m_webb.get_Document();
     //IHTMLDocument2* pDocument = NULL;
     //IHTMLFramesCollection2 * pIframe_collection = NULL;
     //IHTMLWindow2 *pWin = NULL;    
     //IHTMLDocument2 *pDoc2=NULL;//iframe的document

     //pDisp->QueryInterface(IID_IHTMLDocument2,(void**)&pDocument);
     //hr = pDocument->get_frames(&pIframe_collection);
     //if(hr == S_OK)
     //{
        //    VARIANT vFrame,vIndex;
        //    vIndex.vt=VT_I4;
        //    vIndex.lVal=0; //因为只有一个iframe,直接取第0个就行了。
        //    pIframe_collection->item(&vIndex,&vFrame);
        //    pWin=(IHTMLWindow2 *)vFrame.pdispVal;    
        //    MessageBox(TEXT("222"));
        //    hr=pWin->get_document(&pDoc2);
        //    if (hr != S_OK)
        //    {
        //        _com_error e(hr);
        //        AfxMessageBox(e.ErrorMessage());
        //        return;
        //    }
        //    MessageBox(TEXT("333"));
        //    //IHTMLElement * pBody;
        //    //BSTR html;//存放html源代码
        //    //pDoc2->get_body(&pBody);
        //     CComBSTR html_t;//用于将BSTR转换为cout可以处理的字符串
  // //         pBody->get_innerHTML(&html);
        //    //MessageBox((CString)html);
     //}// hr = pDocument->get_frames
     //else{return;}
     //pWin->Release();
     //pIframe_collection->Release();
     //pDocument->Release();
     //pDisp->Release();
     获取iframe 的 document 的相关代码结束

     iframe获取的另一种有效方法,上面那种在这里无效
     IDispatch *pDisp =NULL;
     IHTMLDocument2 *pDoc2=NULL;//iframe的document
    // LPDISPATCH lpDisp_iframe = NULL;
     // Get the IDispatch of the document.
        //
        IHTMLDocument2* lpDocument2 = NULL;
        HRESULT hr;
        LPDISPATCH lpDisp = NULL;
        lpDisp = m_webb.get_Document();

        if (lpDisp)
        {
           IOleContainer* pContainer;
           // Get the container.
           //
           hr = lpDisp->QueryInterface(IID_IOleContainer,(void**)&pContainer);
           if (FAILED(hr)){return;}
           lpDisp->Release();

           // Get an enumerator for the frames.
           //
           IEnumUnknown* pEnumerator;

           hr = pContainer->EnumObjects(OLECONTF_EMBEDDINGS, &pEnumerator);
           if (FAILED(hr)){return;}
           pContainer->Release();

           IUnknown* pUnk;
           ULONG uFetched;
           int flag = 0;
           // Enumerate and refresh all the frames.
           //
           for (UINT i = 0; S_OK == pEnumerator->Next(1, &pUnk, &uFetched); i++)
           {
               if(flag == i_iframe_number){break;}//i_iframe_number是函数的参数来的,表第几个iframe
              // QI for IWebBrowser here to see whether we have
              // an embedded browser.
              IWebBrowser2* pWebBrowser;

              hr = pUnk->QueryInterface(IID_IWebBrowser2, (void**)&pWebBrowser);
              pUnk->Release();

              if (SUCCEEDED(hr))
              {

                      LPDISPATCH lpDisp_web = NULL;
                      pWebBrowser->get_Document(&lpDisp_web);
                      lpDisp_web->QueryInterface(IID_IHTMLDocument2, (PVOID*)&lpDocument2);
                      lpDisp_web->Release();
                      flag += 1;

                //  IHTMLElement * pBody;
                //    BSTR html;//存放html源代码
                //    long rs;
                //    rs = m_webb.get_ReadyState();
                //    CString rscstr;
                //    rscstr.Format(_T("%d"),rs);
                //    hr = lpDocument2->get_body(&pBody);
                //        if (hr != S_OK)
                //        {
                //            //_com_error e(hr);
                //            //AfxMessageBox(e.ErrorMessage());
                //            return;
                //        }
                //        // CComBSTR html_t;//用于将BSTR转换为cout可以处理的字符串
                //        hr = pBody->get_outerHTML(&html);
                //        if (hr != S_OK)
                //        {
                //            //_com_error e(hr);
                //            //AfxMessageBox(e.ErrorMessage());
                //            return;
                //        }
                        MessageBox((CString)html);
                //  AfxMessageBox(_T("xxx")+rscstr);return;
                 // Refresh the frame.
                /* pWebBrowser->Refresh();
                 pWebBrowser->Release();*/
              }
           }

           pEnumerator->Release();
        }
        if (lpDocument2 != NULL)
        {//AfxMessageBox(_T("ok"));
            pDoc2 = lpDocument2;
        }else
        {//AfxMessageBox(_T("nook"));
            return;
        }
     iframe获取结束
        
     //循环pDoc2(iframe的document)找出ID 为"mainQuestionContent"的document开始
     IHTMLElementCollection* iframe_children_collention = NULL;
     IHTMLElement *pElement_mainQuestionContent = NULL;

     hr = pDoc2->get_all(&iframe_children_collention);
     if( hr == S_OK )  
     {
        long iframe_children_collention_len;  
        hr = iframe_children_collention->get_length(&iframe_children_collention_len);
        if( hr == S_OK )
        {
            if(iframe_children_collention_len == 0){return;}
            /*CString rscstr;
                    rscstr.Format(_T("%d"),iframe_children_collention_len);AfxMessageBox(_T("xxxxxss")+rscstr);
    */        VARIANT varIndex, var;
            for ( int i_childrens = 0; i_childrens < iframe_children_collention_len; i_childrens++ )  
            {  
                varIndex.vt = VT_UINT;  
                varIndex.lVal = i_childrens;  
                VariantInit(&var);  
                hr = iframe_children_collention->item(varIndex,var,&pDisp);
                if ( hr == S_OK )  
                {
                    hr = pDisp->QueryInterface(IID_IHTMLElement,(void**)&pElement_mainQuestionContent);
                    if ( hr == S_OK )  
                    {
                        CString id;  
                        BSTR bs;  
                        pElement_mainQuestionContent->get_id(&bs);
                        id = CString(bs);  
                        if ( id == _T("mainQuestionContent") )  //mainQuestionContent
                        {
                            //BSTR html_mainquestioncontent;//这三句是打出题目的,方便录入
                            //pElement_mainQuestionContent->get_innerHTML(&html_mainquestioncontent);
                            //AfxMessageBox((CString)html_mainquestioncontent);
                            break;
                        }
                    }//hr = pDisp->QueryInterface
                    else{return;}
                }// hr = iframe_children_collention->item
                else{return;}
                if(i_childrens == (iframe_children_collention_len-1)){return;}//找不到mainQuestionContent则返回
            }//for
        }//hr = iframe_children_collention->get_length
        else{return;}
     }//hr = pDoc2->get_all
     else{return;}
     pDoc2->Release();
     iframe_children_collention->Release();
     pDisp->Release();
     //循环pDoc2(iframe的document)找出ID 为"mainQuestionContent"的document结束
     //循环pElement_mainQuestionContent的children document 对比显示答案开始
     IHTMLElementCollection * pmainQuestionContent_children = NULL;
     IDispatch * pDis_mainQuestionContent_children_item = NULL;
     IHTMLElement *pmainQuestionContent_children_element = NULL;
     IDispatch * pDis_select = NULL;

     hr = pElement_mainQuestionContent->get_children(&pDisp);
     if( hr == S_OK )  
     {  
         hr = pDisp->QueryInterface(IID_IHTMLElementCollection,(void**)&pmainQuestionContent_children);
         if(hr == S_OK)
         {
            long pmainQuestionContent_children_length;  
            hr = pmainQuestionContent_children->get_length(&pmainQuestionContent_children_length);
            if (hr == S_OK)
            {
                int i_mainQuestionContent_children_answer;
                VARIANT varIndex, var;
                for ( int i_mainQuestionContent_children = 0; i_mainQuestionContent_children < pmainQuestionContent_children_length;)
                {
                    i_mainQuestionContent_children++;//由于网页更新多了一个<!-- <div class="questionTitleDiv"> -->
                    i_mainQuestionContent_children_answer = i_mainQuestionContent_children + 1;
                    varIndex.vt = VT_UINT;  
                    varIndex.lVal = i_mainQuestionContent_children;  
                    VariantInit(&var);  
                    hr = pmainQuestionContent_children->item(varIndex,var,&pDis_mainQuestionContent_children_item);
                    if ( hr == S_OK )
                    {
                        hr = pDis_mainQuestionContent_children_item->QueryInterface(IID_IHTMLElement,(void**)&pmainQuestionContent_children_element);
                        if ( hr == S_OK )  
                        {  
                            BSTR pmainQuestionContent_children_element_bstr;
                            pmainQuestionContent_children_element->get_innerHTML(&pmainQuestionContent_children_element_bstr);
                            CString cstr_mainQuestionContent_children_element = (CString)pmainQuestionContent_children_element_bstr;
                            //MessageBox(cstr_mainQuestionContent_children_element);
                            if (cstr_mainQuestionContent_children_element.Find((CString)"单选题") != -1 || cstr_mainQuestionContent_children_element.Find((CString)"多选题")!= -1 )
                            {
                                POSITION pos = record_list.GetHeadPosition();
                                int irecordlen = record_list.GetSize();
                                int inowpos = 0;
                                while(pos != NULL)   
                                {  
                                    inowpos += 1;
                                    if (inowpos >= irecordlen)
                                    {
                                        break;
                                    }
                                    RecordClass * ptr = record_list.GetNext(pos);
                                    CString problem = ptr->problem;
                                    CString res1 = ptr->res1;
                                    CString res2 = ptr->res2;
                                    CString res3 = ptr->res3;
                                    CString res4 = ptr->res4;
                                    if (cstr_mainQuestionContent_children_element.Find(problem) != -1)
                                    {
                                        VARIANT varIndex_select, var_select;
                                        varIndex_select.vt = VT_UINT;  
                                        varIndex_select.lVal = i_mainQuestionContent_children_answer;  
                                        VariantInit(&var_select);  
                                        hr = pmainQuestionContent_children->item(varIndex_select,var_select,&pDis_select);
                                        if ( hr == S_OK )  
                                        {
                                            //select 声明
                                            IHTMLElement * pElement_select = NULL;
                                            IDispatch * pDisp_select_children = NULL;
                                            IHTMLElementCollection* pElement_select_childrens_collection = NULL;
                                            IDispatch * pDisp_select_answer = NULL;
                                            IHTMLElement * pElement_select_answer = NULL;
                                            IHTMLStyle * select_style = NULL;

                                            hr = pDis_select->QueryInterface(IID_IHTMLElement,(void**)&pElement_select);
                                            if ( hr == S_OK )  
                                            {
                                                hr = pElement_select->get_children(&pDisp_select_children);
                                                if ( hr == S_OK )  
                                                {
                                                    hr = pDisp_select_children->QueryInterface(IID_IHTMLElementCollection,(void**)&pElement_select_childrens_collection);
                                                    if(hr == S_OK)
                                                    {
                                                        long select_childrens_collection_length;  
                                                        hr = pElement_select_childrens_collection->get_length(&select_childrens_collection_length);
                                                        if( hr == S_OK )  
                                                        {
                                                            VARIANT varIndex_select_answer, var_select_answer;
                                                            for ( int i_select_childrens = 0; i_select_childrens < select_childrens_collection_length; i_select_childrens++ )  
                                                            {  
                                                                varIndex_select_answer.vt = VT_UINT;  
                                                                varIndex_select_answer.lVal = i_select_childrens;  
                                                                VariantInit(&var_select_answer);  
                                                                hr = pElement_select_childrens_collection->item(varIndex_select_answer,var_select_answer,&pDisp_select_answer);
                                                                if ( hr == S_OK )  
                                                                {
                                                                    hr = pDisp_select_answer->QueryInterface(IID_IHTMLElement,(void**)&pElement_select_answer);
                                                                    if (hr == S_OK)
                                                                    {
                                                                        BSTR pElement_answer_bstr;
                                                                        pElement_select_answer->get_innerHTML(&pElement_answer_bstr);
                                                                        CString cstr_pElement_answer = (CString)pElement_answer_bstr;
                                                                        pElement_select_answer->get_style(&select_style);
                                                                        if (res1 != "" && cstr_pElement_answer.Find(res1) != -1)
                                                                        {
                                                                            select_style->put_color(CComVariant("#FF0000"));
                                                                        }
                                                                        if (res2 != "" && cstr_pElement_answer.Find(res2) !=-1)
                                                                        {
                                                                            select_style->put_color(CComVariant("#FF0000"));
                                                                        }
                                                                        if (res3 != "" && cstr_pElement_answer.Find(res3) != -1)
                                                                        {
                                                                            select_style->put_color(CComVariant("#FF0000"));
                                                                        }
                                                                        if (res4 != "" && cstr_pElement_answer.Find(res4) != -1)
                                                                        {
                                                                            select_style->put_color(CComVariant("#FF0000"));
                                                                        }
                                                                    }//hr = pDisp_select_answer->QueryInterface
                                                                    else{return;}
                                                                }//hr = pElement_select_childrens_collection->item
                                                                else{return;}
                                                            }//for
                                                        }//hr = pElement_select_childrens_collection->get_length
                                                        else{return;}
                                                    }//hr = pDisp_select_children->QueryInterface
                                                    else{return;}
                                                }//hr = pElement_select->get_children
                                                else{return;}
                                            }//hr = pDis_select->QueryInterface
                                            else{return;}
                                            select_style->Release();
                                            pElement_select_answer->Release();
                                            pDisp_select_answer->Release();
                                            pElement_select_childrens_collection->Release();
                                            pDisp_select_children->Release();
                                            pElement_select->Release();
                                        }//hr = pmainQuestionContent_children->item select
                                        else{return;}
                                    }//if (cstr_mainQuestionContent_children_element.Find(problem) != -1)
                                }//while
                                i_mainQuestionContent_children += 3;//单选题,多选题,每题三个div
                            }
                            else if (cstr_mainQuestionContent_children_element.Find((CString)"判断题") != -1)
                            {
                                POSITION pos = record_list.GetHeadPosition();   
                                int irecordlen = record_list.GetSize();
                                int inowpos = 0;
                                while(pos != NULL)   
                                {  
                                    inowpos += 1;
                                    if (inowpos >= irecordlen)
                                    {
                                        break;
                                    }
                                    RecordClass * ptr = record_list.GetNext(pos);
                                    CString problem = ptr->problem;
                                    CString res1 = ptr->res1;
                                    CString res2 = ptr->res2;
                                    CString res3 = ptr->res3;
                                    CString res4 = ptr->res4;
                                    if (cstr_mainQuestionContent_children_element.Find(problem) != -1)
                                    {
                                        VARIANT varIndex_select, var_select;
                                        varIndex_select.vt = VT_UINT;  
                                        varIndex_select.lVal = i_mainQuestionContent_children_answer;  
                                        VariantInit(&var_select);  
                                        hr = pmainQuestionContent_children->item(varIndex_select,var_select,&pDis_select);
                                        if ( hr == S_OK )  
                                        {
                                            //select 声明
                                            IHTMLElement * pElement_select = NULL;
                                            IDispatch * pDisp_select_children = NULL;
                                            IHTMLElementCollection* pElement_select_childrens_collection = NULL;
                                            IDispatch * pDisp_select_answer = NULL;
                                            IHTMLElement * pElement_select_answer = NULL;
                                            IHTMLStyle * select_style = NULL;

                                            hr = pDis_select->QueryInterface(IID_IHTMLElement,(void**)&pElement_select);
                                            if ( hr == S_OK )  
                                            {
                                                hr = pElement_select->get_all(&pDisp_select_children);//判断用get_all
                                                if ( hr == S_OK )  
                                                {
                                                    hr = pDisp_select_children->QueryInterface(IID_IHTMLElementCollection,(void**)&pElement_select_childrens_collection);
                                                    if(hr == S_OK)
                                                    {
                                                        long select_childrens_collection_length;  
                                                        hr = pElement_select_childrens_collection->get_length(&select_childrens_collection_length);
                                                        if( hr == S_OK )  
                                                        {
                                                            VARIANT varIndex_select_answer, var_select_answer;
                                                            for ( int i_select_childrens = 0; i_select_childrens < select_childrens_collection_length; i_select_childrens++ )  
                                                            {  
                                                                varIndex_select_answer.vt = VT_UINT;  
                                                                varIndex_select_answer.lVal = i_select_childrens;  
                                                                VariantInit(&var_select_answer);  
                                                                hr = pElement_select_childrens_collection->item(varIndex_select_answer,var_select_answer,&pDisp_select_answer);
                                                                if ( hr == S_OK )  
                                                                {
                                                                    hr = pDisp_select_answer->QueryInterface(IID_IHTMLElement,(void**)&pElement_select_answer);
                                                                    if (hr == S_OK)
                                                                    {
                                                                        BSTR answer_label;
                                                                        pElement_select_answer->get_tagName(&answer_label);
                                                                        CString label_cstring = CString(answer_label);
                                                                        if ( label_cstring.CompareNoCase(_T("LABEL")) == 0 )  
                                                                        {  
                                                                            BSTR pElement_answer_bstr;
                                                                            pElement_select_answer->get_innerHTML(&pElement_answer_bstr);
                                                                            CString cstr_pElement_answer = (CString)pElement_answer_bstr;
                                                                            pElement_select_answer->get_style(&select_style);
                                                                            if (res1 != "" && cstr_pElement_answer.Find(res1) != -1)
                                                                            {
                                                                                select_style->put_color(CComVariant("#FF0000"));
                                                                            }
                                                                            if (res2 != "" && cstr_pElement_answer.Find(res2) !=-1)
                                                                            {
                                                                                select_style->put_color(CComVariant("#FF0000"));
                                                                            }
                                                                            if (res3 != "" && cstr_pElement_answer.Find(res3) != -1)
                                                                            {
                                                                                select_style->put_color(CComVariant("#FF0000"));
                                                                            }
                                                                            if (res4 != "" && cstr_pElement_answer.Find(res4) != -1)
                                                                            {
                                                                                select_style->put_color(CComVariant("#FF0000"));
                                                                            }
                                                                        }                                                                        
                                                                    }//hr = pDisp_select_answer->QueryInterface
                                                                    else{return;}
                                                                }//hr = pElement_select_childrens_collection->item
                                                                else{return;}
                                                            }//for
                                                        }//hr = pElement_select_childrens_collection->get_length
                                                        else{return;}
                                                    }//hr = pDisp_select_children->QueryInterface
                                                    else{return;}
                                                }//hr = pElement_select->get_children
                                                else{return;}
                                            }//hr = pDis_select->QueryInterface
                                            else{return;}
                                            select_style->Release();
                                            pElement_select_answer->Release();
                                            pDisp_select_answer->Release();
                                            pElement_select_childrens_collection->Release();
                                            pDisp_select_children->Release();
                                            pElement_select->Release();
                                        }//hr = pmainQuestionContent_children->item select
                                        else{return;}
                                    }//if (cstr_mainQuestionContent_children_element.Find(problem) != -1)
                                }//while
                                i_mainQuestionContent_children += 2;//判断题每题二个div
                            }else
                            {
                                return;//没有单选题,多选题,判断题,异常返回
                            }
                        }//hr = pDis_mainQuestionContent_children_item->QueryInterface
                        else{return;}
                    }//hr = pmainQuestionContent_children->item
                    else{return;}
                }//for
            }//hr = pmainQuestionContent_children->get_length
            else{return;}
         }// hr = pDisp->QueryInterface
         else{return;}
     }// hr = pElement_mainQuestionContent->get_children
     else{return;}
     pElement_mainQuestionContent->Release();
     pDis_select->Release();
     pmainQuestionContent_children_element->Release();
     pDis_mainQuestionContent_children_item->Release();
     pmainQuestionContent_children->Release();
     //循环pElement_mainQuestionContent的children document 对比显示答案结束
    
}
//旧的mainbody
//void CMFCAppxxDlg::mainbody(void)
//{
//    //MessageBox(TEXT("mainbody"));
//     if (ispost) { return; }
//     if ((flag_mainbody % 2) != 0) { flag_mainbody += 1; return; }
//     flag_mainbody += 1;
//     if (!ispass) { AfxMessageBox((CString)"该授权码已使用过"); return; }
//     CString doccodehref = m_webb.get_LocationURL();
//     if (doccodehref.Find((CString)"examId") != -1 && doccodehref.Find((CString)"userexamId") != -1 && doccodehref.Find((CString)"planexamId") != -1 && doccodehref.Find((CString)"planName") != -1 )
//    {
//
//    }
//    else
//    {
//        return;//URL中不含有上面的标志便返回
//    }//if else
//    //
//
//    //获取iframe 的 document 的相关代码开始
//     HRESULT hr;
//     IDispatch *pDisp = m_webb.get_Document();
//     IHTMLDocument2* pDocument = NULL;
//     IHTMLFramesCollection2 * pIframe_collection = NULL;
//     IHTMLWindow2 *pWin = NULL;    
//     IHTMLDocument2 *pDoc2=NULL;//iframe的document
//
//     pDisp->QueryInterface(IID_IHTMLDocument2,(void**)&pDocument);
//     hr = pDocument->get_frames(&pIframe_collection);
//     if(hr == S_OK)
//     {
//            VARIANT vFrame,vIndex;
//            vIndex.vt=VT_I4;
//            vIndex.lVal=0; //因为只有一个iframe,直接取第0个就行了。
//            pIframe_collection->item(&vIndex,&vFrame);
//            pWin=(IHTMLWindow2 *)vFrame.pdispVal;        
//            hr=pWin->get_document(&pDoc2);
//            if (hr != S_OK)
//            {
//                return;
//            }
//     }// hr = pDocument->get_frames
//     else{return;}
//     pWin->Release();
//     pIframe_collection->Release();
//     pDocument->Release();
//     pDisp->Release();
//     //获取iframe 的 document 的相关代码结束
//
//     //循环pDoc2(iframe的document)找出ID 为"mainQuestionContent"的document开始
//     IHTMLElementCollection* iframe_children_collention = NULL;
//     IHTMLElement *pElement_mainQuestionContent = NULL;
//
//     hr = pDoc2->get_all(&iframe_children_collention);
//     if( hr == S_OK )  
//     {
//        long iframe_children_collention_len;  
//        hr = iframe_children_collention->get_length(&iframe_children_collention_len);
//        if( hr == S_OK )
//        {
//            VARIANT varIndex, var;
//            for ( int i_childrens = 0; i_childrens < iframe_children_collention_len; i_childrens++ )  
//            {  
//                varIndex.vt = VT_UINT;  
//                varIndex.lVal = i_childrens;  
//                VariantInit(&var);  
//                hr = iframe_children_collention->item(varIndex,var,&pDisp);
//                if ( hr == S_OK )  
//                {
//                    hr = pDisp->QueryInterface(IID_IHTMLElement,(void**)&pElement_mainQuestionContent);
//                    if ( hr == S_OK )  
//                    {
//                        CString id;  
//                        BSTR bs;  
//                        pElement_mainQuestionContent->get_id(&bs);  
//                        id = CString(bs);  
//                        if ( id == _T("mainQuestionContent") )  
//                        {
//                            //BSTR html_mainquestioncontent;//这三句是打出题目的,方便录入
//                            //pElement_mainQuestionContent->get_innerHTML(&html_mainquestioncontent);
//                            //AfxMessageBox((CString)html_mainquestioncontent);
//                            //return;
//                            break;
//                        }
//                    }//hr = pDisp->QueryInterface
//                    else{return;}
//                }// hr = iframe_children_collention->item
//                else{return;}
//                if(i_childrens == (iframe_children_collention_len-1)){return;}//找不到mainQuestionContent则返回
//            }//for
//        }//hr = iframe_children_collention->get_length
//        else{return;}
//     }//hr = pDoc2->get_all
//     else{return;}
//     pDoc2->Release();
//     iframe_children_collention->Release();
//     pDisp->Release();
//     //循环pDoc2(iframe的document)找出ID 为"mainQuestionContent"的document结束
//     //循环pElement_mainQuestionContent的children document 对比显示答案开始
//     IHTMLElementCollection * pmainQuestionContent_children = NULL;
//     IDispatch * pDis_mainQuestionContent_children_item = NULL;
//     IHTMLElement *pmainQuestionContent_children_element = NULL;
//     IDispatch * pDis_select = NULL;
//    
//     hr = pElement_mainQuestionContent->get_children(&pDisp);
//     if( hr == S_OK )  
//     {  
//         hr = pDisp->QueryInterface(IID_IHTMLElementCollection,(void**)&pmainQuestionContent_children);
//         if(hr == S_OK)
//         {
//            long pmainQuestionContent_children_length;  
//            hr = pmainQuestionContent_children->get_length(&pmainQuestionContent_children_length);
//            if (hr == S_OK)
//            {
//                int i_mainQuestionContent_children_answer;
//                VARIANT varIndex, var;
//                for ( int i_mainQuestionContent_children = 0; i_mainQuestionContent_children < pmainQuestionContent_children_length;)
//                {
//                    i_mainQuestionContent_children_answer = i_mainQuestionContent_children + 1;
//                    varIndex.vt = VT_UINT;  
//                    varIndex.lVal = i_mainQuestionContent_children;  
//                    VariantInit(&var);  
//                    hr = pmainQuestionContent_children->item(varIndex,var,&pDis_mainQuestionContent_children_item);
//                    if ( hr == S_OK )  
//                    {
//                        hr = pDis_mainQuestionContent_children_item->QueryInterface(IID_IHTMLElement,(void**)&pmainQuestionContent_children_element);
//                        if ( hr == S_OK )  
//                        {  
//                            BSTR pmainQuestionContent_children_element_bstr;
//                            pmainQuestionContent_children_element->get_innerHTML(&pmainQuestionContent_children_element_bstr);
//                            CString cstr_mainQuestionContent_children_element = (CString)pmainQuestionContent_children_element_bstr;
//                        //    MessageBox(cstr_mainQuestionContent_children_element);
//                            if (cstr_mainQuestionContent_children_element.Find((CString)"单选题") != -1 || cstr_mainQuestionContent_children_element.Find((CString)"多选题")!= -1 )
//                            {
//                                POSITION pos = record_list.GetHeadPosition();   
//                                int irecordlen = record_list.GetSize();
//                                int inowpos = 0;
//                                while(pos != NULL)   
//                                {  
//                                    inowpos += 1;
//                                    if (inowpos >= irecordlen)
//                                    {
//                                        break;
//                                    }
//                                    RecordClass * ptr = record_list.GetNext(pos);
//                                    CString problem = ptr->problem;
//                                    CString res1 = ptr->res1;
//                                    CString res2 = ptr->res2;
//                                    CString res3 = ptr->res3;
//                                    CString res4 = ptr->res4;
//                                    if (cstr_mainQuestionContent_children_element.Find(problem) != -1)
//                                    {
//                                        VARIANT varIndex_select, var_select;
//                                        varIndex_select.vt = VT_UINT;  
//                                        varIndex_select.lVal = i_mainQuestionContent_children_answer;  
//                                        VariantInit(&var_select);  
//                                        hr = pmainQuestionContent_children->item(varIndex_select,var_select,&pDis_select);
//                                        if ( hr == S_OK )  
//                                        {
//                                            //select 声明
//                                            IHTMLElement * pElement_select = NULL;
//                                            IDispatch * pDisp_select_children = NULL;
//                                            IHTMLElementCollection* pElement_select_childrens_collection = NULL;
//                                            IDispatch * pDisp_select_answer = NULL;
//                                            IHTMLElement * pElement_select_answer = NULL;
//                                            IHTMLStyle * select_style = NULL;
//
//                                            hr = pDis_select->QueryInterface(IID_IHTMLElement,(void**)&pElement_select);
//                                            if ( hr == S_OK )  
//                                            {
//                                                hr = pElement_select->get_children(&pDisp_select_children);
//                                                if ( hr == S_OK )  
//                                                {
//                                                    hr = pDisp_select_children->QueryInterface(IID_IHTMLElementCollection,(void**)&pElement_select_childrens_collection);
//                                                    if(hr == S_OK)
//                                                    {
//                                                        long select_childrens_collection_length;  
//                                                        hr = pElement_select_childrens_collection->get_length(&select_childrens_collection_length);
//                                                        if( hr == S_OK )  
//                                                        {
//                                                            VARIANT varIndex_select_answer, var_select_answer;
//                                                            for ( int i_select_childrens = 0; i_select_childrens < select_childrens_collection_length; i_select_childrens++ )  
//                                                            {  
//                                                                varIndex_select_answer.vt = VT_UINT;  
//                                                                varIndex_select_answer.lVal = i_select_childrens;  
//                                                                VariantInit(&var_select_answer);  
//                                                                hr = pElement_select_childrens_collection->item(varIndex_select_answer,var_select_answer,&pDisp_select_answer);
//                                                                if ( hr == S_OK )  
//                                                                {
//                                                                    hr = pDisp_select_answer->QueryInterface(IID_IHTMLElement,(void**)&pElement_select_answer);
//                                                                    if (hr == S_OK)
//                                                                    {
//                                                                        BSTR pElement_answer_bstr;
//                                                                        pElement_select_answer->get_innerHTML(&pElement_answer_bstr);
//                                                                        CString cstr_pElement_answer = (CString)pElement_answer_bstr;
//                                                                        pElement_select_answer->get_style(&select_style);
//                                                                        if (res1 != "" && cstr_pElement_answer.Find(res1) != -1)
//                                                                        {
//                                                                            select_style->put_color(CComVariant("#FF0000"));
//                                                                        }
//                                                                        if (res2 != "" && cstr_pElement_answer.Find(res2) !=-1)
//                                                                        {
//                                                                            select_style->put_color(CComVariant("#FF0000"));
//                                                                        }
//                                                                        if (res3 != "" && cstr_pElement_answer.Find(res3) != -1)
//                                                                        {
//                                                                            select_style->put_color(CComVariant("#FF0000"));
//                                                                        }
//                                                                        if (res4 != "" && cstr_pElement_answer.Find(res4) != -1)
//                                                                        {
//                                                                            select_style->put_color(CComVariant("#FF0000"));
//                                                                        }
//                                                                    }//hr = pDisp_select_answer->QueryInterface
//                                                                    else{return;}
//                                                                }//hr = pElement_select_childrens_collection->item
//                                                                else{return;}
//                                                            }//for
//                                                        }//hr = pElement_select_childrens_collection->get_length
//                                                        else{return;}
//                                                    }//hr = pDisp_select_children->QueryInterface
//                                                    else{return;}
//                                                }//hr = pElement_select->get_children
//                                                else{return;}
//                                            }//hr = pDis_select->QueryInterface
//                                            else{return;}
//                                            select_style->Release();
//                                            pElement_select_answer->Release();
//                                            pDisp_select_answer->Release();
//                                            pElement_select_childrens_collection->Release();
//                                            pDisp_select_children->Release();
//                                            pElement_select->Release();
//                                        }//hr = pmainQuestionContent_children->item select
//                                        else{return;}
//                                    }//if (cstr_mainQuestionContent_children_element.Find(problem) != -1)
//                                }//while
//                                i_mainQuestionContent_children += 3;//单选题,多选题,每题三个div
//                            }
//                            else if (cstr_mainQuestionContent_children_element.Find((CString)"判断题") != -1)
//                            {
//                                POSITION pos = record_list.GetHeadPosition();
//                                int irecordlen = record_list.GetSize();
//                                int inowpos = 0;
//                                while(pos != NULL)   
//                                {  
//                                    inowpos += 1;
//                                    if (inowpos >= irecordlen)
//                                    {
//                                        break;
//                                    }
//                                    RecordClass * ptr = record_list.GetNext(pos);
//                                    CString problem = ptr->problem;
//                                    CString res1 = ptr->res1;
//                                    CString res2 = ptr->res2;
//                                    CString res3 = ptr->res3;
//                                    CString res4 = ptr->res4;
//                                    if (cstr_mainQuestionContent_children_element.Find(problem) != -1)
//                                    {
//                                        VARIANT varIndex_select, var_select;
//                                        varIndex_select.vt = VT_UINT;  
//                                        varIndex_select.lVal = i_mainQuestionContent_children_answer;  
//                                        VariantInit(&var_select);  
//                                        hr = pmainQuestionContent_children->item(varIndex_select,var_select,&pDis_select);
//                                        if ( hr == S_OK )  
//                                        {
//                                            //select 声明
//                                            IHTMLElement * pElement_select = NULL;
//                                            IDispatch * pDisp_select_children = NULL;
//                                            IHTMLElementCollection* pElement_select_childrens_collection = NULL;
//                                            IDispatch * pDisp_select_answer = NULL;
//                                            IHTMLElement * pElement_select_answer = NULL;
//                                            IHTMLStyle * select_style = NULL;
//
//                                            hr = pDis_select->QueryInterface(IID_IHTMLElement,(void**)&pElement_select);
//                                            if ( hr == S_OK )  
//                                            {
//                                                hr = pElement_select->get_all(&pDisp_select_children);//判断用get_all
//                                                if ( hr == S_OK )  
//                                                {
//                                                    hr = pDisp_select_children->QueryInterface(IID_IHTMLElementCollection,(void**)&pElement_select_childrens_collection);
//                                                    if(hr == S_OK)
//                                                    {
//                                                        long select_childrens_collection_length;  
//                                                        hr = pElement_select_childrens_collection->get_length(&select_childrens_collection_length);
//                                                        if( hr == S_OK )  
//                                                        {
//                                                            VARIANT varIndex_select_answer, var_select_answer;
//                                                            for ( int i_select_childrens = 0; i_select_childrens < select_childrens_collection_length; i_select_childrens++ )  
//                                                            {  
//                                                                varIndex_select_answer.vt = VT_UINT;  
//                                                                varIndex_select_answer.lVal = i_select_childrens;  
//                                                                VariantInit(&var_select_answer);  
//                                                                hr = pElement_select_childrens_collection->item(varIndex_select_answer,var_select_answer,&pDisp_select_answer);
//                                                                if ( hr == S_OK )  
//                                                                {
//                                                                    hr = pDisp_select_answer->QueryInterface(IID_IHTMLElement,(void**)&pElement_select_answer);
//                                                                    if (hr == S_OK)
//                                                                    {
//                                                                        BSTR answer_label;
//                                                                        pElement_select_answer->get_tagName(&answer_label);
//                                                                        CString label_cstring = CString(answer_label);
//                                                                        if ( label_cstring.CompareNoCase(_T("LABEL")) == 0 )  
//                                                                        {  
//                                                                            BSTR pElement_answer_bstr;
//                                                                            pElement_select_answer->get_innerHTML(&pElement_answer_bstr);
//                                                                            CString cstr_pElement_answer = (CString)pElement_answer_bstr;
//                                                                            pElement_select_answer->get_style(&select_style);
//                                                                            if (res1 != "" && cstr_pElement_answer.Find(res1) != -1)
//                                                                            {
//                                                                                select_style->put_color(CComVariant("#FF0000"));
//                                                                            }
//                                                                            if (res2 != "" && cstr_pElement_answer.Find(res2) !=-1)
//                                                                            {
//                                                                                select_style->put_color(CComVariant("#FF0000"));
//                                                                            }
//                                                                            if (res3 != "" && cstr_pElement_answer.Find(res3) != -1)
//                                                                            {
//                                                                                select_style->put_color(CComVariant("#FF0000"));
//                                                                            }
//                                                                            if (res4 != "" && cstr_pElement_answer.Find(res4) != -1)
//                                                                            {
//                                                                                select_style->put_color(CComVariant("#FF0000"));
//                                                                            }
//                                                                        }                                                                        
//                                                                    }//hr = pDisp_select_answer->QueryInterface
//                                                                    else{return;}
//                                                                }//hr = pElement_select_childrens_collection->item
//                                                                else{return;}
//                                                            }//for
//                                                        }//hr = pElement_select_childrens_collection->get_length
//                                                        else{return;}
//                                                    }//hr = pDisp_select_children->QueryInterface
//                                                    else{return;}
//                                                }//hr = pElement_select->get_children
//                                                else{return;}
//                                            }//hr = pDis_select->QueryInterface
//                                            else{return;}
//                                            select_style->Release();
//                                            pElement_select_answer->Release();
//                                            pDisp_select_answer->Release();
//                                            pElement_select_childrens_collection->Release();
//                                            pDisp_select_children->Release();
//                                            pElement_select->Release();
//                                        }//hr = pmainQuestionContent_children->item select
//                                        else{return;}
//                                    }//if (cstr_mainQuestionContent_children_element.Find(problem) != -1)
//                                }//while
//                                i_mainQuestionContent_children += 2;//判断题每题二个div
//                            }else
//                            {
//                                return;//没有单选题,多选题,判断题,异常返回
//                            }
//                        }//hr = pDis_mainQuestionContent_children_item->QueryInterface
//                        else{return;}
//                    }//hr = pmainQuestionContent_children->item
//                    else{return;}
//                }//for
//            }//hr = pmainQuestionContent_children->get_length
//            else{return;}
//         }// hr = pDisp->QueryInterface
//         else{return;}
//     }// hr = pElement_mainQuestionContent->get_children
//     else{return;}
//     pElement_mainQuestionContent->Release();
//     pDis_select->Release();
//     pmainQuestionContent_children_element->Release();
//     pDis_mainQuestionContent_children_item->Release();
//     pmainQuestionContent_children->Release();
//     //循环pElement_mainQuestionContent的children document 对比显示答案结束
//        
//}


HBRUSH CMFCAppxxDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
    HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);

    // TODO:  在此更改 DC 的任何特性
    if(pWnd->GetDlgCtrlID()==2)
    {
         pDC->SetBkColor(RGB(255,255,255));
        HBRUSH brush = CreateSolidBrush(RGB(255,255,255));
        return brush;
    }
    //switch(pWnd->GetDlgCtrlID())   
    //{   
    //case 2:   
    pDC->SetBkMode(TRANSPARENT);
    //pDC->SetBkColor(RGB(255,255,255));
    pDC->SetTextColor(RGB(0,0,0));
    //return (HBRUSH)GetStockObject(HOLLOW_BRUSH);   
    //default:   
    //break;   
    //}   

    // TODO:  如果默认的不是所需画笔,则返回另一个画笔
    return hbr;
}


void CMFCAppxxDlg::StatusTextChangeCexplorer1(LPCTSTR Text)
{
    // TODO: 在此处添加消息处理程序代码
        CRect rect;
        statictext.GetWindowRect(&rect);
        ScreenToClient(&rect);
        InvalidateRect(&rect);
        if (CString("完成").Find(Text) != -1)
        {
            statictext.SetWindowTextW(TEXT(""));
        }
        else
        {
            statictext.SetWindowTextW(Text);
        }        
}

    /********************************************************
    * 方法名称: PreTranslateMessage(MSG *pMsg)
    * 描述: 该方法主要是处理传递消息的,任何消息产生的消息都会经过这个方法处理,
    * 然后,消息才会到达相应的应用程序中。
    * 调用模块:CDialogEx::PreTranslateMessage(pMsg)父类的对应方法  
    * 输入: MSG类型的消息对象指针
    * 输出: 无
    * 返回值: bool值
    *********************************************************/  
BOOL CMFCAppxxDlg::PreTranslateMessage(MSG* pMsg)  
    {  
        // TODO: Add your specialized code here and/or call the base class  
        // 把Esc和Enter按键事件消息过滤掉,否则该消息会导致对应应用程序调用OnOK()方法,结束应用程序  
        if (pMsg->message == WM_KEYDOWN)  
        {  
            switch(pMsg->wParam)  
            {  
                case VK_ESCAPE: //Esc按键事件  
                    return true;  
                //case VK_RETURN: //Enter按键事件  
                //    return true;  
                default:  
                    ;  
            }  
        }  
          
        return CDialogEx::PreTranslateMessage(pMsg);  
    }  



void CMFCAppxxDlg::OnBnClickedButton1()
{
    // TODO: 在此添加控件通知处理程序代码
    
    //m_learnbutton.EnableWindow(false);
    learning = false;
    if(!ispass)
    {
        AfxMessageBox(TEXT("授权无效!"));
        return;
    }
     CString doccodehref = m_webb.get_LocationURL();
     if (doccodehref.Find((CString)"chinahrt") != -1 && doccodehref.Find((CString)"pages") != -1 && doccodehref.Find((CString)"launch_gxzj") != -1)
     {
         learning = true;
         learnlistpage = doccodehref;
         learnfunction();
     }
     else
     {
         AfxMessageBox(TEXT("此按钮进入课程列表中后点击有效!"));
         learning = false;
         return;
     }
    
}


void CMFCAppxxDlg::learnfunction(void)
{
    //iframe
      IDispatch *pDisp =NULL;
    // LPDISPATCH lpDisp_iframe = NULL;
     // Get the IDispatch of the document.
        //
        IHTMLDocument2* lpDocument1 = NULL;
        IHTMLDocument2* lpDocument2 = NULL;
        HRESULT hr;
        LPDISPATCH lpDisp = NULL;
        lpDisp = m_webb.get_Document();

        if (lpDisp)
        {
           IOleContainer* pContainer;
           // Get the container.
           //
           hr = lpDisp->QueryInterface(IID_IOleContainer,(void**)&pContainer);
           if (FAILED(hr)){return;}
           lpDisp->Release();

           // Get an enumerator for the frames.
           //
           IEnumUnknown* pEnumerator;

           hr = pContainer->EnumObjects(OLECONTF_EMBEDDINGS, &pEnumerator);
           if (FAILED(hr)){return;}
           pContainer->Release();

           IUnknown* pUnk;
           ULONG uFetched;
           int flag = 0;
           // Enumerate and refresh all the frames.
           //
           for (UINT i = 0; S_OK == pEnumerator->Next(1, &pUnk, &uFetched); i++)
           {
               if(flag == 4){break;}
              // QI for IWebBrowser here to see whether we have
              // an embedded browser.
              IWebBrowser2* pWebBrowser;

              hr = pUnk->QueryInterface(IID_IWebBrowser2, (void**)&pWebBrowser);
              pUnk->Release();

              if (SUCCEEDED(hr))
              {

                      LPDISPATCH lpDisp_web = NULL;
                      pWebBrowser->get_Document(&lpDisp_web);
                      lpDisp_web->QueryInterface(IID_IHTMLDocument2, (PVOID*)&lpDocument1);
                      lpDisp_web->Release();
                      flag += 1;

              }
           }

           pEnumerator->Release();
        }
        //IHTMLElement * pBody1;
        //    BSTR html1;//存放html源代码
        //    lpDocument1->get_body(&pBody1);
        //    pBody1->get_innerHTML(&html1);
        //    MessageBox((CString)html1);
     //iframe
    //循环lpDocument1(iframe的document)找出tr的document开始
     IHTMLElementCollection* tr_collention = NULL;
     IHTMLElement *pElement_tr = NULL;

     hr = lpDocument1->get_all(&tr_collention);
     if( hr == S_OK )  
     {
        long tr_collention_len;  
        hr = tr_collention->get_length(&tr_collention_len);
        if( hr == S_OK )
        {
            VARIANT varIndex, var;
            for ( int i_childrens = 0; i_childrens < tr_collention_len; i_childrens++ )  
            {  
                varIndex.vt = VT_UINT;  
                varIndex.lVal = i_childrens;  
                VariantInit(&var);  
                hr = tr_collention->item(varIndex,var,&pDisp);
                if ( hr == S_OK )  
                {
                    hr = pDisp->QueryInterface(IID_IHTMLElement,(void**)&pElement_tr);
                    if ( hr == S_OK )  
                    {
                        CString tag;  
                        BSTR bs;  
                        pElement_tr->get_tagName(&bs);  
                        tag = CString(bs);  
                        if ( tag == _T("tr") || tag == _T("TR"))  
                        {
                            BSTR tr_element_bstr;
                            pElement_tr->get_innerHTML(&tr_element_bstr);
                            CString cstr_tr_element = (CString)tr_element_bstr;
                            //MessageBox(cstr_tr_element);
                            if(cstr_tr_element.Find((CString)"已学完") == -1 && (cstr_tr_element.Find((CString)"正在学") != -1 || cstr_tr_element.Find((CString)"未学习") != -1))
                            {
                                break;
                            }
                            
                        }
                    }//hr = pDisp->QueryInterface
                    else{return;}
                }// hr = iframe_children_collention->item
                else{return;}
                if(i_childrens == (tr_collention_len-1))
                {
                    m_learnbutton.EnableWindow(true);
                    learning = false;
                    AfxMessageBox(TEXT("已经全部学完"));
                    return;
                }//找不到没学的则返回
            }//for
        }//hr = iframe_children_collention->get_length
        else{return;}
     }//hr = pDoc2->get_all
     else{return;}
     tr_collention->Release();
     pDisp->Release();
     //循环lpDocument1(iframe的document)找出tr的document结束
     //获取a标签并点击
     IDispatch * pDis_a_element_item = NULL;
     IHTMLElement * a_element = NULL;
     IHTMLElementCollection *pElement_a_collection = NULL;
     pElement_tr->get_all(&pDisp);
     pDisp->QueryInterface(IID_IHTMLElementCollection,(void**)&pElement_a_collection);
     VARIANT varIndex, var;
     varIndex.vt = VT_UINT;  
    varIndex.lVal = 4;  
    VariantInit(&var);
    hr = pElement_a_collection->item(varIndex,var,&pDis_a_element_item);
    if ( hr == S_OK )
    {
        hr = pDis_a_element_item->QueryInterface(IID_IHTMLElement,(void**)&a_element);
        if ( hr == S_OK )
        {
            a_element->click();
            from_list_page = true;
        }
    }
}

void CMFCAppxxDlg::learnThreadFunction(void)
{
    //自动学习开始
    /*IDispatch *lpDispatch =NULL;
    lpDispatch = m_webb.get_Document();  
    IHTMLDocument2* lpDocument2;
    HRESULT hr;
    hr = lpDispatch->QueryInterface(IID_IHTMLDocument2, (PVOID*)&lpDocument2);
    IHTMLWindow2* pIHTMLWindow = NULL;
    lpDocument2->get_parentWindow(&pIHTMLWindow);
    if (pIHTMLWindow)
    {
        CString js_str = TEXT("ajaxCompleted();");
        VARIANT pvarRet;
        pIHTMLWindow->execScript(CComBSTR(js_str), CComBSTR("JavaScript"), &pvarRet);
        pIHTMLWindow->Release();
    }   */  
    //自动学习结束
    /*m_learnthiscourse.EnableWindow(false);
    m_learnbutton.EnableWindow(true);
    from_list_page = false;
    m_webb.Navigate(firspage,NULL,NULL,NULL,NULL);*/
    
}

void CMFCAppxxDlg::OnBnClickedButton2()
{
    // TODO: 在此添加控件通知处理程序代码
    if(!ispass)
    {
        AfxMessageBox(TEXT("授权无效!"));
        return;
    }
    CString doccodehref = m_webb.get_LocationURL();
    if (doccodehref.Find((CString)"chinahrt") != -1 && doccodehref.Find((CString)"pages") != -1 && doccodehref.Find((CString)"launch_gxzj") != -1)
     {
        learnThreadFunction();
        MessageBox(TEXT("本课已学习完毕。可以学下一课了。你也可以直接在课程列表页(你点击播放时进入本网页的那个网页)点击\"在视频列表快速学习\"来快速学习"));
     }
     else
     {
         AfxMessageBox(TEXT("此按钮进入课程播放页中后点击有效!"));
         return;
     }
    }


void CMFCAppxxDlg::OnBnClickedButton4()
{
    // TODO: 在此添加控件通知处理程序代码
}



void CMFCAppxxDlg::DownloadCompleteCexplorer1()
{
    // TODO: 在此处添加消息处理程序代码
    if(!from_list_page){return;}
    CString doccodehref = m_webb.get_LocationURL();
     //自动学习开始
     if (learning)
     {
        if (doccodehref.Find((CString)"chinahrt") != -1 && doccodehref.Find((CString)"pages") != -1 && doccodehref.Find((CString)"launch_gxzj") != -1 && doccodehref.Find((CString)"entityId") != -1 && doccodehref.Find((CString)"student") != -1 && (doccodehref.Find((CString)"index") != -1 || doccodehref.Find((CString)"plan") != -1) && (doccodehref.Find((CString)"SESIONID") != -1 || doccodehref.Find((CString)"planId") != -1) && doccodehref.Find((CString)"courseId") != -1)
         {
            learnThreadFunction();
         }
         else
         {
            // AfxMessageBox(TEXT("此按钮进入课程列表中后点击有效!"));
             return;
         }
     }
    
     //自动学习结束
}

//点击首页的链接,跳到课程列表页
void CMFCAppxxDlg::clickfirstpagetolistpage(void)
{
    IDispatch *pDisp=NULL;
    IHTMLElementCollection * a_collection =NULL;
    IHTMLDocument2* pDocument = NULL;
    HRESULT hr;
    LPDISPATCH lpDisp = NULL;
    IHTMLElement * pElement_a =NULL;
    lpDisp = m_webb.get_Document();
    lpDisp->QueryInterface(IID_IHTMLDocument2,(void**)&pDocument);
    hr = pDocument->get_links(&a_collection);
    if(hr == S_OK)
    {
        long a_collection_len;  
        hr = a_collection->get_length(&a_collection_len);
        if( hr == S_OK )
        {
            VARIANT varIndex, var;
            for ( int i_childrens = 0; i_childrens < a_collection_len; i_childrens++ )  
            {  
                varIndex.vt = VT_UINT;  
                varIndex.lVal = i_childrens;  
                VariantInit(&var);  
                hr = a_collection->item(varIndex,var,&pDisp);
                if ( hr == S_OK )  
                {
                    hr = pDisp->QueryInterface(IID_IHTMLElement,(void**)&pElement_a);
                    if ( hr == S_OK )  
                    {
                        CString str_a_html;
                        BSTR a_innerhtml;
                        pElement_a->get_innerHTML(&a_innerhtml);
                        str_a_html = CString(a_innerhtml);  
                        if ( str_a_html.Find((CString)"信息技术与信息安全") != -1 || str_a_html.Find((CString)"低碳") != -1)  
                        {
                            //AfxMessageBox(a_innerhtml);
                            break;
                        }
                    }else{return;}
                }else{return;}
            }//for
        }else{return;}
    }else{return;}
    pElement_a->click();
    pElement_a->Release();
    lpDisp->Release();
    pDocument->Release();
    a_collection->Release();
    pDisp->Release();
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值