// DatasShowDlg.cpp : 实现文件
//
?
#include "stdafx.h"
#include "DatasShow.h"
#include "DatasShowDlg.h"
#include "afxdialogex.h"
?
?
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
?
?
// CDatasShowDlg 对话框
char szbuffer[10][arrayBytes];
int recvcount;
bool m_run;
CRect* pictureWH = new CRect();
string msgLable;
string busNum;
?
CDatasShowDlg::CDatasShowDlg(CWnd* pParent /*=NULL*/)
???: CDialogEx(CDatasShowDlg::IDD, pParent)
???, m_msgLabelNum(_T(""))
???, m_busNumValue(_T(""))
{
???m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
?
void CDatasShowDlg::DoDataExchange(CDataExchange* pDX)
{
???CDialogEx::DoDataExchange(pDX);
???DDX_Control(pDX, IDOK, m_show);
???DDX_Control(pDX, IDC_EDIT1, m_msgLable);
???DDX_Control(pDX, IDC_EDIT2, m_busNum);
???//DDX_Control(pDX, IDC_PICTURE, m_picture);
???DDX_Text(pDX, IDC_EDIT1, m_msgLabelNum);
???DDX_Text(pDX, IDC_EDIT2, m_busNumValue);
}
?
BEGIN_MESSAGE_MAP(CDatasShowDlg, CDialogEx)
???ON_WM_PAINT()
???ON_WM_QUERYDRAGICON()
???ON_BN_CLICKED(IDOK, &CDatasShowDlg::OnBnClickedOk)
END_MESSAGE_MAP()
?
?
// CDatasShowDlg 消息处理程序
?
BOOL CDatasShowDlg::OnInitDialog()
{
???CDialogEx::OnInitDialog();
?
???// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
???// 执行此操作
???SetIcon(m_hIcon, TRUE); // 设置大图标
???SetIcon(m_hIcon, FALSE); // 设置小图标
?
???// TODO: 在此添加额外的初始化代码
???m_run = false;
???recvcount = 0;
???CRect rect;
???/*m_picture.GetWindowRect(rect);*/
?
???/*pictureWH = ▭ 下面的参数没什么卵用*/
???AfxBeginThread((AFX_THREADPROC)DealThread,(LPVOID)GetSafeHwnd(),THREAD_BASE_PRIORITY_IDLE);
???AfxBeginThread((AFX_THREADPROC)ReceiverThread,NULL,THREAD_BASE_PRIORITY_IDLE);
???//对edit控件赋值
???/*char label[20] = {0};
???char busnum[20] = {0};*/
???SetDlgItemText(IDC_EDIT1,"Path_GPS");
???SetDlgItemText(IDC_EDIT2,"1");
?
???return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
}
?
// 如果向对话框添加最小化按钮,则需要下面的代码
// 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
// 这将由框架自动完成。
?
?
DWORD WINAPI DealThread(LPVOID pParam)
{
?
???//CRect* rect = (CRect*)pParam;
???while(1)
???{
??????if (m_run)
????{
??????unsigned char str1[arrayBytes] = {0}; //获取数据
??????//开辟两个无符号类型,这里是加了锁机制处理,string 默认并不是无符号类型
?
??????for (int i = 0; i < arrayBytes; ++i)
??????{
?????????str1[i] = szbuffer[(recvcount-1+10)%10][i];
??????}
??????Matrix *matrixH = new Matrix(); //记得释放
??????memset(matrixH,0,sizeof(Matrix));
??????matrixH->Num = str1[3]*16*16*16*16*16*16*16*16 + str1[2]*16*16*16*16 + str1[1]*16*16 + str1[0];
??????int obs1 = 0;
??????for (int i = 0; i < matrixH->Num; ++i)
??????{
?????????matrixH->point[obs1].x = str1[startoffset + 1 + i*PointLength]*16*16 + str1[startoffset + 0 + i*PointLength];
?????????matrixH->point[obs1].y = str1[startoffset + 3 + i*PointLength]*16*16 + str1[startoffset + 2 + i*PointLength];
?????????matrixH->point[obs1].value = str1[startoffset + 4 + i*PointLength];
?????????//matrixH->point[obs1].value = 50;
?????????matrixH->point[obs1].U = str1[startoffset + 5 + i*PointLength];
?????????obs1++; //注意清零
??????}
??????DrawPoints(matrixH,pParam);
?
?
??????delete matrixH;
??????}//end if
??????else
??????{
?????????Sleep(1);
??????}
???}
?
?
???return 0;
}
?
void DrawPoints(Matrix *marix,LPVOID pParam)
{
???//HWND hWnd = (HWND)pParam;
???CRect rect;
????AfxGetApp()->m_pMainWnd->GetWindowRect(rect);
???int PicW = rect.Width();
???int PicH = rect.Height() - 145;
???//曲线轮廓显示
???//以下是画在主线程中,我们需要画在picture控件中
???CDC* pDC = AfxGetApp()->m_pMainWnd->GetDC(); //通过GetDc()获取的HDC直接与相关设备沟通, CDC* pDC = picture.GetDC();
?
???CDC memDC;
???CBitmap bmp; //本函数创建的DC,则是与内存中的一个表,面相关联。
???memDC.CreateCompatibleDC(pDC); //该函数创建一个与指定设备兼容的内存设备上下文环境(DC)。
???bmp.CreateCompatibleBitmap( pDC, PicW, PicH); //该函数创建与指定的设备环境相关的设备兼容的位图
???memDC.SelectObject(bmp); //该函数选择一对象到指定的设备上下文环境中,该新对象替换先前的相同类型的对象
?
???memDC.SelectStockObject(WHITE_BRUSH);//该语句把终端字体选入设备环境
???memDC.SelectStockObject(WHITE_PEN);
?
???pDC->SelectStockObject(WHITE_BRUSH);
???pDC->SelectStockObject(WHITE_PEN);
?
???int yGap = 10;
???memDC.Ellipse( PicW/2-5, PicH-yGap-5, PicW/2+5, PicH-yGap+5); //小圆形,用来标识雷达
?
???int n = 0;
???int m = 0;
???for (int i = 0; i < marix->Num; ++i)
???{
??????n = marix->point[i].x;
??????m = marix->point[i].y;
??????if ((n > 0 && n < 350) && (m > 0 && m < 100))
??????{
?????????n = n * PicH / 400;
?????????m = m * PicW / 100;
?????????memDC.SetPixel(m, n,RGB(255,255,255));
?????????//memDC.Ellipse( m-5, n-yGap-5, m+5, n-yGap+5); //小圆形,用来标识雷达
??????}
???}
?
???pDC->StretchBlt(0,0,PicH,PicH,&memDC,0,0,PicH,PicH,SRCCOPY); //函数从源矩形中复制一个位图到目标矩形
???bmp.DeleteObject(); //必要时按目标设备设置的模式进行图像的拉伸或压缩
?
???/*目标区域左上角点的x坐标
????目标区域左上角点的y坐标
???目标区域的宽度
???目标区域的高度
???源贴图区域DC的指针
???源贴图区域x坐标
???源贴图区域y坐标
???像素直接拷贝模式*/
???memDC.DeleteDC();
???AfxGetApp()->m_pMainWnd->ReleaseDC(pDC);
???Sleep(50);
}
?
DWORD WINAPI ReceiverThread(LPVOID pParam)
{
???VirtualSwitchPlusRecv *vspR;
???while(1) //等待用户输入
????{
??????if (m_run)
?????{
???????int BUSNUM = busNum[0] - ‘0‘;
????????vspR = new VirtualSwitchPlusRecv(BUSNUM);
???????break;
??????}
??????else
??????{
?????????Sleep(1);
????????}
?????}
?
?
???while (true)
???{
???????vspR->SubMsg(msgLable); //数据必须这样接收,每次判断一次
??????for (int i = 0; i < 3000; ++i)
??????{
?????????szbuffer[recvcount][i] = vspR->szbuffer[i];
??????}
??????int nRet = vspR->nRet;
?
??????if (nRet == SOCKET_ERROR)
??????{
?????????cout << "Path_GPS not receive!" << endl;
??????}
??????if(nRet > 0) //主程序需要循环检测
??????{
?????????cout << "flag0: "<<recvcount<<endl;
?????????recvcount = (recvcount + 1) % 10;
??????}else{
?????????recvcount = 0;
??????}
???}
???delete vspR;
}
?
void CDatasShowDlg::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 CDatasShowDlg::OnQueryDragIcon()
{
???return static_cast<HCURSOR>(m_hIcon);
}
?
?
?
void CDatasShowDlg::OnBnClickedOk()
{
???// TODO: 在此添加控件通知处理程序代码
???if (!m_run){
??????m_show.SetWindowText(_T("暂停"));
??????m_run = true;
??????char label[20] = {0};
??????char busnum[20] = {0};
??????GetDlgItemText(IDC_EDIT1,label,20);
??????GetDlgItemText(IDC_EDIT2,busnum,20);
?
??????busNum = busnum[0];
??????for (int i = 0; i < 20; ++i)
??????{
?????????if (label[i] != 0)
?????????{
????????????msgLable += label[i];
?????????}
??????}
???}else{
??????m_show.SetWindowText(_T("显示"));
??????m_run = false;
???}
?
}