// ThreadTrace.cpp: implementation of the CThreadTrace class.
//
//////////////////////////////////////////////////////////////////////
/** \file ThreadTrace.cpp
* \brief基本描述.
* 详细描述,详细描述,详细描述,详细描述,
* 详细描述,详细描述,详细描述,详细描述.
*/
#include "stdafx.h"
#include "ThreadTrace.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CThreadTrace::CThreadTrace()
{
//#ifdef _DEBUG
// WinExec("CopyRecv.exe",SW_HIDE);
InitializeCriticalSection(&m_CritSec);
m_sStrToSend = "Thread Tracer!";
memset(&cds, 0, sizeof(cds));
cds.dwData = ACTION_DISPLAY_TEXT;
cds.cbData = m_sStrToSend.GetLength() + 1; //
cds.lpData = (LPVOID)(LPCTSTR)m_sStrToSend;
pDisplayWnd = CWnd::FindWindow(NULL, szDisplayAppName);
ClearWindows();
//#endif
}
CThreadTrace::~CThreadTrace()
{
//#ifdef _DEBUG
DeleteCriticalSection(&m_CritSec);
//#endif
}
void CThreadTrace::SendToServer(LPCTSTR str)
{
//#ifdef _DEBUG
EnterCriticalSection(&m_CritSec);
m_sStrToSend = str;
memset(&cds, 0, sizeof(cds));
cds.dwData = ACTION_DISPLAY_TEXT;
cds.cbData = m_sStrToSend.GetLength() + 1; // +1 for the NULL
cds.lpData = (LPVOID)(LPCTSTR)m_sStrToSend;
if (pDisplayWnd)
{
pDisplayWnd->SendMessage(WM_COPYDATA,(WPARAM)0, (LPARAM)&cds);
}
LeaveCriticalSection(&m_CritSec);
//#endif
}
void CThreadTrace::SendToServer(char *fmt, ...)
{
//#ifdef _DEBUG
EnterCriticalSection(&m_CritSec);
char s[300];
va_list argptr;
int cnt;
va_start(argptr, fmt);
cnt = vsprintf(s, fmt, argptr);
va_end(argptr);
m_sStrToSend.Format("%s",s);
memset(&cds, 0, sizeof(cds));
cds.dwData = ACTION_DISPLAY_TEXT;
cds.cbData = m_sStrToSend.GetLength() + 1; // +1 for the NULL
cds.lpData = (LPVOID)(LPCTSTR)m_sStrToSend;
if (pDisplayWnd)
{
pDisplayWnd->SendMessage(WM_COPYDATA,(WPARAM)0, (LPARAM)&cds);
}
LeaveCriticalSection(&m_CritSec);
//#endif
}
void CThreadTrace::ClearWindows()
{
//#ifdef _DEBUG
memset(&cds, 0, sizeof(cds));
cds.dwData = ACTION_CLEAR_WINDOW;
if (pDisplayWnd)
{
pDisplayWnd->SendMessage(WM_COPYDATA,(WPARAM)0/*GetSafeHwnd()*/, (LPARAM)&cds);
}
else
{
::AfxMessageBox("不能找到调试服务器,请先启动!");
exit(0);
}
//#endif
}