⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 d160aunpbxdlg.cpp

📁 VC交换机例程,东进
💻 CPP
📖 第 1 页 / 共 4 页
字号:
// D160AUNPBXDlg.cpp : implementation file
//

#include "stdafx.h"
#include "D160AUNPBX.h"
#include "D160AUNPBXDlg.h"
#include "Tc08a32.h"
#include "NewSig.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

bool bHaveLoadDriver;
/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CD160AUNPBXDlg dialog

CD160AUNPBXDlg::CD160AUNPBXDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CD160AUNPBXDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CD160AUNPBXDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	
	intnum=0;
	intnum1=0;
	// 取得语音文件路径
	char temp[50];
	::GetCurrentDirectory (50,temp);
	strcpy(VoicePath,temp);
	strcat(VoicePath,"\\");
			
}

void CD160AUNPBXDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CD160AUNPBXDlg)
	DDX_Control(pDX, IDC_LIST1, m_listctrl);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CD160AUNPBXDlg, CDialog)
	//{{AFX_MSG_MAP(CD160AUNPBXDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_DESTROY()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_SIZE()
	ON_WM_CLOSE()
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_RUN, OnRun)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CD160AUNPBXDlg message handlers

BOOL CD160AUNPBXDlg::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

	// 取上次窗口关闭时的位置
/*	CFile mFile;
	char FileName[50];
	::GetCurrentDirectory (50,FileName);
	strcat(FileName,"\\lastdlgStatus.sav");

	if(mFile.Open((FileName), CFile::modeReadWrite) && mFile.GetLength()>0)
	{
		CArchive ar(&mFile, CArchive::load);
		mapStrToRect.Serialize(ar);
		ar.Close();
		mFile.Close();
		CString strWindow;
		GetWindowText(strWindow);
		CRect rectDlg;
		if(mapStrToRect.Lookup(strWindow, rectDlg))
			MoveWindow(rectDlg);
	}

*/	
	CRect rectWnd;
	GetWindowRect(&rectWnd);
	listRect.AddTail(&rectWnd);
	CWnd *pWndChild = GetWindow(GW_CHILD);
	while(pWndChild)
	{
		pWndChild->GetWindowRect(&rectWnd);
		listRect.AddTail(&rectWnd);
		pWndChild = pWndChild->GetNextWindow();
	}

	InitSystem ();


	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CD160AUNPBXDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	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 CD160AUNPBXDlg::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
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CD160AUNPBXDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CD160AUNPBXDlg::OnSize(UINT nType, int cx, int cy) 
{
	CDialog::OnSize(nType, cx, cy);
	
	// TODO: Add your message handler code here
	int nCount=listRect.GetCount();
	if(listRect.GetCount()>0)
	{
		CRect rectDlgNow;
		GetWindowRect(&rectDlgNow);
		POSITION mP = listRect.GetHeadPosition();
		CRect rectDlgSaved;
		rectDlgSaved = listRect.GetNext(mP);
		ScreenToClient(rectDlgSaved);
		ScreenToClient(rectDlgNow);
		float fRateScaleX = (float)(rectDlgNow.right-rectDlgNow.left)/(rectDlgSaved.right-rectDlgSaved.left);
		float fRateScaleY = (float)(rectDlgNow.bottom-rectDlgNow.top)/(rectDlgSaved.bottom-rectDlgSaved.top);
		ClientToScreen(rectDlgSaved);
		ClientToScreen(rectDlgNow);
		LOGFONT stFont;
		::GetObject((HFONT)GetStockObject(DEFAULT_GUI_FONT), sizeof(stFont), &stFont);
		strcpy(stFont.lfFaceName,"Times New Roman");
		stFont.lfHeight = (long)(fRateScaleY*14);
		stFont.lfWidth = (long)(fRateScaleX*7);
		CFont * m_pCFont;
		m_pCFont = new CFont;
		m_pCFont->CreateFontIndirect(&stFont);
		CRect rectChildSaved;
		CWnd *pWndChild = GetWindow(GW_CHILD);
		while(pWndChild)
		{
			rectChildSaved = listRect.GetNext(mP);
			rectChildSaved.left = rectDlgNow.left+(int)((rectChildSaved.left-rectDlgSaved.left)* fRateScaleX);
			rectChildSaved.top = rectDlgNow.top+(int)((rectChildSaved.top-rectDlgSaved.top)*fRateScaleY);
			rectChildSaved.right = rectDlgNow.right+(int)((rectChildSaved.right-rectDlgSaved.right)* fRateScaleX);
			rectChildSaved.bottom = rectDlgNow.bottom+(int)((rectChildSaved.bottom-rectDlgSaved.bottom)* fRateScaleY);
			ScreenToClient(rectChildSaved);
			pWndChild->MoveWindow(rectChildSaved);
			pWndChild->SetFont(m_pCFont);
			pWndChild = pWndChild->GetNextWindow();		
		}
	}
	Invalidate();
	
}

void CD160AUNPBXDlg::OnDestroy()
{
	KillTimer(1);
	WinHelp(0L, HELP_QUIT);
	CDialog::OnDestroy();

	// 保存程序退出时的窗口位置
/*	CRect rectDlg;
	GetWindowRect(&rectDlg);
	CString strWindow;
	GetWindowText(strWindow);
	mapStrToRect.SetAt(strWindow, rectDlg);
	CFile mFile;
	char FileName[50];
	::GetCurrentDirectory (50,FileName);
	strcat(FileName,"\\lastdlgStatus.sav");
	mFile.Open(FileName,CFile::modeCreate|CFile::modeWrite);
	CArchive ar(&mFile, CArchive::store);
	mapStrToRect.Serialize(ar);
	ar.Close();
	mFile.Close(); 
*/
  }

void CD160AUNPBXDlg::OnOK() 
{
	// TODO: Add extra validation here
	if(MessageBox("确认要退出本系统 ?","Exit System !", MB_ICONQUESTION |MB_OKCANCEL)==1)
		CDialog::OnOK();
	
}

void CD160AUNPBXDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	if(MessageBox("确认要退出本系统 ?","Exit System !", MB_ICONQUESTION |MB_OKCANCEL)==1)
	{// 按确定键退出本程序
		CDialog::OnClose();
		KillTimer(1);
	}
}

void CD160AUNPBXDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	/*
		intnum++;
		if(intnum==12)
		{	intnum=0;	intnum1++;}
		if(intnum1==5)intnum1=0;
		switch(intnum1)
		{
			case 0:
				for(i=0;i<=TotalLine-1;i++)
					m_listctrl.SetItemText (i,COL_OF_REMARK," *");
				break;

			case 1:	for(i=0;i<=TotalLine-1;i++)
					m_listctrl.SetItemText (i,COL_OF_REMARK," /");
				break;
			case 2:
				for(i=0;i<=TotalLine-1;i++)
					m_listctrl.SetItemText (i,COL_OF_REMARK," -");
				break;
			case 3:
				for(i=0;i<=TotalLine-1;i++)
					m_listctrl.SetItemText (i,COL_OF_REMARK," \\");
				break;
			case 4:	for(i=0;i<=TotalLine-1;i++)
					m_listctrl.SetItemText (i,COL_OF_REMARK," |");
				break;
			default :
				break;
		}

	*/
	if (RunFlag)
		DoWork();
	
	CDialog::OnTimer(nIDEvent);
}

BOOL CD160AUNPBXDlg::InitSystem()
{	// 程序初始化
	InitCard();								// 初始化语音卡的硬件
	InitDisp();								// 初试化显示内容

	return TRUE;
}

void CD160AUNPBXDlg::OnRun() 
{
	// TODO: Add your control notification handler code here
	SetTimer(1,100,NULL);
	
	if(!RunFlag)
	{
		RunFlag=TRUE;
		GetDlgItem(IDC_RUN)->SetWindowText(" 停 止(&S)");
		GetDlgItem(IDOK)->EnableWindow(false);
	}
	else
	{
		RunFlag=FALSE;
		GetDlgItem(IDC_RUN)->SetWindowText(" 运  行(&R)");
		GetDlgItem(IDOK)->EnableWindow(true);
	}

	
}
void CD160AUNPBXDlg::InitCard()
{	// 初始化语音卡的硬件

		if ( LoadDRV ( ) ) {		
		MessageBox ( "  加载D160A语音卡驱动程序失败 !  ", "Message", MB_ICONEXCLAMATION   |MB_SYSTEMMODAL|MB_OK );
//    	yzExitSystem();
		PostQuitMessage(0);
	
	}

	Sleep(1000);		
	if ( EnableCard(CheckValidCh(),1024*8) ) {
		FreeDRV();
		MessageBox ( "  激活D160A语音卡失败 !  ", "Message", MB_ICONEXCLAMATION |MB_SYSTEMMODAL|MB_OK );
	//	yzExitSystem();
		PostQuitMessage(0);
	
	}

	Sleep(1000);

	// 需从配置文件中读取参数
	SetBusyPara(350);				// 设置忙音参数
	SetDialPara(1000,4000,350,7);	// 设置回铃音参数

	SetPackRate ( PACK_64KBPS );	// 设置压缩率
	Sig_Init(0);					// 使用新的信号音检测函数

	ReadGenerateSigBuf ("..\\..\\voc\\teding.voc");
}


void CD160AUNPBXDlg::InitDisp()
{	// 初试化显示内容
	TotalLine=CheckValidCh();
	channel=CheckValidCh();
	//	m_listctrl.SetItemCount (channel);
	//channel=32;

	// 初始化列表视头内容
	m_listctrl.InsertColumn(COL_OF_LINE_NO,"线路序号",LVCFMT_LEFT,90,-1);
	m_listctrl.InsertColumn(COL_OF_LINE_NUMBER," 线路号码",LVCFMT_LEFT,110,-1);
	m_listctrl.InsertColumn(COL_OF_LINE_STATUS,"    线路状态",LVCFMT_LEFT,260,-1);
	m_listctrl.InsertColumn(COL_OF_CALLERID," 主叫号码",LVCFMT_LEFT,110,-1);
	m_listctrl.InsertColumn(COL_OF_CALLEEID," 被叫号码",LVCFMT_LEFT,110,-1);
	m_listctrl.InsertColumn(COL_OF_REMARK," *",LVCFMT_LEFT,50,-1);
	//m_listctrl.InsertColumn(5," *",LVCFMT_LEFT,55,-1);


	// 显示线路序号
	CString tempstr,tempstr1;
	for(int i=channel-1;i>=0;i--)
	{
		tempstr.Format(" No.%d",i+1);	
	//	if(i<9)
		//	tempstr.Format(" No. %d",i+1);	
		m_listctrl.InsertItem(0,tempstr); 
	
	}
	
	// 显示线路号码,并存储线路号码
	// <10 的线路号码存储为‘0’+i ,即为“01”,“02”,“03”,……“09”
	// >=10的线路号码存储为:“10”,“11”,“12”,……,“64”
	int interline=1;
	int outline=1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -