2012年2月23日 星期四

[ VC(Visual C++) ]- GPS網路回報程式模組

[ VC(Visual C++) ]- GPS網路回報程式模組



本篇分享GPS網路回報程式模組有興趣的(C/P)同好歡迎來http://filemarkets.com/file/jashliao/495642b1/索取因為我不會上傳檔案分享哈哈 ^ ^












主要程式碼:



// IE_COMDlg.cpp : implementation file

//

 

#include "stdafx.h"

#include "IE_COM.h"

#include "IE_COMDlg.h"

#include<fstream.h>//7

#ifdef _DEBUG

#definenew DEBUG_NEW

#undef THIS_FILE

staticchar THIS_FILE[] = __FILE__;

#endif

 

/////////////////////////////////////////////////////////////////////////////

// CAboutDlg dialog used for App About

 

class CAboutDlg : public CDialog

{

public:

    CAboutDlg();

 

// Dialog Data

    //{{AFX_DATA(CAboutDlg)

    enum { IDD = IDD_ABOUTBOX };

    //}}AFX_DATA

 

    // ClassWizard generated virtual function overrides

    //{{AFX_VIRTUAL(CAboutDlg)

    protected:

    virtualvoid DoDataExchange(CDataExchange* pDX);    // DDX/DDV support

    //}}AFX_VIRTUAL

 

// Implementation

protected:

    //{{AFX_MSG(CAboutDlg)

    //}}AFX_MSG

    DECLARE_MESSAGE_MAP()

};

 

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)

{

    //{{AFX_DATA_INIT(CAboutDlg)

    //}}AFX_DATA_INIT

}

 

void CAboutDlg::DoDataExchange(CDataExchange* pDX)

{

    CDialog::DoDataExchange(pDX);

    //{{AFX_DATA_MAP(CAboutDlg)

    //}}AFX_DATA_MAP

}

 

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)

    //{{AFX_MSG_MAP(CAboutDlg)

        // No message handlers

    //}}AFX_MSG_MAP

END_MESSAGE_MAP()

 

/////////////////////////////////////////////////////////////////////////////

// CIE_COMDlg dialog

 

CIE_COMDlg::CIE_COMDlg(CWnd* pParent /*=NULL*/)

    : CDialog(CIE_COMDlg::IDD, pParent)

{

    //{{AFX_DATA_INIT(CIE_COMDlg)

        // NOTE: the ClassWizard will add member initialization here

    //}}AFX_DATA_INIT

    // Note that LoadIcon does not require a subsequent DestroyIcon in Win32

    m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

}

 

void CIE_COMDlg::DoDataExchange(CDataExchange* pDX)

{

    CDialog::DoDataExchange(pDX);

    //{{AFX_DATA_MAP(CIE_COMDlg)

    DDX_Control(pDX, IDC_EXPLORER1, m_ctrlWeb);

    //}}AFX_DATA_MAP

}

 

BEGIN_MESSAGE_MAP(CIE_COMDlg, CDialog)

    //{{AFX_MSG_MAP(CIE_COMDlg)

    ON_WM_SYSCOMMAND()

    ON_WM_PAINT()

    ON_WM_QUERYDRAGICON()

    //}}AFX_MSG_MAP

END_MESSAGE_MAP()

 

/////////////////////////////////////////////////////////////////////////////

// CIE_COMDlg message handlers

 

BOOL CIE_COMDlg::OnInitDialog()

{

    CDialog::OnInitDialog();

 

    // Add "About..." menu item to system menu.

 

    // IDM_ABOUTBOX must be in the system command range.

    ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);

    ASSERT(IDM_ABOUTBOX < 0xF000);

 

    CMenu* pSysMenu = GetSystemMenu(FALSE);

    if (pSysMenu != NULL)

    {

        CString strAboutMenu;

        strAboutMenu.LoadString(IDS_ABOUTBOX);

        if (!strAboutMenu.IsEmpty())

        {

            pSysMenu->AppendMenu(MF_SEPARATOR);

            pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);

        }

    }

 

    // Set the icon for this dialog.  The framework does this automatically

    //  when the application's main window is not a dialog

    SetIcon(m_hIcon, TRUE);            // Set big icon

    SetIcon(m_hIcon, FALSE);        // Set small icon

    

    // TODO: Add extra initialization here

    ///////////4_start

    //COleVariant vaUrl="http://office.tw-airnet.net/office/airnet_office_big5/webroot/emp_data/emp_online_log.php";

    COleVariant vaUrl="http://www.chtv.com.tw/testGPS/GPS_frm.htm";

    COleVariant vtMissing;

    m_ctrlWeb.Navigate2(&vaUrl,&vtMissing,&vtMissing,&vtMissing,&vtMissing); 

    ///////////4_end

    return TRUE;  // return TRUE  unless you set the focus to a control

}

 

void CIE_COMDlg::OnSysCommand(UINT nID, LPARAM lParam)

{

    if ((nID & 0xFFF0) == IDM_ABOUTBOX)

    {

        CAboutDlg dlgAbout;

        dlgAbout.DoModal();

    }

    else

    {

        CDialog::OnSysCommand(nID, lParam);

    }

}

 

// If you add a minimize button to your dialog, you will need the code below

//  to draw the icon.  For MFC applications using the document/view model,

//  this is automatically done for you by the framework.

 

void CIE_COMDlg::OnPaint() 

{

    if (IsIconic())

    {

        CPaintDC dc(this); // device context for painting

 

        SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

 

        // Center icon in client rectangle

        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;

 

        // Draw the icon

        dc.DrawIcon(x, y, m_hIcon);

    }

    else

    {

        CDialog::OnPaint();

    }

}

 

// The system calls this to obtain the cursor to display while the user drags

//  the minimized window.

HCURSOR CIE_COMDlg::OnQueryDragIcon()

{

    return (HCURSOR) m_hIcon;

}

 

BEGIN_EVENTSINK_MAP(CIE_COMDlg, CDialog)

    //{{AFX_EVENTSINK_MAP(CIE_COMDlg)

    ON_EVENT(CIE_COMDlg, IDC_EXPLORER1, 104 /* DownloadComplete */, OnDownloadCompleteExplorer1, VTS_NONE)

    //}}AFX_EVENTSINK_MAP

END_EVENTSINK_MAP()

 

void CIE_COMDlg::OnDownloadCompleteExplorer1()////3 

{

    // TODO: Add your control notification handler code here

    ////////////////////////6_start

    CString str[3];

    CTime time = CTime::GetCurrentTime();   ///構造CTime物件

    str[0] = time.Format("%Y-%m-%d %H:%M:%S");

    str[1] ="X_Data";

    str[2] ="Y_Data";

    IHTMLElementCollection *objAllElement=NULL;

    IHTMLDocument2 *objDocument=NULL;

    CString strUrl,strTemp;

    strUrl=m_ctrlWeb.GetLocationURL();//得到當前網頁的URL

    if(strUrl.IsEmpty())

        return;

    objDocument=(IHTMLDocument2 *)m_ctrlWeb.GetDocument(); //由控制項得到IHTMLDocument2介面指標

    objDocument->get_all(&objAllElement); //得到網頁所有元素的集合

    //由於所有頁面下載完後都會執行這個函數,所以必須根據URL判斷消息來源網頁

    //if(strUrl=="http://office.tw-airnet.net/office/airnet_office_big5/webroot/emp_data/emp_online_log.php") 

    if(strUrl=="http://www.chtv.com.tw/testGPS/GPS_frm.htm")

    {

        CComPtr<IDispatch>pDisp;

        if(HasItem(objAllElement,"GPSDatafrm")==true) //voteform為投票選項所在的Form

        {

            objAllElement->item(COleVariant("GPSDatafrm"),COleVariant((long)0),&pDisp);

            CComQIPtr<IHTMLFormElement , &IID_IHTMLFormElement >pElement; 

            if(pDisp==NULL)

            {

                //介面指標獲取失敗,結束程式,不另外作處理,原因見後

                EndDialog(IDOK);

                return;

            }

            PutIEText(objAllElement,"timeData",str[0]);

            PutIEText(objAllElement,"X_Data",str[2]);

            PutIEText(objAllElement,"Y_Data",str[1]);

            SubmitPage(objAllElement,"B1"); //提交網頁,votesubmit按鈕的idname

 

        }

    }

    ///////////////////////////////6_end

    Sleep(5000);

    this->OnOK();     

}

///////////////////////////5_start

bool CIE_COMDlg::HasItem(IHTMLElementCollection *pobjAllElement,CString strName)

{

    CComPtr<IDispatch>pDisp;

    pobjAllElement->item(COleVariant(strName),COleVariant((long)0),&pDisp);

    if(pDisp==NULL)

        returnfalse;

    else

        returntrue; 

}

void CIE_COMDlg::PutIEText(IHTMLElementCollection *pobjAllElement,CString strName,CString strText)

{

    CComPtr<IDispatch> pDisp; 

    pobjAllElement->item(COleVariant(strName),COleVariant((long)0),&pDisp); 

    CComQIPtr<IHTMLInputTextElement,&IID_IHTMLInputTextElement>pElement; 

    if(pDisp==NULL)

    {

        MessageBox(strName + "沒有找到!"); 

    }

    else

    {

        pElement=pDisp; 

        pElement->put_value(strText.AllocSysString()); 

    }

} 

void CIE_COMDlg::SubmitPage(IHTMLElementCollection *pobjAllElement,CString strName)

{

    CComPtr<IDispatch> pDisp; 

    pobjAllElement->item(COleVariant(strName),COleVariant((long)0),&pDisp); 

    CComQIPtr<IHTMLElement, &IID_IHTMLElement>pElement; 

    if(pDisp==NULL)

    {

        AfxMessageBox(strName + "沒有找到!"); 

    }

    else

    {

        pElement=pDisp;

        pElement->click();

    }

} 

void CIE_COMDlg::CheckItem(IHTMLElementCollection *pobjAllElement,CString strName)

{

    CComPtr<IDispatch> pDisp;

    pobjAllElement->item(COleVariant(strName),COleVariant((long)0),&pDisp);

    CComQIPtr<IHTMLElement, &IID_IHTMLElement>pElement;

    if(pDisp==NULL)

    {

        AfxMessageBox(strName + "沒有找到!");

    }

    else

    {

        pElement=pDisp;

        pElement->click();

    }

}

CString CIE_COMDlg::GetHidText(IHTMLElementCollection *pobjAllElement,CString strName)

{

    _bstr_t   bstText;   

    BSTR   bsText;

    CString str;

    CComPtr<IDispatch> pDisp;

    pobjAllElement->item(COleVariant(strName),COleVariant((long)0),&pDisp);

    CComQIPtr < IHTMLInputHiddenElement,&IID_IHTMLInputHiddenElement > pElement;

    if(pDisp==NULL)

    {

        AfxMessageBox(strName + "沒有找到!");

    }

    else

    {

        pElement=pDisp;

        pElement->get_value(&bsText);

        bstText=bsText;

        str=(LPCSTR)bstText;

    }

    return   str; 

}

void CIE_COMDlg::SelectItemValue(IHTMLElementCollection *pobjAllElement,CString strName,long number)

{

    CComPtr<IDispatch> pDisp;

    pobjAllElement->item(COleVariant(strName),COleVariant((long)0),&pDisp);

    CComQIPtr < IHTMLSelectElement,&IID_IHTMLSelectElement > pElement;

    if(pDisp==NULL)

    {

        AfxMessageBox(strName + "沒有找到!");

    }

    else

    {

        pElement=pDisp;

        pElement->put_selectedIndex(number);

    }

}

/////////////////////////5_end

 

 



 


沒有留言:

張貼留言