前端有一个仪器,仪器的CPU温度被检测器检测出来后,直接以数据包的形式(二进制)通过网线传给后面的PC主机.通讯采用TCP。检测器为TCP的服务器端。
检测器侦听端口:29011(channel 1) ; 29012 (channel 2) …我在PC上用VC建了一个控件,要求从前端传来的温度能在控件中实时显示.在下想请诸位大侠提供类似的VC源程序.

解决方案 »

  1.   

    这是一个大的源程序,包括"状态图示","网络连接","检测器类型",
    "视频输入类型",
    "视频输入状态",
    "视频略图",
    "CPU温度",
    "CPU占用率",
    "CPU风扇转速",
    "系统温度",
    "系统运行时间",
    "线程总数",
    "内存使用率",等方面.
    只要把显示温度部分剥离出来就行,谁可以做到?
      

  2.   

    #include "stdafx.h"
    #include "Monitor.h"
    #include <process.h>#include "MonitorDoc.h"
    #include "MonitorView.h"
    #include "regkey.h"
    #include "watchwnd.h"
    #include "mycell.h"
    #include "statusmycell.h"
    #include "socket.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif
    struct CHANNEL
    {
    int id;
    char ip[16];
    int cid;
    char name[17];
    int reserved; int  autoIncStorage;
    int  comfirmIncStorage;
    int  nonComfirmIncStorage;
    int  staticDataStorage;
    int  logDataStorage;
    };CHANNEL channel[1024];
    int channelCount = 0;void LoadChannel()
    {
    FILE* f = fopen("..\\etc\\channel.cfg","rb");
    if(f)
    {
    int n = fread(channel,1,sizeof(channel),f);
    fclose(f); channelCount = n/sizeof(CHANNEL);
    }
    }/////////////////////////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////
    int rcount = 12;CString rows[21] = {"状态图示",
    "网络连接",
    "检测器类型",
    "视频输入类型",
    "视频输入状态",
    "视频略图",
    "CPU温度",
    "CPU占用率",
    "CPU风扇转速",
    "系统温度",
    "系统运行时间",
    "线程总数",
    "内存使用率",
    "",
    "",
    "",
    "",
    "",
    "",
    "",
    ""
    };/////////////////////////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////
    struct MON_DAT
    {
    DWORD nNetworkStatus;
    DWORD nDetectorType;
    DWORD nVideoType;
    DWORD nVideoStatus;
    DWORD nCpuTemperature;
    DWORD nCpuTemperatureThreshold;
    DWORD nCpuUsed;
    DWORD nCpuFanSpeed;
    DWORD nCpuFanSpeedThreshold;
    DWORD nSystemTemperature;
    DWORD nSystemTemperatureThreshold;
    DWORD nSystemRunTime;
    DWORD nThreadCount;
    DWORD nMemoryUsed; DWORD nHasIncident; char  simage[96*72*3];
    };MON_DAT *mon_dat = NULL;CMonitorView* pView = NULL;BOOL bQuit = false;
      

  3.   

    void callback(CSock* pSock,int msg)
    {
    MON_DAT md;
    int len = pSock->Recv((char*)&md,sizeof(MON_DAT));
    if(len > 0)
    {
    memcpy(&mon_dat[msg],&md,sizeof(MON_DAT));
    mon_dat[msg].nNetworkStatus = 5;
    }
    }DWORD WINAPI CommThread(void* arg)
    {
    int ch = (int)arg; mon_dat[ch].nNetworkStatus = 0; CMySocket sock(false,0);
    sock.m_msg = ch;
    sock.SetCallBack(callback);

    while(!bQuit)
    {
    if(sock.GetValidLineCount() == 0)
    {
    if(sock.Connect(channel[ch].ip,10001+channel[ch].cid) == false)
    {
    Sleep(300);
    continue;
    }
    else
    {
    }
    } Sleep(1000); sock.Lock();
    if(sock.GetValidLineCount() > 0)
    {
    CSock* pSock = sock.GetLineByIndex(0);
    DWORD a[4] = {0x10000001,0x10000001,0x1000001,0x7ffffffe};
    sock.SendData(pSock,(char*)a,16);
    }
    sock.Unlock();
    }
    return 0;
    }/////////////////////////////////////////////////////////////////////////////
    /////////////////////////////////////////////////////////////////////////////
    // CMonitorViewIMPLEMENT_DYNCREATE(CMonitorView, CView)BEGIN_MESSAGE_MAP(CMonitorView, CView)
    //{{AFX_MSG_MAP(CMonitorView)
    ON_WM_CREATE()
    ON_WM_DESTROY()
    ON_WM_SIZE()
    ON_COMMAND(ID_SHOWGRID, OnShowgrid)
    ON_COMMAND(ID_SHOWWATCHGRID, OnShowwatchgrid)
    ON_COMMAND(ID_SHOWNAME, OnShowname)
    ON_UPDATE_COMMAND_UI(ID_SHOWNAME, OnUpdateShowname)
    ON_COMMAND(ID_SHOWIP, OnShowip)
    ON_UPDATE_COMMAND_UI(ID_SHOWIP, OnUpdateShowip)
    ON_UPDATE_COMMAND_UI(ID_SHOWWATCHGRID, OnUpdateShowwatchgrid)
    ON_UPDATE_COMMAND_UI(ID_SHOWGRID, OnUpdateShowgrid)
    ON_WM_TIMER()
    ON_MESSAGE(WM_CELLDBLCLK,OnCellDblClk)
    ON_WM_RBUTTONUP() ON_COMMAND(ID_RUNCONFIG,OnRunConfig)
    ON_COMMAND(ID_RUNVIEW,OnRunView)
    ON_COMMAND(ID_RUNINC,OnRunInc)
    ON_COMMAND(ID_RUNSTA,OnRunSta)
    ON_COMMAND(ID_RUNLOG,OnRunLog)
    ON_COMMAND(ID_STARTUSERRECORD,OnStartUserRecord)
    ON_COMMAND(ID_STOPUSERRECORD,OnStopUserRecord) //}}AFX_MSG_MAP
    // Standard printing commands
    ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
    ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
    ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // CMonitorView construction/destructionCMonitorView::CMonitorView()
    {
    m_bShowName = true;
    m_bShowAll = true;
    pView = this; m_nSelChannel = -1;
    }CMonitorView::~CMonitorView()
    {
    }BOOL CMonitorView::PreCreateWindow(CREATESTRUCT& cs)
    {
    // TODO: Modify the Window class or styles here by modifying
    //  the CREATESTRUCT cs return CView::PreCreateWindow(cs);
    }/////////////////////////////////////////////////////////////////////////////
    // CMonitorView drawingvoid CMonitorView::OnDraw(CDC* pDC)
    {
    }/////////////////////////////////////////////////////////////////////////////
    // CMonitorView printingBOOL CMonitorView::OnPreparePrinting(CPrintInfo* pInfo)
    {
    // default preparation
    return DoPreparePrinting(pInfo);
    }void CMonitorView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
    {
    // TODO: add extra initialization before printing
    }void CMonitorView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
    {
    // TODO: add cleanup after printing
    }/////////////////////////////////////////////////////////////////////////////
    // CMonitorView diagnostics#ifdef _DEBUG
    void CMonitorView::AssertValid() const
    {
    CView::AssertValid();
    }void CMonitorView::Dump(CDumpContext& dc) const
    {
    CView::Dump(dc);
    }CMonitorDoc* CMonitorView::GetDocument() // non-debug version is inline
    {
    ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMonitorDoc)));
    return (CMonitorDoc*)m_pDocument;
    }
    #endif //_DEBUG/////////////////////////////////////////////////////////////////////////////
    // CMonitorView message handlersint CMonitorView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
    {
    if (CView::OnCreate(lpCreateStruct) == -1)
    return -1;

    LoadChannel();

    CRect rect;
    GetClientRect(&rect); m_grid.Create(rect,this,1000);
    m_watchGrid.Create(rect,this,1001);
    m_watchGrid.ShowWindow(SW_HIDE); m_grid.SetRowCount(1+21);
    m_grid.SetColumnCount(1+channelCount); m_grid.SetFixedBkColor(0x00a0a080);
    m_grid.SetFixedRowCount(1);
    m_grid.SetFixedColumnCount(1);
    m_grid.SetRowHeight(0,50);
    m_grid.SetFixedTextColor(0x0000ffff);
    m_grid.SetColumnWidth(0,122);
    for(int i=0;i<channelCount;i++)
    {
    m_grid.SetItemText(0,i+1,channel[i].name);
    m_grid.SetColumnWidth(i+1,120);
    m_grid.SetItemData(0,i+1,0x10000000 | i);
    }
    for(i=0;i<21;i++)
    {
    m_grid.SetItemText(i+1,0,rows[i]);
    if(i == 5)
    {
    m_grid.SetRowHeight(i+1,92);
    }
    else
    if(i == 0)
    {
    m_grid.SetRowHeight(i+1,60);
    }
    else
    {
    m_grid.SetRowHeight(i+1,50);
    }

    m_grid.SetItemFormat(i+1,0,DT_RIGHT|DT_VCENTER|DT_SINGLELINE|DT_NOPREFIX);
    } for(i=0;i<21;i++)
    {
    for(int j=0;j<channelCount;j++)
    {
    m_grid.SetItemBkColour(i+1,j+1,0x00c0c080);
    if(i == 5)
    {
    m_grid.SetCellType(i+1,j+1,RUNTIME_CLASS(CMyCell));
    m_grid.SetItemData(i+1,j+1,0x20000000 | j);
    }
    else
    if(i == 0)
    {
    m_grid.SetCellType(i+1,j+1,RUNTIME_CLASS(CStatusCell));
    //m_grid.SetItemData(i+1,j+1,0x20000000 | j);
    }
    }
    } mon_dat = new MON_DAT[channelCount];
    memset(mon_dat,0,channelCount*sizeof(MON_DAT)); for(i=0;i<channelCount;i++)
    {
    DWORD id;
    ::CreateThread(NULL,0,CommThread,(void*)i,0,&id);
    } SetTimer(1,1000,NULL); return 0;
    }void CMonitorView::OnDestroy() 
    {
    bQuit = true;
    Sleep(2000); delete mon_dat; CView::OnDestroy();
    }void CMonitorView::OnSize(UINT nType, int cx, int cy) 
    {
    CView::OnSize(nType, cx, cy);

    m_grid.SetWindowPos(&wndTop,0,0,cx,cy,0);
    ResetWatchGrid();
    }