📄 ai2001dlg.cpp
字号:
GetPrivateProfileString("PATH", "FAXPATH","\\Pansr\\Fax\\", SFaxDir, 128, ".\\Setup.ini" );
char combvox[128] = ".\\combvox.ini";
int unit, tlen ;
CMindex *mindex = new CMindex;
mindex->InitCombvox( combvox, "MANDARIN" );
unit = mindex->GetCount();
tlen = mindex->GetCombBufLen();
pCombIdx[0] = new IDXINFO[unit];
pCombBuf[0] = new char[tlen];
memcpy( (char *)pCombIdx[0], mindex->GetCombIdx(), unit*sizeof(IDXINFO) );
memcpy( pCombBuf[0], mindex->GetCombBuf(), tlen );
CombCount[0] = unit;
mindex->ResetComb();
mindex->InitCombvox( combvox, "CANTONESE" );
unit = mindex->GetCount();
tlen = mindex->GetCombBufLen();
pCombIdx[1] = new IDXINFO[unit];
pCombBuf[1] = new char[tlen];
memcpy( (char *)pCombIdx[1], mindex->GetCombIdx(), unit*sizeof(IDXINFO) );
memcpy( pCombBuf[1], mindex->GetCombBuf(), tlen );
CombCount[1] = unit;
mindex->ResetComb();
mindex->ReadEnglish( combvox, "ENGLISH" );
unit = mindex->GetCount();
tlen = mindex->GetCombBufLen();
pCombIdx[2] = new IDXINFO[unit];
pCombBuf[2] = new char[tlen];
memcpy( (char *)pCombIdx[2], mindex->GetCombIdx(), unit*sizeof(IDXINFO) );
memcpy( pCombBuf[2], mindex->GetCombBuf(), tlen );
CombCount[2] = unit;
mindex->ResetComb();
delete mindex;
pSilenceBuf = new char[16000];
memset( pSilenceBuf, 0x08, 16000 );
maxchans = GetPrivateProfileInt("CHANNEL", "MAXCHANS", 4, ".\\Setup.ini" );
frontend = GetPrivateProfileInt("CHANNEL", "FRONTEND", 2, ".\\Setup.ini" );
char faxtype[12] = "";
GetPrivateProfileString("CHANNEL", "FAXRES", "VFAX",faxtype,12, ".\\Setup.ini" );
if( stricmp( faxtype, "GFAX" ) == 0 )
{
gammfax = 1;
faxchans = GetPrivateProfileInt("GFAX", "FAXCHANS", 0, ".\\Setup.ini" );
faxbdnum = GetPrivateProfileInt("GFAX", "FAXBDNUM", 0, ".\\Setup.ini" );
}
else
{
gammfax = 0;
faxchans = GetPrivateProfileInt("VFAX", "FAXCHANS", 0, ".\\Setup.ini" );
faxbdnum = GetPrivateProfileInt("VFAX", "FAXBDNUM", 0, ".\\Setup.ini" );
}
msichans = GetPrivateProfileInt("MSI", "MSICHANS", 0, ".\\Setup.ini" );
msibdnum = GetPrivateProfileInt("MSI", "MSIBDNUM", 0, ".\\Setup.ini" );
warnspan = GetPrivateProfileInt("WARN", "WARNSPAN", 4, ".\\Setup.ini" );
stopspan = GetPrivateProfileInt("WARN", "STOPSPAN", 6, ".\\Setup.ini" );
warntype = GetPrivateProfileInt("WARN", "WARNTYPE", 0, ".\\Setup.ini" );
return 0;
}
int RunAI2001( HWND hWnd )
{
int chdev;
if((chdev = dx_open("dxxxB1C1", 0)) == -1)
{
m_iMyWindowFlag=1;
AfxMessageBox("Dialogic Service is not running! \r\nPlease first run it!", MB_ICONEXCLAMATION );
m_iMyWindowFlag=0;
return -1;
}
else
{
dx_close(chdev);
}
DeleteFile("SourceMonitor.inf");
if (!ResetEvent(ghDLGCEvent)) // make sure ghDLGCEvent is unsignalled
{
AfxMessageBox("Reset event failed in OnDlgcButton", MB_ICONEXCLAMATION );
return -1;
}
//-----Run VSInterpreter thread
//
struct VSInterpreterThreadParam *pvsInterpreter;
pvsInterpreter = (struct VSInterpreterThreadParam *)malloc(sizeof(VSInterpreterThreadParam));
memset( (char *)pvsInterpreter, 0x0, sizeof(VSInterpreterThreadParam) );
pvsInterpreter->iChannelCount = maxchans;
//初始化
strcpy(pvsInterpreter->aszInstructionFileName, "d:\\ai2001\\script\\vscript_isee.ini" );
if( !AfxBeginThread(VSInterpreterThread,(LPVOID)pvsInterpreter) )
{
AfxMessageBox("AfxBeginThread VSInterpreter failed.", MB_ICONEXCLAMATION);
return -1;
}
Sleep(1000); //等待CONSOLE创建完毕
//-----Run Dialogic thread
//
ARG_STRUCT m_args;
m_args.hWnd = hWnd;
m_args.d4xbdnum = 1;
m_args.dtibdnum = 1;
m_args.maxchans = maxchans;
m_args.faxbdnum = faxbdnum;
m_args.faxchans = faxchans;
m_args.msibdnum = msibdnum;
m_args.msichans = msichans;
m_args.frontend = frontend;
m_args.scbus = TRUE;
m_args.routeag = TRUE;
m_args.boardtag = FALSE;
if (!AfxBeginThread(RunDialogic,(LPVOID)&m_args))
{
AfxMessageBox("AfxBeginThread RunDialogic failed.", MB_ICONEXCLAMATION);
return -1;
}
Sleep(4000);
return 0;
}
void CAI2001Dlg::OnCancel()
{
// TODO: Add your message handler code here and/or call default
//CDialog::OnCancel();
}
void CAI2001Dlg::OnClose()
{
// TODO: Add your message handler code here and/or call default
if(AfxMessageBox("您确实要退出吗?" ,MB_YESNO|MB_DEFBUTTON2) == IDYES)
{
SetEvent(ghDLGCEvent);
Sleep(4000);
CDialog::OnOK();
}
//CDialog::OnClose();
}
void CAI2001Dlg::OnButtonConsole()
{
// TODO: Add your control notification handler code here
if( __hStdOut == NULL )
{
CreatConsole();
iDrawFlag = 0;
Invalidate(FALSE);
UpdateWindow();
}
else
{
__hStdOut = NULL;
FreeConsole();
}
}
BOOL WINAPI HandlerRoutine( DWORD dwCtrlType )
{
__hStdOut = NULL;
FreeConsole();
return TRUE;
}
int CreatConsole( void )
{
AllocConsole();
SetConsoleTitle("Console Window");
__hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
COORD co = {100, 100};
SetConsoleScreenBufferSize(__hStdOut, co);
SetConsoleCtrlHandler( HandlerRoutine, TRUE );
CWnd *pwnd = AfxGetMainWnd();
SetForegroundWindow(pwnd->m_hWnd);
return 0;
}
void CAI2001Dlg::OnButtonScript()
{
// TODO: Add your control notification handler code here
if( m_iFlag == 0 ) return;
if( !iShow )
{
vsInterpreter.m_psourceMonitor->ShowWindow( SW_SHOW );
iShow = 1;
}
else
{
vsInterpreter.m_psourceMonitor->ShowWindow( SW_HIDE );
iShow = 0;
}
}
BOOL CAI2001Dlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
switch(pMsg->message)
{
case WM_DLGC_STATE:
if (pMsg->lParam == ST_ERROR)
{
m_ChannelStatus[pMsg->wParam] = 3;
iDrawFlag = 3;
}
else if(pMsg->lParam == ST_WTRING ||pMsg->lParam == ST_ONHOOK)
{
m_ChannelStatus[pMsg->wParam] = 1;
iDrawFlag = 1;
}
else
{
m_ChannelStatus[pMsg->wParam] = 2;
iDrawFlag = 2;
}
m_iStatusNo=pMsg->wParam;
wprintf("channelno:%d state:%d",pMsg->wParam,pMsg->lParam);
if(m_iStatusNo>0&&m_iStatusNo<=360)
{
m_sub1Dlg.Invalidate(FALSE);
m_sub1Dlg.UpdateWindow();
}
if(m_iStatusNo>360&&m_iStatusNo<=720)
{
m_sub2Dlg.Invalidate(FALSE);
m_sub2Dlg.UpdateWindow();
}
if(m_iStatusNo>720&&m_iStatusNo<=1080)
{
m_sub3Dlg.Invalidate(FALSE);
m_sub3Dlg.UpdateWindow();
}
if(m_iStatusNo>1080&&m_iStatusNo<=1140)
{
m_sub4Dlg.Invalidate(FALSE);
m_sub4Dlg.UpdateWindow();
}
/* if(m_iStatusNo<=360)
::SendMessage(m_sub1Dlg.m_hWnd, WM_PAINT,0,0);
if(m_iStatusNo>360 && m_iStatusNo<=720)
::SendMessage(m_sub2Dlg.m_hWnd, WM_PAINT, 0,0);
if(m_iStatusNo>720 && m_iStatusNo<=1080)
::SendMessage(m_sub3Dlg.m_hWnd, WM_PAINT, 0,0);
if(m_iStatusNo>1080 && m_iStatusNo<=1440)
::SendMessage(m_sub4Dlg.m_hWnd, WM_PAINT, 0,0);
*/
break;
case WM_KEYDOWN: //屏蔽回车键
if(pMsg->wParam == VK_RETURN)
return TRUE;
case WM_DLGC_STOPPED:
case WM_DLGC_CODE:
default:
break;
}
return CDialog::PreTranslateMessage(pMsg);
}
void CAI2001Dlg::OnMenuitemOnhook()
{
// TODO: Add your command handler code here
/*
SendMessage(WM_POP_STATE, m_iCurrNo, 1 );
m_cs.Lock();
m_ChannelStatus[m_iCurrNo]=1;
m_cs.Unlock();
m_iStatusNo = m_iCurrNo;
iDrawFlag = 1;
Invalidate(FALSE);
UpdateWindow();
*/
}
void CAI2001Dlg::OnMenuitemReset()
{
// TODO: Add your command handler code here
SendMessage(WM_POP_STATE, m_iCurrNo, 2 );
}
void CAI2001Dlg::OnMenuitemScript()
{
// TODO: Add your command handler code here
SendMessage(WM_POP_STATE, m_iCurrNo, 3 );
}
void CAI2001Dlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
char aszTemp[100]="";
switch( nIDEvent )
{
case 1:
if( m_iFlag != 1 ) return;
sprintf(aszTemp, "呼入次数: %d", vsInterpreter.m_iCountOfTurnOnOfTotal_In );
m_StatusBarCtl.SetText(aszTemp, 1, 0);
sprintf(aszTemp, "呼出次数: %d", vsInterpreter.m_iCountOfTurnOnOfTotal_Out );
m_StatusBarCtl.SetText(aszTemp, 2, 0);
sprintf(aszTemp, "联机状态: %d", isConnect );
m_StatusBarCtl.SetText(aszTemp, 3, 0);
break;
case 2:
Ccs_sr_Connect();
break;
default:
break;
}
CDialog::OnTimer(nIDEvent);
}
//更新脚本,
//add by lj 2003/05/21
void CAI2001Dlg::OnButtonSimuivr()
{
//将内存中脚本文件重新读入内存
/*********************************************************
将m_vsFileBufferList(BUFFER末尾有0结束)中已经load进内存的所有文件
重新load一次。
重新load script.ini中引用的所有脚本到内存
------add by lj 2003/05/22
*********************************************************/
int j;
struct CurrentState *pcurrentState;
FILE *file;
int iFileSize;
for(int i=0; i<maxchans; i++)
{
pcurrentState = &(vsInterpreter.m_pcurrentState[i]);
//读出文件
file = fopen(pcurrentState->aszInstructionFile, "rb");
if(file == NULL)
{
wprintf_err1("In LoadVSFileToBuffer_Refresh(%d) can not open %s", i, pcurrentState->aszInstructionFile);
return;
}
fseek(file, SEEK_SET, SEEK_END);
iFileSize = ftell(file) + 1; //在末尾增加一个0
fseek(file, SEEK_SET, SEEK_SET);
char *szFileBuf;
szFileBuf = (char *)malloc(iFileSize);
if(fread(szFileBuf, sizeof(char), iFileSize, file) != iFileSize - 1)
{
wprintf_err1("In LoadVSFileToBuffer_Refresh(%d), fread(%s) failed", i, pcurrentState->aszInstructionFile);
return;
}
szFileBuf[iFileSize - 1] = 0;
fclose(file);
//检查这个通道的脚本文件是否已被调入内存
for(j = 0; j < vsInterpreter.m_vsFileBufList.iCount; j ++)
{
if(stricmp((vsInterpreter.m_vsFileBufList.vsFileBuf)[j].aszVSFileName, pcurrentState->aszInstructionFile) == 0)
break;
}
if(j < vsInterpreter.m_vsFileBufList.iCount)
{//已被调入过
//刷新调入内存中的VSFILE
free((vsInterpreter.m_vsFileBufList.vsFileBuf)[j].szFileBuf); //释放原来的内存
(vsInterpreter.m_vsFileBufList.vsFileBuf)[j].szFileBuf = szFileBuf;
continue ;
}
//未被调入过,则调入内存
vsInterpreter.m_vsFileBufList.iCount ++;
vsInterpreter.m_vsFileBufList.vsFileBuf = (struct VSFileBuf *)realloc(vsInterpreter.m_vsFileBufList.vsFileBuf, vsInterpreter.m_vsFileBufList.iCount * sizeof(struct VSFileBuf));
(vsInterpreter.m_vsFileBufList.vsFileBuf)[vsInterpreter.m_vsFileBufList.iCount - 1].szFileBuf = szFileBuf;
(vsInterpreter.m_vsFileBufList.vsFileBuf)[vsInterpreter.m_vsFileBufList.iCount - 1].iFileBufLen = iFileSize;
strcpy((vsInterpreter.m_vsFileBufList.vsFileBuf)[vsInterpreter.m_vsFileBufList.iCount - 1].aszVSFileName, pcurrentState->aszInstructionFile);
}
//将script.ini中引用的子script调入内存
char szFileName[100] = "\0";
char aszTempKey[100] = "\0";
int len;
CStdioFile fTemp;
CString strTemp;
int nStart, nEnd;
if(fTemp.Open(".\\script.ini",CFile::modeRead) == 0)
return;
while( fTemp.ReadString(strTemp) )
{
if((nStart=strTemp.Find('=')) != -1 && (nEnd=strTemp.Find('#')) != -1)
{
memset(szFileName, 0x0, 100);
memset(aszTempKey, 0x0, 100);
strcpy(szFileName, strTemp.Mid(nStart+1, nEnd-nStart-1 ));
if( szFileName[0] != '\\' && szFileName[1] != ':' )
{
GetCurrentDirectory(100, aszTempKey);
len = strlen(aszTempKey);
if( aszTempKey[len-1] != '\\' )
{
strcat( aszTempKey, "\\Script\\" );
strcat( aszTempKey, szFileName );
}
strcpy( szFileName, aszTempKey );
}
if((file = fopen(szFileName, "rb")) == NULL)
{
continue;
}
fseek(file, SEEK_SET, SEEK_END);
iFileSize = ftell(file) + 1; //在末尾增加一个0
fseek(file, SEEK_SET, SEEK_SET);
char* szIniBuf;
szIniBuf = (char *)malloc(iFileSize);
if(fread(szIniBuf, sizeof(char), iFileSize, file) != iFileSize - 1)
{
wprintf_err1("In LoadVSFileToBuffer_Refresh(%d), fread(%s) failed", i, pcurrentState->aszInstructionFile);
return ;
}
szIniBuf[iFileSize - 1] = 0;
fclose(file);
//写到内存文件,先检查是否已经调入内存
for(j = 0; j < vsInterpreter.m_vsFileBufList.iCount; j ++)
{
if(stricmp((vsInterpreter.m_vsFileBufList.vsFileBuf)[j].aszVSFileName, szFileName) == 0)
break;
}
if(j < vsInterpreter.m_vsFileBufList.iCount)
{//已被调入过
//刷新调入内存中的VSFILE
free((vsInterpreter.m_vsFileBufList.vsFileBuf)[j].szFileBuf); //释放原来的内存
(vsInterpreter.m_vsFileBufList.vsFileBuf)[j].szFileBuf = szIniBuf;
(vsInterpreter.m_vsFileBufList.vsFileBuf)[j].iFileBufLen = iFileSize;
continue ;
}
//未被调入过,则调入内存
vsInterpreter.m_vsFileBufList.iCount ++;
vsInterpreter.m_vsFileBufList.vsFileBuf = (struct VSFileBuf *)realloc(vsInterpreter.m_vsFileBufList.vsFileBuf, vsInterpreter.m_vsFileBufList.iCount * sizeof(struct VSFileBuf));
(vsInterpreter.m_vsFileBufList.vsFileBuf)[vsInterpreter.m_vsFileBufList.iCount - 1].szFileBuf = szIniBuf;
(vsInterpreter.m_vsFileBufList.vsFileBuf)[vsInterpreter.m_vsFileBufList.iCount - 1].iFileBufLen = iFileSize;
strcpy((vsInterpreter.m_vsFileBufList.vsFileBuf)[vsInterpreter.m_vsFileBufList.iCount - 1].aszVSFileName, szFileName);
}
}
fTemp.Close();
return ;
}
//end add
void CAI2001Dlg::OnSelchangeTabIvr(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
CTabCtrl *pTab=(CTabCtrl *)GetDlgItem(IDC_TAB_IVR);
int nPage=pTab->GetCurSel();
if(nPage==0)
{
iDrawFlag = 0; //初始化
m_sub2Dlg.ShowWindow(SW_HIDE);
m_sub3Dlg.ShowWindow(SW_HIDE);
m_sub4Dlg.ShowWindow(SW_HIDE);
m_sub1Dlg.ShowWindow(SW_SHOW);
::SendMessage(m_sub1Dlg.m_hWnd, WM_PAINT, 0, 0);
}
if(nPage==1)
{
iDrawFlag = 0; //初始化
m_sub1Dlg.ShowWindow(SW_HIDE);
m_sub3Dlg.ShowWindow(SW_HIDE);
m_sub4Dlg.ShowWindow(SW_HIDE);
m_sub2Dlg.ShowWindow(SW_SHOW);
::SendMessage(m_sub2Dlg.m_hWnd, WM_PAINT, 0, 0);
}
if(nPage==2)
{
iDrawFlag = 0;
m_sub2Dlg.ShowWindow(SW_HIDE);
m_sub1Dlg.ShowWindow(SW_HIDE);
m_sub4Dlg.ShowWindow(SW_HIDE);
m_sub3Dlg.ShowWindow(SW_SHOW);
::SendMessage(m_sub3Dlg.m_hWnd, WM_PAINT, 0, 0);
}
if(nPage==3)
{
iDrawFlag = 0;
m_sub2Dlg.ShowWindow(SW_HIDE);
m_sub3Dlg.ShowWindow(SW_HIDE);
m_sub1Dlg.ShowWindow(SW_HIDE);
m_sub4Dlg.ShowWindow(SW_SHOW);
::SendMessage(m_sub4Dlg.m_hWnd, WM_PAINT, 0, 0);
}
*pResult = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -