以前写的代码感觉很有用

以前写的代码感觉很有用,


// TestDlg.h : 头文件


#pragma once


#define  ANG(dradian)  (double((dradian)*180/M_PI)) 
typedef struct tagJWD
{
    double fLONG;//经度
    double fLAT;//纬度
    bool operator == (const tagJWD ob)
    {
        bool isok=false;
        if( abs(fLONG-ob.fLONG)<0.00001 && abs(fLAT-ob.fLAT)<0.00001)
        {
            isok=true;
        }
        return isok;
    }
}JWD;

typedef struct tagSITE
{
    vector<JWD> boundPoint;
    double minfLONG;
    double minfLAT;
    double maxfLONG;
    double maxfLAT;
    CString cityName;
}SITE;

//台站信息
class CSwStation
{
public:
    CSwStation()
    {
        nType = 2;
        strGUID = "";
        strStartTime = "";
        strStopTime = "";
        strEmisType = "";
        nBand = 0;
        nFreq = 0;
        nPow = -999;
        nLevel = -999;
        nOcc = nGate = -999;
        bGeneral = false;
        sApplycode = "";
        sDeclCode  = "";
        bExistFreq = false;
        bLocal     = true;
        nSendAnteHigh = 0;
        nBJIndication= -999;        //北京示向度
        nBJElevation= -999;     //北京仰角
        nHRBIndication= -999;       //哈尔滨示向度
        nHRBElevation= -999;        //哈尔滨仰角 
        nSHIndication= -999;        //上海示向度
        nSHElevation= -999;     //上海仰角  
        nCHDIndication= -999;       //成都示向度
        nCHDElevation= -999;        //成都仰角  
        nWLMQIndication= -999;  //乌鲁木齐示向度
        nWLMQElevation= -999;       //乌鲁木齐仰角    
        nSZIndication= -999;        //深圳示向度
        nSZElevation= -999;     //深圳仰角  
        nWYSIndication= -999;       //武夷山示向度
        nWYSElevation= -999;        //武夷山仰角 
        nXAIndication= -999;        //西安示向度
        nXAElevation= -999;     //西安仰角
        nKMIndication= -999;        //昆明示向度
        nKMElevation= -999;     //昆明仰角
        nAntPloa = -1;
        fantegaint = -999;
        dEmcField  = -999.f;
        dEmcStrength = -999.f;
    }

    ~CSwStation(){;}

    int             nType;              //数据源类型 0-ITU-HFBC 1-常规监测表 2-台站数据库  3-本地
    std::string     strGUID;
    __int64         nFreq;              //频率
    std::string     strMonitorDate;     //监测日期
    std::string     strStartTime;       //开始时间
    std::string     strStopTime;        //结束时间
    int             nLevel;             //电平值放大100倍
    std::string     strBRC;             //电台呼号
    std::string     strADM;             //主管部门
    std::string     strStationType;     //台站类别
    __int64         nBand;              //带宽(Hz)
    std::string     strEmisType;        //发射类别
    std::string     strLONGITYPE;       //经度类别(E/W)
    int             nLongi;             //经度(度)
    double          nLongifen;          //经度(分)
    std::string     strLATITYPE;        //纬度类别(N/S)
    int             nLati;              //纬度(度)
    double          nLatifen;           //纬度(分)         
    long            nPow;               //发射功率
    std::string     strModeType;        //调制类型
    std::string     strLANGUAGE;        //语言          
    int             nBJIndication;      //北京示向度
    int             nBJElevation;       //北京仰角
    int             nHRBIndication;     //哈尔滨示向度
    int             nHRBElevation;      //哈尔滨仰角 
    int             nSHIndication;      //上海示向度
    int             nSHElevation;       //上海仰角  
    int             nCHDIndication;     //成都示向度
    int             nCHDElevation;      //成都仰角  
    int             nWLMQIndication;    //乌鲁木齐示向度
    int             nWLMQElevation;     //乌鲁木齐仰角    
    int             nSZIndication;      //深圳示向度
    int             nSZElevation;       //深圳仰角  
    int             nWYSIndication;     //武夷山示向度
    int             nWYSElevation;      //武夷山仰角 
    int             nXAIndication;      //西安示向度
    int             nXAElevation;       //西安仰角
    int             nKMIndication;      //昆明示向度
    int             nKMElevation;       //昆明仰角
    std::string     strLOCATION;        //发射台具体位置 
    bool            bGeneral;           //是否常规监测表
    std::string     sApplycode   ;      //申请表编号
    std::string     sDeclCode   ;       //技术资料表编号
    bool            bExistFreq;         //频谱中存在该台站发射频率
    bool            bLocal;             //是否是本地数据
    int             nSendAnteHigh ;       //发射天线高度

    //本地数据源时使用
    double          fLongi       ;  //经度      
    double          fLati        ;  //纬度
    int             nOcc;         
    int             nGate;

    short   nAntPloa;        //极化方式
    float   fantegaint;      //天线增益
    double  dEmcField;       //该点到监测站的电平值
    double  dEmcStrength;    //场强值
};

typedef struct Parameter
{
    vector<CSwStation> m_stations;
    std::string     m_strStationID;           //监测站ID
    INT64 m_iFreq;
    INT64 m_iBandwide;
}Param;

// CTestDlg 对话框
class CTestDlg : public CDialog
{
// 构造
public:
    CTestDlg(CWnd* pParent = NULL); // 标准构造函数

// 对话框数据
    enum { IDD = IDD_TEST_DIALOG };

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


// 实现
protected:
    HICON m_hIcon;

    // 生成的消息映射函数
    virtual BOOL OnInitDialog();
    afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
    afx_msg void OnPaint();
    afx_msg HCURSOR OnQueryDragIcon();
    DECLARE_MESSAGE_MAP()
public:
    afx_msg void OnEnChangeEdit1();
    afx_msg void OnBnClickedOk();
    double GetAngle(JWD jwd1,JWD jwd2);
    SITE LoadXML();
    void  GetPathTwoways();
private:
    CEdit           m_fLong1;//台站1的经度
    CEdit           m_fLAT1;//台站1的经度
    CEdit           m_fLong2;//台站1的经度
    CEdit           m_fLAT2;//台站1的经度
    Param                   m_sParam;

public:
    afx_msg void OnBnClickedWiznext();
     void  isPointInPolygon(JWD testP,SITE site);
     bool  PointBeInPolygon(JWD testP,SITE site);
     void  FiltErrorPoint(/*vector<double> points*/);

     afx_msg void OnBnClickedButton1();
     void MFCReadTxt();
     void ReadTxt();
     void WriteTxt(CString ostr);
     CString PackageXML(INT64 lnFreq,INT64 bandwide,vector<CSwStation> queryStation);
     bool ParseXML(std::string strparam,std::string freq);


     void SetInInfo();
     void  CTimeToCString();
     __int64  SysTimeToInt(SYSTEMTIME systime );
     SYSTEMTIME Int64ToSystemTime(const __int64& itime);
     __int64 SystemTimeToInt64(const SYSTEMTIME& itime);
     bool  IsLeapYear(unsigned short wYear) ;

     SYSTEMTIME  SytemTimeAdd8Hour(SYSTEMTIME& st);
     void  EqualZero(std::string myreportV)  ;

     void  OnUnsigedLong();
     void PlayMp3();
     std::string  DecimalConversion(std::string decimal,int anglen);
     void UpperCase(char str[]);


};

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

#include "stdafx.h"
#include "Test.h"
#include "TestDlg.h"
#include <iostream>
#include <fstream>
#include "windows.h"
#pragma  comment(lib,"WinMM.Lib")
#include "mmsystem.h"
#include <string.h>
using namespace std;

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


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

class CAboutDlg : public CDialog
{
public:
    CAboutDlg();

// 对话框数据
    enum { IDD = IDD_ABOUTBOX };

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

// 实现
protected:
    DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}

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

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()


// CTestDlg 对话框




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

void CTestDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    DDX_Control(pDX, IDC_EDIT1, m_fLong1);
    DDX_Control(pDX, IDC_EDIT2, m_fLAT1);
    DDX_Control(pDX, IDC_EDIT4, m_fLong2);
    DDX_Control(pDX, IDC_EDIT5, m_fLAT2);
}

BEGIN_MESSAGE_MAP(CTestDlg, CDialog)
    ON_WM_SYSCOMMAND()
    ON_WM_PAINT()
    ON_WM_QUERYDRAGICON()
    //}}AFX_MSG_MAP
    ON_EN_CHANGE(IDC_EDIT1, &CTestDlg::OnEnChangeEdit1)
    ON_BN_CLICKED(IDOK, &CTestDlg::OnBnClickedOk)
    ON_BN_CLICKED(ID_WIZNEXT, &CTestDlg::OnBnClickedWiznext)
    ON_BN_CLICKED(IDC_BUTTON1, &CTestDlg::OnBnClickedButton1)
END_MESSAGE_MAP()


// CTestDlg 消息处理程序

BOOL CTestDlg::OnInitDialog()
{
    CDialog::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);        // 设置小图标

    // TODO: 在此添加额外的初始化代码

    return TRUE;  // 除非将焦点设置到控件,否则返回 TRUE
}

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

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

void CTestDlg::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
    {
        CDialog::OnPaint();
    }
}

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


void CTestDlg::OnEnChangeEdit1()
{
    // TODO:  If this is a RICHEDIT control, the control will not
    // send this notification unless you override the CDialog::OnInitDialog()
    // function and call CRichEditCtrl().SetEventMask()
    // with the ENM_CHANGE flag ORed into the mask.

    // TODO:  Add your control notification handler code here
}

void CTestDlg::OnBnClickedOk()
{

    JWD jwd1,jwd2;
    CString strValue;   
    m_fLong1.GetWindowText(strValue);   
    strValue.Trim();
    if (strValue.GetLength()==0)
    {
        MessageBox( _T("台站1经度不能为空"));       
    }
    jwd1.fLONG=_ttol(strValue);

    m_fLAT1.GetWindowText(strValue);    
    strValue.Trim();
    if (strValue.GetLength()==0)
    {
        MessageBox( _T("台站1纬度不能为空"));       
    }
    jwd1.fLAT=_ttol(strValue);

    m_fLong2.GetWindowText(strValue);   
    strValue.Trim();
    if (strValue.GetLength()==0)
    {
        MessageBox( _T("台站2经度不能为空"));       
    }
    jwd2.fLONG=_ttol(strValue);

    m_fLAT2.GetWindowText(strValue);    
    strValue.Trim();
    if (strValue.GetLength()==0)
    {
        MessageBox( _T("台站2纬度不能为空"));       
    }
    jwd2.fLAT=atof(strValue);


    double angle=GetAngle(jwd1,jwd2);
    CEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDIT_RESULT);

    CString temp;
    temp.Format("%f",angle);
    if(pEdit)
    {
        pEdit->SetWindowText(temp);
    }
//  OnOK();
}

double CTestDlg::GetAngle(JWD jwd1,JWD jwd2)
{ 
    double Rjd1,Rwd1,Rjd2,Rwd2,dAngle;
    Rjd1=jwd1.fLONG*M_PI/180;//计算弧度
    Rwd1=jwd1.fLAT*M_PI/180;
    Rjd2=jwd2.fLONG*M_PI/180;
    Rwd2=jwd2.fLAT*M_PI/180;

    dAngle=abs(ANG(atan((sin(Rjd2-Rjd1)*cos(Rwd2))/(sin(Rwd2)*cos(Rwd1)-cos(Rjd2-Rjd1)*cos(Rwd2)*sin(Rwd1)))));
    if(Rwd2>=Rwd1)
    {
        if(Rjd2<Rjd1)
            dAngle=360-dAngle;
    }
    else
    {
        if(Rjd2>=Rjd1)
            dAngle=180-dAngle;
        else
            dAngle=180+dAngle;
    }
    return dAngle;
}

void CTestDlg::OnBnClickedWiznext()
{
    //JWD testP;
    //CString strValue;  
    //m_fLong2.GetWindowText(strValue); 
    //strValue.Trim();
    //if (strValue.GetLength()==0)
    //{
    //  MessageBox( _T("台站2经度不能为空"));       
    //}
    //testP.fLONG=atof(strValue);

    //m_fLAT2.GetWindowText(strValue);  
    //strValue.Trim();
    //if (strValue.GetLength()==0)
    //{
    //  MessageBox( _T("台站2纬度不能为空"));       
    //}
    //testP.fLAT=atof(strValue);




}
//MFC方式读取并解析Txt文件
void CTestDlg::MFCReadTxt()
{
    //使用MFC封装的文件类读取txt文件,读取结果存于CString字符串中
    CString fileName="city.txt";    
    CFile file(fileName,CFile::modeRead);
    BYTE buffer[0x1000];
    DWORD dwBytesRemaining/*file.GetLength()*/;
    CString strBuffer,strTemp;
    UINT nBytesRead;

    int pos;
    while (dwBytesRemaining)
    {
        if (dwBytesRemaining>4096)
        {
            nBytesRead=file.Read(buffer,sizeof(buffer));        
            strTemp=buffer;
        }else
        {
            BYTE temBuffer[0x1000];
            nBytesRead=file.Read(temBuffer,sizeof(temBuffer));      
            strTemp=temBuffer;
        }       
        pos=strTemp.Find("烫");
        strTemp=strTemp.Left(pos);
        strBuffer+=strTemp;
        dwBytesRemaining=dwBytesRemaining-nBytesRead;
    }

    //解析CString字符串
    SITE site;
    JWD temp;
    vector<SITE> m_sites;

    while (strBuffer.Find(",")>=0&&strBuffer.Find(";")>=0)
    {
        pos=strBuffer.Find(" ");
        site.cityName=strBuffer.Left(pos);
        strBuffer=strBuffer.Right(strBuffer.GetLength()-pos-1);

        pos=strBuffer.Find("\n");
        strTemp=strBuffer.Left(pos);
        if (pos==-1)
        {
            strTemp=strBuffer;
        }
        strBuffer=strBuffer.Right(strBuffer.GetLength()-pos-1);

        site.minfLAT=100000;
        site.minfLONG=100000;
        site.maxfLAT=-100000;
        site.maxfLONG=-100000;

        while (strTemp.Find(",")>=0&&strTemp.Find(";")>=0)
        {
            pos=strTemp.Find(",");
            temp.fLONG=atof(strTemp.Left(pos));
            if (site.minfLONG>temp.fLONG)
            {
                site.minfLONG=temp.fLONG;
            }
            if (site.maxfLONG<temp.fLONG)
            {
                site.maxfLONG=temp.fLONG;
            }
            strTemp=strTemp.Right(strTemp.GetLength()-pos-1);
            pos=strTemp.Find(";");
            temp.fLAT=atof(strTemp.Left(pos));
            if (site.minfLAT>temp.fLAT)
            {
                site.minfLAT=temp.fLAT;
            }
            if (site.maxfLAT<temp.fLAT)
            {
                site.maxfLAT=temp.fLAT;
            }
            strTemp=strTemp.Right(strTemp.GetLength()-pos-1);           
            site.boundPoint.push_back(temp);
        }
        m_sites.push_back(site);
        site.boundPoint.clear();
    }

}
//C++保存Txt文件
void CTestDlg::GetPathTwoways()
{
    TCHAR exeFullPath[MAX_PATH]; // MAX_PATH
    GetCurrentDirectory(MAX_PATH,exeFullPath);
    CString lstr = exeFullPath;
    lstr +="\bool.txt";
    std::string strPath = lstr.GetBuffer();
    //采用C++文件流读取txt文件,将读取内容保存于CString字符串中
    ifstream file;
    file.open(strPath.c_str(),ios::in);



    CString path; 
    GetModuleFileName(NULL,path.GetBufferSetLength(MAX_PATH+1),MAX_PATH); 
    path.ReleaseBuffer(); 
    int pos2 = path.ReverseFind('\\'); 
    path = path.Left(pos2); 
    CString fileName="city.txt";
    path+="\\data\\"+fileName;
    ofstream ofs(path);
    bool mb=true;
    CString ostr;
    if (mb)
    {
      ostr="1;";
    }else{
     ostr="0;";
    }
    ofs.write(ostr,ostr.GetLength());
    ofs.close();

}

//C++读取并解析Txt文件
void CTestDlg::ReadTxt()
{   
    CString path; 
    //获得.exe所在路径**\**\a.exe
    GetModuleFileName(NULL,path.GetBufferSetLength(MAX_PATH+1),MAX_PATH); 
    path.ReleaseBuffer(); 
    int pos2 = path.ReverseFind('\\'); 
    path = path.Left(pos2); 
    CString fileName="city.txt";
    path+="\\data\\"+fileName;

    //采用C++文件流读取txt文件,将读取内容保存于CString字符串中
    ifstream file;
    file.open(path,ios::in);
    if(!file)
    {
        cout<<"open fail!"<<endl;
        return ;
    }   
    int pos;
    CString strBuffer,strTemp,res;
    while(!file.eof())
    {
        char buffer[4096];
        file.read(buffer,4096); 
        strTemp=buffer;
        pos=strTemp.Find("烫");
        strTemp=strTemp.Left(pos);
        strBuffer+=strTemp;
        res=strTemp;

    }
    file.close();

    //解析CString字符串
    SITE site;
    JWD temp;
    vector<SITE> m_sites;

    while (strBuffer.Find(",")>=0&&strBuffer.Find(";")>=0)
    {
        pos=strBuffer.Find(" ");
        site.cityName=strBuffer.Left(pos);
        strBuffer=strBuffer.Right(strBuffer.GetLength()-pos-1);

        pos=strBuffer.Find("\n");
        strTemp=strBuffer.Left(pos);
    /*  if (pos==-1)
        {
            strTemp=strBuffer;
        }*/
        strBuffer=strBuffer.Right(strBuffer.GetLength()-pos-1);

        site.minfLAT=100000;
        site.minfLONG=100000;
        site.maxfLAT=-100000;
        site.maxfLONG=-100000;

        while (strTemp.Find(",")>=0&&strTemp.Find(";")>=0)
        {
            pos=strTemp.Find(",");
            temp.fLONG=atof(strTemp.Left(pos));
            if (site.minfLONG>temp.fLONG)
            {
                site.minfLONG=temp.fLONG;
            }
            if (site.maxfLONG<temp.fLONG)
            {
                site.maxfLONG=temp.fLONG;
            }
            strTemp=strTemp.Right(strTemp.GetLength()-pos-1);
            pos=strTemp.Find(";");
            temp.fLAT=atof(strTemp.Left(pos));
            if (site.minfLAT>temp.fLAT)
            {
                site.minfLAT=temp.fLAT;
            }
            if (site.maxfLAT<temp.fLAT)
            {
                site.maxfLAT=temp.fLAT;
            }
            strTemp=strTemp.Right(strTemp.GetLength()-pos-1);           
            site.boundPoint.push_back(temp);
        }
        m_sites.push_back(site);
        site.boundPoint.clear();
    }

    CEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDIT_RESULT);

    std::string m_result=res;
    if(pEdit)
    {
        pEdit->SetWindowText(m_result.c_str());
    }
}
//封装XML字符串
CString CTestDlg::PackageXML(INT64 lnFreq,INT64 bandwide,vector<CSwStation> queryStation)
{
    //封装成XML
    CString strResult=_T("<?xml version=\"1.0\" encoding=\"gb2312\" ?>\n") ;
    CString strTemp;
    strTemp.Format("<root>\n");
    strResult+=strTemp;
    strTemp.Format("<base freq=%I64d bandwide=%I64d/>\n",lnFreq,bandwide);
    strResult+=strTemp;
    if (queryStation.size()>0)
    {
        std::vector<CSwStation> ::iterator iter;
        for (iter=queryStation.begin();iter!=queryStation.end();iter++)
        {
            strTemp.Format("<station sApplycode=%s sDeclCode=%s ",iter->sApplycode,iter->sDeclCode);
            strResult+=strTemp;
            strTemp.Format("strADM=%s strLOCATION=%s ",iter->strADM,iter->strLOCATION);
            strResult+=strTemp;
            strTemp.Format("fLongi=%lf fLati=%lf/>\n",iter->fLongi,iter->fLati);
            strResult+=strTemp;
        }
    }
    strTemp.Format("</root>\n");
    strResult+=strTemp;
    return strResult;
}
//解析XML格式的字符串
bool CTestDlg::ParseXML(std::string strparam,std::string freq)
{
    //解析XML格式字符串
    TiXmlDocument lxmlDoc;
    lxmlDoc.Parse(strparam.c_str());

    if(!lxmlDoc.Error())
    {
        TiXmlElement* pRoot = lxmlDoc.RootElement();
        if (pRoot != NULL)
        {
            CString ret;
            TiXmlElement* pFrame = pRoot->FirstChildElement("group");
            if (pFrame)
            {
                std::string mname;
                std::string mfreq;
                TiXmlElement* pItem=pFrame->FirstChildElement("item");
                while (pItem)
                {
                    mname=pItem->Attribute("name");
                    if (mname.compare("frequency")==0)
                    {
                        mfreq=pItem->Attribute("value");
                        int pos=mfreq.find("M");                            
                        mfreq=mfreq.substr(0,pos);

                        double m_nfreq=atof(mfreq.c_str());
                        CString mstrFreq;
                        mstrFreq.Format("%.4lf", m_nfreq);
                        mfreq=mstrFreq;

                        double nfreq = atof(freq.c_str());
                        CString strfreq;
                        strfreq.Format("%.4lf", nfreq);
                        freq=strfreq;

                        if (mfreq.compare(freq)==0)
                        {
                            return true;

                        }
                        std::string myinfo="频率不相等";

                    }
                    pItem=pItem->NextSiblingElement("item");
                }//pItem
            }//pFrame
        }//pRoot!=NULL
    }//!lxmlDoc.Error()
}
//从进程所在路径打开txt文件并写入数据
void CTestDlg::WriteTxt(CString ostr)
{
    TCHAR exeFullPath[MAX_PATH]; // MAX_PATH
    GetCurrentDirectory(MAX_PATH,exeFullPath);
    CString lstr = exeFullPath;
    lstr +="\\bool.txt";
    std::string strPath = lstr.GetBuffer();

    ofstream ofs(strPath.c_str());  
    ofs.write(ostr,ostr.GetLength());
    ofs.close();

}
//加载XML文件并解析
SITE CTestDlg::LoadXML()
{

    SITE site;

    //读入XML文件,解析并存入数据结构中
    TCHAR exeFullPath[MAX_PATH]; // MAX_PATH
    GetCurrentDirectory(MAX_PATH,exeFullPath);
    CString lstr = exeFullPath;
    lstr +="\\site.xml";
    std::string strPath = lstr.GetBuffer();
    TiXmlDocument doc;
    doc.LoadFile(strPath);
    TiXmlElement* pRoot = doc.RootElement();
    if (pRoot == NULL)
    {
        MessageBox("没有找到site.xml文件!");
        return site;
    }
    CString ret;
    TiXmlElement* pFrame = pRoot->FirstChildElement("min");
    if (pFrame)
    {
        CString tempValue;
        JWD tempJ;

        tempValue= pFrame->Attribute("minfLONG");
        site.minfLONG=atof(tempValue);
        tempValue= pFrame->Attribute("minfLAT");
        site.minfLAT=atof(tempValue);

        TiXmlElement* pMap = pFrame->NextSiblingElement("max");
        tempValue= pMap->Attribute("maxfLONG");
        site.maxfLONG=atof(tempValue);
        tempValue= pMap->Attribute("maxfLAT");
        site.maxfLAT=atof(tempValue);

        pMap = pMap->NextSiblingElement("jwd");
        while (pMap){           
            tempValue= pMap->Attribute("fLONG");        
            tempJ.fLONG=atof(tempValue);        
            tempValue= pMap->Attribute("fLAT");
            tempJ.fLAT=atof(tempValue);
            site.boundPoint.push_back(tempJ);
            pMap = pMap->NextSiblingElement("jwd");
        }
    }

    return site;
}
//算法一:判断点是否在多边形内    
 void CTestDlg:: isPointInPolygon(JWD testP,SITE site)
 {
     int count =site.boundPoint.size();

     if(count < 3)
     {
         return;
     }

     bool result = false;   
     int i=0;

     std::vector<JWD>::iterator iter,temp;
     vector<JWD> chosedP;
     JWD tjwd;

     temp=site.boundPoint.end();
     temp--;
     for (iter=site.boundPoint.begin();iter!=site.boundPoint.end();iter++)
     {
         //如果点在边界上,则判定该点不在该区域内
         if (iter->fLAT==testP.fLAT&&iter->fLONG==testP.fLONG)
            {
                result=false;
                break;
            }
         if((iter->fLAT <testP.fLAT && temp->fLAT > testP.fLAT )||(temp->fLAT < testP.fLAT && iter->fLAT > testP.fLAT))
            {
                cout<<""<<endl;
                double a1=(testP.fLAT -iter->fLAT)/(temp->fLAT -iter->fLAT)*(temp->fLONG-iter->fLONG);
                if(iter->fLONG+a1<testP.fLONG)
                {
                    i++;
                    tjwd.fLAT=iter->fLAT;
                    tjwd.fLONG=iter->fLONG;
                    chosedP.push_back(tjwd);
                    result =true;                   
                } 
         }          
         temp = iter;
     }

     CEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDIT_RESULT);

     if(pEdit)
     {
         if (result)
            {
                pEdit->SetWindowText("YES,在区域内……");
         }else
            {
                pEdit->SetWindowText("NO,该点不在区域内……");
         }      
     }

 }

//算法二:判断点是否在多边形内
 bool CTestDlg:: PointBeInPolygon(JWD testP,SITE site)
 {
     int count =site.boundPoint.size();

     if(count < 3)
     {
         return false;
     }

     bool result = false;   
     int i=0;
     std::vector<JWD>::iterator iter,temp,next;
     vector<JWD> chosedP;
    // JWD tjwd;

     //如果点在边界之外,直接退出
     if (testP.fLAT<site.minfLAT||testP.fLONG<site.minfLONG||testP.fLAT>site.maxfLAT||testP.fLONG>site.maxfLONG)
     {
         return false;
     }

     temp=site.boundPoint.end();
     temp--;
     for (iter=site.boundPoint.begin();iter!=site.boundPoint.end();iter++)
     {
         //如果点在边界上,则判定该点在该区域内
         if (iter->fLAT==testP.fLAT&&iter->fLONG==testP.fLONG)
            {
                return true;
            }
         if (testP.fLAT<min(iter->fLAT,temp->fLAT)||testP.fLAT>max(iter->fLAT,iter->fLAT))
         {
             temp=iter;
             continue;
         }
         if (testP.fLAT>=min(iter->fLAT,temp->fLAT)&&testP.fLAT<=max(iter->fLAT,iter->fLAT))
         {
            if (testP.fLONG<=max(iter->fLONG,temp->fLONG))
            {
                if (iter->fLAT==temp->fLAT&&testP.fLONG>=min(iter->fLONG,temp->fLONG))
                {
                    return true;
                }

                if (iter->fLONG==temp->fLONG)
                {
                    if (testP.fLONG==iter->fLONG)
                    {
                        return true;
                    }else{
                        ++i;
                    }
                }else{
                    double a2=(testP.fLAT-temp->fLAT)*(iter->fLONG-temp->fLONG)/(iter->fLAT-temp->fLAT)+temp->fLONG;
//                  if(abs(testP.fLONG-a2)<0.0000000002)
//                      return true;
                    if (testP.fLONG<a2)
                    {
                        /*++i;*/
                        return true;
                    }
                }
            }
         }else{
             if (testP.fLAT==iter->fLAT&&testP.fLONG<=iter->fLONG)
             {
                 next=iter;
                 next++;
                 if (testP.fLAT>=min(temp->fLAT,next->fLAT)&&testP.fLAT<=max(temp->fLAT,next->fLAT))
                 {
                     ++i;
                 }else{
                     i+=2;
                 }
             }
         }
         temp=iter;
     }
     if (i%2==0)
     { 
         return false;
     }else{
         return true;
     }   
 } 

//过滤偏差太大的误差点,Vector向量的用法。
void CTestDlg::FiltErrorPoint(/*vector<double> pointsit*/)
{

    //构造测试数据
    vector<double> pointsit,result;
    double a[3]={177.42,179.19,189.27};
    for (int i=0;i<3;i++)
    {
        pointsit.push_back(a[i]);
    } 

    //从小到大排列测向线
    sort(pointsit.begin(),pointsit.end());
    std::vector<double >::iterator tempB,iterB,iterEnd,iter;

    vector <int>::size_type len;
    len=pointsit.size();
    iterB=pointsit.begin();
    tempB=iterB;
    tempB++;
    iterEnd=pointsit.end();
    iterEnd--;

    double mean=(*iterEnd-*iterB)/len;
    bool delBeg;
    int m_count=0;

    for (;tempB!=pointsit.end();)
    {
        delBeg=false;       
        m_count++;

        double preV=*tempB-*iterB;
        if(preV>mean)
        {
            if (m_count*2>len)
            {
                tempB=pointsit.erase(tempB);
                if (tempB!=pointsit.end())
                {
                    iterB=tempB-1;
                }
            }else{
                iterB = pointsit.erase(iterB);
                tempB = iterB +1;
            }
            delBeg=true;
        }
        if (delBeg==false)
        {
            iterB++;
            tempB++;
        }
    }

    CEdit* pEdit = (CEdit*)GetDlgItem(IDC_EDIT_RESULT);
    CString strv;
    std::string str;    

    if(pEdit)
    {
        for (iter=pointsit.begin();iter!=pointsit.end();iter++)
        {
            UpdateData();   
            strv.Format("%d",*iter);
            str=strv;
            pEdit->SetWindowText(str.c_str());
        }
    }
}


void CTestDlg::SetInInfo()
{
    const std::string lstrIn="monitorId:37160001,freq:152225000,bandwide:25000;";
    CString strTemp,strParam;
    strParam=lstrIn.c_str();
    int pos;
    pos=strParam.Find("monitorId");
    pos=strParam.Find(":");
    strParam=strParam.Right(strParam.GetLength()-pos-1);
    pos=strParam.Find(",");
    m_sParam.m_strStationID=strParam.Left(pos);
    pos=strParam.Find(":");
    strParam=strParam.Right(strParam.GetLength()-pos-1);
    pos=strParam.Find(",");
    m_sParam.m_iFreq=static_cast<__int64>(atof(strParam.Left(pos))+0.5);
    pos=strParam.Find(":");
    strParam=strParam.Right(strParam.GetLength()-pos-1);
    pos=strParam.Find(";");
    m_sParam.m_iBandwide=static_cast<__int64>(atof(strParam.Left(pos))+0.5);
    CSwStation stations;
    while (strParam.Find("station:")>0)
    {
        pos=strParam.Find(":");
        strParam=strParam.Right(strParam.GetLength()-pos-1);
        pos=strParam.Find(",");     
        stations.sApplycode=strParam.Left(pos);
        strParam=strParam.Right(strParam.GetLength()-pos-1);
        pos=strParam.Find(",");     
        stations.sDeclCode=strParam.Left(pos);
        strParam=strParam.Right(strParam.GetLength()-pos-1);
        pos=strParam.Find(",");     
        stations.strADM=strParam.Left(pos);
        strParam=strParam.Right(strParam.GetLength()-pos-1);
        pos=strParam.Find(",");     
        stations.strLOCATION=strParam.Left(pos);
        strParam=strParam.Right(strParam.GetLength()-pos-1);
        pos=strParam.Find(",");     
        stations.fLongi=atof(strParam.Left(pos));
        strParam=strParam.Right(strParam.GetLength()-pos-1);
        pos=strParam.Find(";");     
        stations.fLati=atof(strParam.Left(pos));
        strParam=strParam.Right(strParam.GetLength()-pos-1);
        m_sParam.m_stations.push_back(stations);
    }
}

void CTestDlg::CTimeToCString()
{
    CTime   m_cTime = CTime::GetCurrentTime();

    CString cstrDateTime =m_cTime.Format("'%Y-%m-%d %H:%M:%S'");

    //这样得到的日期时间字符串就是以"2006-11-27 23:30:59"的格式.这是不是很方便呢?

    //取得CTime中的日期
    CString cstrDate = m_cTime.Format("%Y-%m-%d");

    //取得CTime中的时间
    CString cstrTime = m_cTime.Format("%H:%M:%S");

}
__int64 CTestDlg::SysTimeToInt(SYSTEMTIME systime )
{
    FILETIME ftStart;
    __int64 nStartTime(0);
    SystemTimeToFileTime(&systime, &ftStart);   
    nStartTime = ftStart.dwHighDateTime;
    nStartTime = nStartTime<<32;
    nStartTime += ftStart.dwLowDateTime;
    return nStartTime;
}
//是否为闰年
bool CTestDlg::IsLeapYear(unsigned short wYear)  
{
    if ((wYear%4==0&&wYear%100!=0)||wYear%400==0)
    {
        return true;
    }else{
        return false;
    }
}

SYSTEMTIME CTestDlg::SytemTimeAdd8Hour(SYSTEMTIME& st)  
{
    if (st.wHour+8<24)
    {
        st.wHour=st.wHour+8;
    } 
    else
    {
        st.wHour=st.wHour+8-24;

        switch(st.wMonth)
        {
        case 2:
            //判断是否为闰年
            if (IsLeapYear(st.wYear))
            {
                if (st.wDay+1<30)
                {
                    st.wDay=st.wDay+1;
                } 
                else
                {
                    st.wDay=1;
                    st.wMonth=st.wMonth+1;
                }
            } 
            else
            {
                if (st.wDay+1<29)
                {
                    st.wDay=st.wDay+1;
                } 
                else
                {
                    st.wDay=1;
                    st.wMonth=st.wMonth+1;
                }
            }
            break;
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
            if (st.wDay+1<32)
            {
                st.wDay=st.wDay+1;
            } 
            else
            {
                st.wDay=1;
                st.wMonth=st.wMonth+1;
            }
            break;
        case 12:
            if (st.wDay+1<32)
            {
                st.wDay=st.wDay+1;
            } 
            else
            {
                st.wDay=1;
                st.wMonth=1;
                st.wYear=st.wYear+1;
            }
            break;

        case 4:
        case 6:
        case 9:
        case 11:
            if (st.wDay+1<31)
            {
                st.wDay=st.wDay+1;
            } 
            else
            {
                st.wDay=1;
                st.wMonth=st.wMonth+1;
            }
            break;
        }
    }
    return st;
}


__int64 CTestDlg::SystemTimeToInt64(const SYSTEMTIME& itime)  
{  
    FILETIME ft;  
    SystemTimeToFileTime(&itime, &ft);  
    ULARGE_INTEGER ularge;  
    ularge.LowPart = ft.dwLowDateTime;  
    ularge.HighPart = ft.dwHighDateTime;  
    __int64 int64 = ularge.QuadPart;  
    return int64;  
}  

SYSTEMTIME CTestDlg::Int64ToSystemTime(const __int64& itime)  
{  
    FILETIME ft;  
    SYSTEMTIME st;  
    ULARGE_INTEGER ularge;  
    __int64 tmptimeA, tmptimeB;  
    tmptimeA = itime;  
    tmptimeB = itime;  
    ularge.HighPart = (DWORD)(tmptimeA>>32);  
    ularge.LowPart = (DWORD)((tmptimeB<<32)>>32);  
    ft.dwLowDateTime = ularge.LowPart;  
    ft.dwHighDateTime = ularge.HighPart;  
    FileTimeToSystemTime(&ft, &st); 

    return st;  
} 

void CTestDlg::EqualZero(std::string myreportV)  
{ 
    if (myreportV.empty())
    {
        myreportV ="0";
    }
}


void CTestDlg::OnUnsigedLong()
{
   DWORD a,b,d;
   a=9;
   b=10;
   double  c=(double)a/(double)b;
   d=0.8;
   if (c>0.8)
   {
      d=0.6;
   } 
   else
   {
      d=0.9;
   }
}

//经纬度小时换算为分秒,
std::string CTestDlg::DecimalConversion(std::string decimal,int anglen)
{
    std::string du,fen,miao;
    int len;
    double dnum;
    int pos;
    CString conStr;
    conStr=decimal.c_str();

    pos=conStr.Find(".");
    du=conStr.Left(pos);
    len=(int)strlen(du.c_str());
    while (len<anglen)
    {
        du="0"+du;
        len++;
    }

    conStr=conStr.Right(conStr.GetLength()-pos-1);
    conStr="0."+conStr;
    dnum=atof(conStr);
    dnum=dnum*60;
    conStr.Format("%.4lf",dnum);
    pos=conStr.Find(".");
    fen=conStr.Left(pos);
    len=(int)strlen(fen.c_str());
    while (len<2)
    {
        fen="0"+fen;
        len++;
    }

    conStr=conStr.Right(conStr.GetLength()-pos-1);
    conStr="0."+conStr;
    dnum=atof(conStr);
    dnum=dnum*60;
    conStr.Format("%.4lf",dnum);
    pos=conStr.Find(".");
    miao=conStr.Left(pos);
    len=(int)strlen(miao.c_str());
    while (len<2)
    {
        miao="0"+miao;
        len++;
    }

    conStr=conStr.Right(conStr.GetLength()-pos-1);
    CString tem=conStr.Left(2);
    miao+=tem;

    std::string res=du+fen+miao;
    return res;
}
void CTestDlg::UpperCase(char str[])
{
    //tes=4,数组作为参数时,传递的是首地址,本质上是一个指针
    int tes=sizeof(str);
    //tes1=5,strlen是计算字符串str的长度
    int tes1=strlen(str);

    int a[5];
    printf("%d\n", a);
    printf("%d\n", &a);
    printf("%d\n", a + 1);
    printf("%d\n", &a + 1);
    printf("%d\n", &a[0] + 1);
    printf("---------------\n");
    printf("%d\n",sizeof(a));
    printf("%d\n",sizeof(&a));

}
void CTestDlg::PlayMp3()
{
    MCI_OPEN_PARMS m_mciOpen;  //打开参数
    MCI_PLAY_PARMS m_mciPlay;  //播放参数

    //要操作的文件类型
    m_mciOpen.lpstrDeviceType ="mpegvideo" ; 
    //要操作的文件路径
    m_mciOpen.lpstrElementName ="F:\\工具类\\20170405频段扫描黑名单显示与声音提示\\Alarm.mp3" ;
    MCIERROR mcierror=mciSendCommand( 0,MCI_OPEN,MCI_OPEN_TYPE | MCI_OPEN_ELEMENT ,(DWORD)&m_mciOpen); //打开文件命令
    if(mcierror){
        char buf[128]={0};
        mciGetErrorString(mcierror, buf,128);
        ::MessageBox(NULL, buf, "错误", MB_OK|MB_ICONERROR);
    }else{
        m_mciPlay.dwCallback=NULL/*(DWORD)hwnd*/;
        m_mciPlay.dwFrom = (DWORD)(12 * 1); //播放起始位置ms为单位
        mciSendCommand(m_mciOpen.wDeviceID, MCI_PLAY, MCI_NOTIFY|MCI_FROM, (DWORD)(LPVOID)&m_mciPlay); 
    }

}
void CTestDlg::OnBnClickedButton1()
{
    char str[]="abced";
    UpperCase(str);






    //PlaySound("F:\\工具类\\20170405频段扫描黑名单显示与声音提示\\Alarm.wav", NULL, SND_FILENAME | SND_ASYNC);

}







这里写代码片
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

haimianjie2012

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值