📄 apithread.cpp
字号:
// ApiThread.cpp : implementation file
//
#include "stdafx.h"
#include "AtlasMsg.h"
#include "ApiThread.h"
HANDLE CApiThread::m_hEventThreadKilled;
HANDLE CApiThread::m_hEventThreadCreated;
HANDLE CApiThread::m_hEventProtocol;
BOOL bReadSmartMedia;
extern int iUsbBlockSize;
/////////////////////////////////////////////////////////////////////////////
// CApiThread
IMPLEMENT_DYNCREATE(CApiThread, CWinThread)
CApiThread::CApiThread()
{
m_iConnectType = 0;
}
CApiThread::~CApiThread()
{
}
void CApiThread::operator delete(void* p)
{
// The exiting main application thread waits for this event before completely
// terminating in order to avoid a false memory leak detection.
CWinThread::operator delete(p);
// OutputDebugString("ApiThread delete this\n");
SetEvent(m_hEventThreadKilled);
}
void CApiThread::PrepareEvent()
{
m_hEventThreadKilled = CreateEvent(NULL, FALSE, FALSE, NULL);
m_hEventThreadCreated = CreateEvent(NULL, FALSE, FALSE, NULL);
m_hEventProtocol = CreateEvent(NULL, FALSE, FALSE, NULL);
}
void CApiThread::UnprepareEvent()
{
CloseHandle(m_hEventThreadKilled);
CloseHandle(m_hEventThreadCreated);
CloseHandle(m_hEventProtocol);
}
BOOL CApiThread::InitInstance()
{
if (m_wndApi.Create() == FALSE)
return FALSE;
// It is important to set CWinThread::m_pMainWnd to the user interface
// window. This is required so that when the m_pMainWnd is destroyed,
// the CWinThread is also automatically destroyed. For insight into
// how the CWinThread is automatically destroyed when the m_pMainWnd
// window is destroyed, see the implementation of CWnd::OnNcDestroy
// in wincore.cpp of the MFC sources.
m_pMainWnd = &m_wndApi;
// OutputDebugString("ApiThread begin\n");
SetEvent(m_hEventThreadCreated);
return TRUE;
}
int CApiThread::ExitInstance()
{
// TODO: perform any per-thread cleanup here
// OutputDebugString("ApiThread end\n");
return CWinThread::ExitInstance();
}
BEGIN_MESSAGE_MAP(CApiThread, CWinThread)
//{{AFX_MSG_MAP(CApiThread)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
ON_MESSAGE(WM_API_CONNECT, OnConnect)
ON_MESSAGE(WM_API_DISCONNECT, OnDisconnect)
ON_MESSAGE(WM_API_COMMAND, OnCommand)
ON_MESSAGE(WM_API_DATA, OnData)
ON_MESSAGE(WM_API_DATA_RESPONSE, OnDataResponse)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CApiThread message handlers
void CApiThread::OnDisconnect(WPARAM, LPARAM)
{
// OutputDebugString("ApiThread disconnect message\n");
m_wndApi.Disconnect();
m_wndApi.DestroyWindow();
}
void CApiThread::OnConnect(WPARAM wParam, LPARAM lParam)
{
// OutputDebugString("ApiThread connect message\n");
m_iConnectType = (int)wParam;
m_wndApi.Connect(m_iConnectType, (int)lParam);
}
void CApiThread::OnCommand(WPARAM wParam, LPARAM lParam)
{
m_wndApi.SendCommand(wParam, lParam);
}
void CApiThread::OnData(WPARAM wParam, LPARAM lParam)
{
m_wndApi.SendData(wParam, lParam);
}
void CApiThread::OnDataResponse(WPARAM wParam, LPARAM lParam)
{
BOOL bAck = (BOOL)wParam;
BOOL bNeedMoreData = (BOOL)lParam;
if (bAck)
m_wndApi.SendAck();
else
m_wndApi.SendDc1();
}
/////////////////////////////////////////////////////////////////////////////
// CApiThread public communication functions
BOOL CApiThread::IsConnected()
{
return m_wndApi.IsConnected();
}
int CApiThread::GetDataValue()
{
return m_wndApi.GetDataValue();
}
BYTE * CApiThread::GetData(int & iLength)
{
iLength = m_wndApi.GetDataLength();
return m_wndApi.GetData();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -