📄 ai2001dlg.cpp
字号:
// AI2001Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "AI2001.h"
#include "AI2001Dlg.h"
#include "setupdlg.h"
//Add header --------2001/6/30
#include "Answer.h"
#include "Mindex.h"
#include "SourceMonitor.h"
#include "ServiceDataQueue.h"
#include "VSInterpreter.h"
//Add end --------2001/6/30
#include "export.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//Add protype --------2001/6/30
extern CVSInterpreter vsInterpreter;
extern int isConnect;
int iShow = 0;
int InitAI2001( void );
int RunAI2001( HWND hWnd );
int CreatConsole( void );
BOOL WINAPI HandlerRoutine( DWORD dwCtrlType );
//Add end --------2001/6/30
extern HANDLE __hStdOut;
int m_ChannelStatus[1441];
HICON hIcon[8];
CCriticalSection m_cs;
int m_iMyWindowFlag=0;//弹出窗口标识 1 子窗口 0 其它应用程序
int iDrawFlag=0;
int m_iCurrNo=0;
int m_iStatusNo=0;
int m_iTotal=0;
int m_iFlag=0;
extern int maxchans;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAI2001Dlg dialog
CAI2001Dlg::CAI2001Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CAI2001Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CAI2001Dlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CAI2001Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAI2001Dlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
DDX_Control(pDX, IDC_BUTTON_START, m_btnStart);
DDX_Control(pDX, IDC_BUTTON_EXIT, m_btnExit);
DDX_Control(pDX, IDC_BUTTON_SCRIPT, m_btnScript);
DDX_Control(pDX, IDC_BUTTON_SETUP, m_btnSetup);
DDX_Control(pDX, IDC_BUTTON_CONSOLE, m_btnConsole);
DDX_Control(pDX, IDC_BUTTON_SIMUIVR, m_btnSimuIvr );
}
BEGIN_MESSAGE_MAP(CAI2001Dlg, CDialog)
//{{AFX_MSG_MAP(CAI2001Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_ACTIVATE()
ON_COMMAND(ID_MENUITEM_ONHOOK, OnMenuitemOnhook)
ON_WM_MOUSEMOVE()
ON_WM_CREATE()
ON_BN_CLICKED(IDC_BUTTON_EXIT, OnButtonExit)
ON_BN_CLICKED(IDC_BUTTON_SETUP, OnButtonSetup)
ON_BN_CLICKED(IDC_BUTTON_START, OnButtonStart)
ON_WM_RBUTTONDOWN()
ON_WM_LBUTTONDBLCLK()
ON_WM_MOVE()
ON_COMMAND(ID_MENUITEM_SCRIPT, OnMenuitemScript)
ON_WM_CLOSE()
ON_BN_CLICKED(IDC_BUTTON_CONSOLE, OnButtonConsole)
ON_BN_CLICKED(IDC_BUTTON_SCRIPT, OnButtonScript)
ON_COMMAND(ID_MENUITEM_RESET, OnMenuitemReset)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BUTTON_SIMUIVR, OnButtonSimuivr)
ON_NOTIFY(TCN_SELCHANGE, IDC_TAB_IVR, OnSelchangeTabIvr)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAI2001Dlg message handlers
BOOL CAI2001Dlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
//读取图标
m_btnStart.SetIcon(IDI_START);
m_btnConsole.SetIcon(IDI_CONSOLE);
m_btnScript.SetIcon(IDI_SCRIPT);
m_btnSetup.SetIcon(IDI_SETUP);
m_btnSimuIvr.SetIcon(IDI_SIMUIVR);
m_btnExit.SetIcon(IDI_EXIT);
hIcon[0] = AfxGetApp()->LoadIcon(IDI_WHITE);
hIcon[1] = AfxGetApp()->LoadIcon(IDI_CYAN);
hIcon[7] = AfxGetApp()->LoadIcon(IDI_GREEN);
hIcon[2] = AfxGetApp()->LoadIcon(IDI_YELLOW);
hIcon[3] = AfxGetApp()->LoadIcon(IDI_RED);
hIcon[4] = AfxGetApp()->LoadIcon(IDI_BLACK);
hIcon[5] = AfxGetApp()->LoadIcon(IDI_BLUE);
hIcon[6] = AfxGetApp()->LoadIcon(IDI_PURPLE);
for (int i=0;i<7;i++)
SetIcon(hIcon[i],TRUE);
CTabCtrl *pTab=(CTabCtrl *)GetDlgItem(IDC_TAB_IVR);
TC_ITEM tcItem;//添加标签
tcItem.mask=TCIF_TEXT;
//----------------------------------------------------
//insert sub1 dlg
//----------------------------------------------------
tcItem.pszText = "模块一";
pTab->InsertItem(0,&tcItem);
m_sub1Dlg.Create(IDD_DIALOG_PANE1,pTab);
//-------------------------------------
tcItem.pszText = "模块二";
pTab->InsertItem(1,&tcItem);
m_sub2Dlg.Create(IDD_DIALOG_PANE2,pTab);
//-----------------------------------
tcItem.pszText = "模块三";
pTab->InsertItem(2,&tcItem);
m_sub3Dlg.Create(IDD_DIALOG_PANE3,pTab);
//------------------------------------
tcItem.pszText = "模块四";
pTab->InsertItem(3, &tcItem);
m_sub4Dlg.Create(IDD_DIALOG_PANE4,pTab);
pTab->SetCurSel(0);
m_sub1Dlg.ShowWindow(SW_SHOW);
InitAI2001();
SetTimer( 1, 500, NULL );
int nTime = GetPrivateProfileInt("TIMESLICE", "time", 10, ".\\setup.ini");
SetTimer( 2, nTime*1000, NULL );
// Sleep(1000);
int run = GetPrivateProfileInt("Auto_Run", "run",1,".\\setup.ini");
if(run)
OnButtonStart();
return TRUE; // return TRUE unless you set the focus to a control
}
void CAI2001Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
m_iMyWindowFlag=1;
dlgAbout.DoModal();
m_iMyWindowFlag=0;
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CAI2001Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CPaintDC dc(this); // device context for painting
dc.SetMapMode(MM_ANISOTROPIC);
dc.SetWindowExt(400,400);
dc.SetViewportExt(dc.GetDeviceCaps(LOGPIXELSX),
dc.GetDeviceCaps(LOGPIXELSY));
int i,j,iChannelNo;
int iResult,x,y;
switch(iDrawFlag) //0:初始状态 1:更改局部状态-offhook2onhook 2:更改局部状态-onhook2offhook 3.更改局部状态-err status
{
case 0:
dc.DrawIcon(240, 1290, hIcon[1]);
dc.DrawIcon(240+400, 1290, hIcon[2]);
dc.DrawIcon(240+780, 1290, hIcon[3]);
dc.DrawIcon(240+1170, 1290, hIcon[0]);
//iDrawFlag = 4;
break;
}
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CAI2001Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
int ChannelNoToPoint(int iChannelNo, int &x, int &y)
{
if (iChannelNo > 360) return -1;
int i,j;
i = iChannelNo % 30;
j = iChannelNo / 30;
if (i != 0)
{
x = BEGIN_X + (i - 1) * INTERVAL_X;
y = BEGIN_Y + j * INTERVAL_Y;
}
else
{
x = BEGIN_X + 29 * INTERVAL_X;
y = BEGIN_Y + (j - 1) * INTERVAL_Y;
}
return 0;
}
int PointToChannelNo(CPoint point)
{
int i,j;
if (point.x * SCALE < BEGIN_X || point.y * SCALE < BEGIN_Y || point.y * SCALE > (BEGIN_Y+INTERVAL_Y*12) || point.x * SCALE > (BEGIN_X+30*INTERVAL_X))
return 0;
else
{
i = (int)(point.x * SCALE - BEGIN_X) / INTERVAL_X;//col number
j = (int)(point.y * SCALE - BEGIN_Y) / INTERVAL_Y;//row number
if (point.x > (i*INTERVAL_X+BEGIN_X)/SCALE && point.x < (BEGIN_X+32+i*INTERVAL_X)/SCALE &&
point.y > (j*INTERVAL_Y+BEGIN_Y)/SCALE && point.y < (BEGIN_Y+32+j*INTERVAL_Y)/SCALE &&
i < 30)
return (j*30+i+1);
else
return 0;
}
}
void CAI2001Dlg::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
{
CDialog::OnActivate(nState, pWndOther, bMinimized);
// TODO: Add your message handler code here
if (nState == WA_INACTIVE && m_iMyWindowFlag == 0)
{
this->ShowWindow(SW_MINIMIZE);
m_iMyWindowFlag = 0;
}
iDrawFlag = 0;
}
void CAI2001Dlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnMouseMove(nFlags, point);
}
int CAI2001Dlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
m_StatusBarCtl.Create(WS_CHILD|WS_VISIBLE|CCS_BOTTOM|SBARS_SIZEGRIP,
CRect(0,0,0,0), this, ID_MY_STATUS_BAR);
int nParts = 4;
CRect rect;
char sTemp[200];
int iFlag = GetPrivateProfileString("CHANNEL", "MAXCHANS", NULL, sTemp, sizeof(sTemp), ".\\Setup.ini");
if(iFlag == 0)
{
AfxMessageBox("Please set the channelnumber in the setup.ini first!");
return -1;
}
m_StatusBarCtl.GetClientRect(&rect);
int widths[4] = { rect.right/4, rect.right/2, rect.right*3/4, -1 };
m_StatusBarCtl.SetParts(4, widths );
m_iTotal = atoi(sTemp);
sprintf(sTemp,"总端口数: %d",m_iTotal);
m_StatusBarCtl.SetText(sTemp,0,0);
m_StatusBarCtl.SetText("呼入次数: 0",1,0);
m_StatusBarCtl.SetText("呼出次数: 0",2,0);
m_StatusBarCtl.SetText("联机状态: 0",3,0);
//获取运行时间
CTime tFirstTime;
tFirstTime = CTime::GetCurrentTime();
strcpy(sTemp,tFirstTime.Format("AI2001 Professional - [ 启动时间:%Y-%m-%d %H:%M:%S ]"));
this->SetWindowText( sTemp );
//初始化通道状态 0 无效通道 1 待机状态 2 通话状态 3 故障状态
int i;
for(i=0;i<1001;i++)
m_ChannelStatus[i] = 0;
for(i=0;i<=m_iTotal;i++)
m_ChannelStatus[i] = 1;
return 0;
}
void CAI2001Dlg::OnButtonExit()
{
// TODO: Add your control notification handler code here
SendMessage(WM_CLOSE);
//CDialog::OnOK();
}
void CAI2001Dlg::OnButtonSetup()
{
// TODO: Add your control notification handler code here
CSetupDlg setup;
m_iMyWindowFlag=1;
setup.DoModal();
m_iMyWindowFlag=0;
}
void CAI2001Dlg::OnButtonStart()
{
// TODO: Add your control notification handler code here
if (m_iFlag == 0)
{
if( RunAI2001( this->m_hWnd ) != 0 )
{
//AfxMessageBox("Start failed", MB_ICONEXCLAMATION);
return;
}
//m_btnStart.EnableWindow( FALSE );
m_btnStart.SetIcon(IDI_STOP);
m_btnStart.SetWindowText("停止");
m_btnSimuIvr.EnableWindow(TRUE); //刷新脚本按钮
UpdateData(FALSE);
m_iFlag = 1;
}
else
{
SendMessage(WM_CLOSE);
/*
if (!SetEvent(ghDLGCEvent)) // unsuccessful
{
AfxMessageBox("Stop failed", MB_ICONEXCLAMATION);
return;
}
m_btnStart.SetIcon(IDI_START);
m_btnStart.SetWindowText("启动");
UpdateData(FALSE);
m_iFlag = 0;
*/
}
}
void CAI2001Dlg::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_iCurrNo = PointToChannelNo(point);
if (m_iCurrNo != 0 && (m_iCurrNo <= m_iTotal))
{
CMenu menu;
CRect rect;
this->GetWindowRect(rect);
menu.LoadMenu(IDR_MYMENU);
char szTemp[20];
sprintf(szTemp,"通道号:%d",m_iCurrNo);
menu.ModifyMenu(0, MF_BYCOMMAND, 0, szTemp);
menu.EnableMenuItem(ID_MENUITEM_ONHOOK,MF_ENABLED);
if (m_ChannelStatus[m_iCurrNo] != 2)
menu.EnableMenuItem(ID_MENUITEM_ONHOOK,MF_GRAYED);
menu.EnableMenuItem(ID_MENUITEM_RESET,MF_ENABLED);
if (m_ChannelStatus[m_iCurrNo] != 3)
menu.EnableMenuItem(ID_MENUITEM_RESET,MF_GRAYED);
menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,rect.left+point.x+5,rect.top+point.y+30,this);
}
CDialog::OnRButtonDown(nFlags, point);
}
void CAI2001Dlg::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
/*
if (m_iCurrNo != 0 && m_iCurrNo <= m_iTotal && m_ChannelStatus[m_iCurrNo] == 1)
{
m_cs.Lock();
m_ChannelStatus[m_iCurrNo] = 2;
m_cs.Unlock();
iDrawFlag = 2;
m_iStatusNo = m_iCurrNo;
wprintf("channelno:%d",m_iCurrNo);
Invalidate(FALSE);
UpdateWindow();
}
*/
CDialog::OnLButtonDblClk(nFlags, point);
}
void CAI2001Dlg::OnMove(int x, int y)
{
CDialog::OnMove(x, y);
// TODO: Add your message handler code here
iDrawFlag=0;
}
int InitAI2001( void )
{
if ((ghDLGCEvent = CreateEvent(
NULL, // pointer to security attributes, we use default
FALSE, // flag for manual reset event, we choose auto-reset
FALSE, // flag for initial state, we choose unsignalled
NULL) // pointer to event-object name, we choose no name
) == NULL)// failure
{
AfxMessageBox("ghDLGCEvent = CreateEvent failed", MB_ICONEXCLAMATION);
return -1;
}
GetPrivateProfileString("PATH", "SYSPATH", "\\Pansr\\Voc\\", SVocDir, 128, ".\\Setup.ini" );
GetPrivateProfileString("PATH", "USRPATH", "\\Pansr\\Voc\\", GVocDir, 128, ".\\Setup.ini" );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -