main.cpp
来自「西门子交换机和Dialogic语音板卡连接驱动编程示例」· C++ 代码 · 共 759 行 · 第 1/2 页
CPP
759 行
///////////////////////////////////////////////////////////
// NAME: Trace_OnClose
// DESCRIPTION: Action of WM_CLOSE. Close the trace
// window and uncheck the main menu
//
//////////////////////////////////////////////////////////
void Trace_OnClose(HWND hwnd)
{
// Destroy the trace window
DestroyWindow(hwnd);
DeleteDC(g_hTraceMemdc);
g_hTraceWnd = NULL;
// Remove a check on the menu item
CheckMenuItem(g_hMenu,ID_TOOLS_TRACE,MF_BYCOMMAND|MF_UNCHECKED);
return;
}
///////////////////////////////////////////////////////////
// NAME: Trace_OnSize
// DESCRIPTION: Action of sizing the window
//
//
//////////////////////////////////////////////////////////
void Trace_OnSize(HWND hwnd, UINT state, int cx, int cy)
{
// Nothing to do here for now
return;
}
///////////////////////////////////////////////////////////
// NAME: Trace_OnCreate
// DESCRIPTION: Action of WM_Create, create a virtual
// to handle screen updates
//
//////////////////////////////////////////////////////////
BOOL Trace_OnCreate(HWND hwnd, LPCREATESTRUCT lpCreateStruct)
{
HDC hdc; // Device context handle
HBRUSH hbrush;
HBITMAP hbit;
// get screen attributes
g_nTraceMaxx=GetSystemMetrics(SM_CXSCREEN);
g_nTraceMaxy=GetSystemMetrics(SM_CYSCREEN);
// Get window DC
hdc=GetDC(hwnd);
// Create copy/compatible virtual window to write to
g_hTraceMemdc=CreateCompatibleDC(hdc);
hbit=CreateCompatibleBitmap(hdc,g_nTraceMaxx,g_nTraceMaxy);
SelectObject(g_hTraceMemdc, hbit);
hbrush=(HBRUSH)GetStockObject(WHITE_BRUSH);
SelectObject(g_hTraceMemdc, hbrush);
PatBlt(g_hTraceMemdc,0,0,g_nTraceMaxx,g_nTraceMaxy,PATCOPY);
// Release main window DC
ReleaseDC(hwnd,hdc);
// Place a check on the menu item
CheckMenuItem(g_hMenu,ID_TOOLS_TRACE,MF_BYCOMMAND|MF_CHECKED);
return(TRUE);
}
///////////////////////////////////////////////////////////
//
// Display functions
//
//
///////////////////////////////////////////////////////////
// NAME: UpdateDisplayMain
// DESCRIPTION: Do text out to the main window via
// the an index. A zero nIndex should
// result in an informational message.
//
//////////////////////////////////////////////////////////
BOOL UpdateDisplayMain(int nIndex, char * szDispBuff)
{
char szOutBuff[MAXDISPLAYBUFF]; // Output buffer
int nLength = 0;
RECT WinRect;
HDC hDC;
// Return if its a bad buffer
if(szDispBuff == NULL) {
return(FALSE);
}
else {
// Get length of string and verify its of good length
nLength = strlen(szDispBuff);
if(nLength > MAXDISPLAY) {
nLength = MAXDISPLAY;
}
}
// Clear the display buffer
memset(szOutBuff,0,MAXDISPLAYBUFF);
// Format the output string
if(nIndex==0) {
sprintf(szOutBuff,"SYSTEM -- ");
}
else {
sprintf(szOutBuff,"CH: %03d -- ",nIndex);
}
strncpy((szOutBuff+strlen(szOutBuff)),szDispBuff,nLength);
// Scroll the trace window
hDC = GetDC(g_hMainWnd);
ScrollDC(g_hMemdc,0,20, NULL, NULL, NULL, NULL);
ScrollDC(hDC,0,20, NULL, NULL, NULL, &WinRect);
// Display output main window
TextOut(g_hMemdc, 10, 20, szOutBuff, strlen(szOutBuff));
TextOut(hDC, 10, 20, szOutBuff, strlen(szOutBuff));
ReleaseDC(g_hMainWnd,hDC);
// InvalidateRect(g_hMainWnd,&WinRect,1);
return(TRUE);
}
///////////////////////////////////////////////////////////
// NAME: UpdateDisplayTrace
// DESCRIPTION: Do text out to the trace window via
// an index. A zero nIndex should
// result in an informational message.
//
//////////////////////////////////////////////////////////
BOOL UpdateDisplayTrace(int nIndex, char * szDispBuff)
{
char szOutBuff[MAXDISPLAYBUFF+1]; // Output buffer
int nLength = 0;
DWORD dwBytes;
BOOL bRet;
RECT WinRect;
HDC hDC;
// Check if trace is enabled, if not return
if((g_hTraceWnd==NULL) && (g_bTraceLog==FALSE)) {
return(FALSE);
}
// Return if its a bad buffer
if(szDispBuff==NULL) {
return(FALSE);
}
else {
// Get length of string and verify its of valid length
nLength = strlen(szDispBuff);
if(nLength > MAXDISPLAY) {
nLength = MAXDISPLAY;
}
}
// Clear the display buffer
memset(szOutBuff,0,MAXDISPLAYBUFF);
// Format the output string
if(nIndex==0) {
sprintf(szOutBuff,"SYSTEM -- ");
}
else {
sprintf(szOutBuff,"CH: %03d -- ",nIndex);
}
strncpy((szOutBuff+strlen(szOutBuff)),szDispBuff,nLength);
// Is the window enabled
if(g_hTraceWnd!=NULL) {
// Scroll the trace window
hDC = GetDC(g_hTraceWnd);
ScrollDC(g_hTraceMemdc,0,20, NULL, NULL, NULL, NULL);
ScrollDC(hDC,0,20, NULL, NULL, NULL, &WinRect);
// Display output to trace window
nLength = strlen(szOutBuff);
bRet = TextOut(g_hTraceMemdc, 10, 20, szOutBuff, nLength);
bRet = TextOut(hDC, 10, 20, szOutBuff, nLength);
ReleaseDC(g_hTraceWnd,hDC);
// InvalidateRect(g_hMainWnd,&WinRect,1);
}
// Is logging enabled
if(g_bTraceLog==TRUE) {
// Write to the trace log file
sprintf((szOutBuff+strlen(szOutBuff)),"\n");
WriteFile(g_hTraceLog,szOutBuff,strlen(szOutBuff),&dwBytes,NULL);
}
return(TRUE);
}
///////////////////////////////////////////////////////////
// NAME: UpdateLogError
// DESCRIPTION: Write textual errors to a log file
//
//////////////////////////////////////////////////////////
BOOL UpdateLogError(int nIndex, char * szDispBuff)
{
char szOutBuff[MAXDISPLAYBUFF]; // Output buffer
int nLength = 0;
DWORD dwBytes;
// Return if its a bad buffer
if(szDispBuff==NULL) {
return(FALSE);
}
else {
// Get length of string and verify its of valid length
nLength = strlen(szDispBuff);
if(nLength > MAXDISPLAY) {
nLength = MAXDISPLAY;
}
}
memset(szOutBuff,0,MAXDISPLAYBUFF);
strncpy((szOutBuff+strlen(szOutBuff)),szDispBuff,nLength);
strncpy((szOutBuff+strlen(szOutBuff)),"\n",1);
// Is logging enabled
if(g_hErrorLog!=NULL) {
// Write to the trace log file
WriteFile(g_hErrorLog,szOutBuff,strlen(szOutBuff),&dwBytes,NULL);
}
return(TRUE);
}
///////////////////////////////////////////////////////////
// NAME: UpdateLogResults
// DESCRIPTION: Write textual results to a log file
//
//////////////////////////////////////////////////////////
BOOL UpdateLogResults(int nIndex, char * szDispBuff)
{
char szOutBuff[MAXDISPLAYBUFF]; // Output buffer
int nLength = 0;
DWORD dwBytes;
// Return if its a bad buffer
if(szDispBuff==NULL) {
return(FALSE);
}
else {
// Get length of string and verify its of valid length
nLength = strlen(szDispBuff);
if(nLength > MAXDISPLAY) {
szDispBuff[MAXDISPLAY] = 0;
}
}
// Format the output string
sprintf(szOutBuff,"%s\n",szDispBuff);
// Is logging enabled
if(g_hErrorLog!=NULL) {
// Write to the trace log file
WriteFile(g_hResultsLog,szOutBuff,strlen(szOutBuff),&dwBytes,NULL);
}
return(TRUE);
}
///////////////////////////////////////////////////////////
// NAME: InitializeLogs
// DESCRIPTION: Open the error log and the trace log
//
//////////////////////////////////////////////////////////
BOOL InitializeLogs(void)
{
// Open the error log file
g_hErrorLog=CreateFile("Error.log",GENERIC_WRITE,0,NULL,CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,NULL);
// Verify error log file opened
if(g_hErrorLog==INVALID_HANDLE_VALUE) {
g_hErrorLog = NULL;
MessageBox(NULL,"Creation of Error Log FAILED!","ERROR!",MB_OK);
return(FALSE);
}
// Open the Results file
g_hResultsLog=CreateFile("Results.log",GENERIC_WRITE,0,NULL,CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,NULL);
// Verify log file opened
if(g_hResultsLog==INVALID_HANDLE_VALUE) {
g_hResultsLog = NULL;
MessageBox(NULL,"Creation of Results Log FAILED!","ERROR!",MB_OK);
CloseHandle(g_hErrorLog);
g_hErrorLog = NULL;
return(FALSE);
}
// Open the Trace file
g_hTraceLog=CreateFile("Trace.log",GENERIC_WRITE,0,NULL,CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,NULL);
// Verify log file opened
if(g_hTraceLog==INVALID_HANDLE_VALUE) {
g_hTraceLog = NULL;
MessageBox(NULL,"Creation of Trace Log FAILED!","ERROR!",MB_OK);
CloseHandle(g_hErrorLog);
g_hErrorLog = NULL;
CloseHandle(g_hResultsLog);
g_hResultsLog = NULL;
return(FALSE);
}
return(TRUE);
}
///////////////////////////////////////////////////////////
// NAME: InitializeTestDefaults
// DESCRIPTION: Create and set up the status bar
//
//
//////////////////////////////////////////////////////////
BOOL InitializeTestDefaults(void)
{
int nIndex;
// Initialize all the global test arguments
g_TestInfo.nChannel = 1;
g_TestInfo.nExtension = 102;
g_ChanInfo[g_TestInfo.nChannel].nMsgCnt = 0;
for (nIndex=1; nIndex<= MAXCHAN; nIndex++)
g_ChanInfo[nIndex].nDevHandle = -1;
return(TRUE);
}
///////////////////////////////////////////////////////////
// NAME: CloseVoxResources
// DESCRIPTION:
//
//
//////////////////////////////////////////////////////////
static void CloseVoxResources(void)
{
int nIndex;
OUTPUT(0,"Closing VOX resources ...");
// Stop all the channels synchronously
for (nIndex=1;nIndex<=MAXCHAN;nIndex++)
{
if (g_ChanInfo[nIndex].nDevHandle != -1)
{
// Stop the channel
dx_stopch(g_ChanInfo[nIndex].nDevHandle,EV_SYNC);
if (ATDX_STATE(g_ChanInfo[nIndex].nDevHandle)!=CS_IDLE)
{
// Retry a stop channel
dx_stopch(g_ChanInfo[nIndex].nDevHandle,EV_SYNC);
}
// Close the channel
dx_close(g_ChanInfo[nIndex].nDevHandle);
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?