📄 readstatus.cpp
字号:
// ReadStatus.cpp: implementation of the ReadStatus class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "MFCStatus.h"
#include "ReadStatus.h"
#include "MFCStatusDlg.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
// ATL defined structure for defining the parameter data of the callback.
// In this case there are two prameters.
_ATL_FUNC_INFO ReadAlertInfo = {CC_STDCALL, VT_EMPTY, 2, {VT_I4,VT_I4}};
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
ReadStatus::ReadStatus(void *winPtr)
{
// We could have passed in just the specific data needed, to make this
// more generic, but passing in the window pointer makes it look more
// like the MFCStatusMT application it is a copy of.
CMFCStatusDlg *workIt = (CMFCStatusDlg *) winPtr;
m_hDialog = workIt->m_hWnd; // window handle for messages
m_stat.CreateInstance(BOXBRIDGELib::CLSID_Status);// start up COM Interface
HRESULT hr = DispEventAdvise((IUnknown*)m_stat);
m_stat->PutnStatusWaitRate(7); // Minimum time between status events
m_stat->PutnBPS(workIt->m_BPS); // Set BPS
m_stat->PutnPort(workIt->m_Port); // Set Port
m_stat->PutbstrIP(workIt->m_IP.AllocSysString()); // Set IP Address
m_stat->PutnBus(workIt->m_BusType?1:0); // Set Bus, checked(true) is ISA, else PCI
m_stat->Connect(workIt->m_Transport,workIt->m_CardNbr);// Connect to Transport
if(!m_stat->GetisOffline()){
m_Msgid = m_stat->AddACRCustom(_T("P6916")); // Start the status queue - p6916 is the ACR global clock
}
}
ReadStatus::~ReadStatus()
{
if(m_stat){
m_stat->DelStatus(m_Msgid);
DispEventUnadvise((IUnknown*)m_stat);
m_stat->Disconnect();
m_stat = NULL; // Setting smart pointers to NULL is *VERY IMPORTANT*
}
}
void __stdcall ReadStatus::ReadAlert(long msg, long err)
{
// Init SafeArray Stuff
SAFEARRAY* pSA;
long lBound = 0;
CComVariant vItem; // The CComVariant is found in the atlbase.h include file
CComVariant status; // it will clean up SAFEARRAY when it goes out of scope.
if(m_Msgid == msg){ // only process desired event
status = m_stat->GetStatus(msg);
if(status.vt & VT_ARRAY){
pSA = status.parray;
SafeArrayGetElement(pSA, &lBound, &vItem);
if(vItem.vt!=VT_EMPTY)
// Either Send or Post message can be used.
//::SendMessage(workIt->m_hDialog,WMU_UpdateClock,0,vItem.lVal);
::PostMessage(m_hDialog,WMU_UpdateClock,0,vItem.lVal);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -