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

📄 dial.cpp

📁 电话拨号演示系统(需硬件板卡支持)
💻 CPP
字号:
/**************************************************************************
 *
 *	Dial:
 *
 *	A sample app showing the sndPlaySound API
 *
 **************************************************************************
 *
 *  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
 *  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
 *  PURPOSE.
 *
 *  Copyright (C) 1994 - 1996  Microsoft Corporation.  All Rights Reserved.
 *
 **************************************************************************/
#pragma warning(disable: 4001)
#define __DIAL_CPP
#define Unused(var)	(var=var)

// header dependancies 
#include <windows.h>
#include <commdlg.h>
#include <commctrl.h>
#include <windowsx.h>
#include "resource.h"
#include "Tce1.h"
#include "Dial.h"
//global variables 
HANDLE hInst;
HWND hGWnd;
HWND hPropPage[3],hVisable;
bool bHaveLoadDriver;
extern DIALDATA_STRUCT DialData;
extern int nDialType;
extern int TotalTrunk;
////////////////////////////////////////////////////////////////////////////////
//WinMain
//
//Purpose: The main procedure
//
//Parameters: HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdParam, 
//int nCmdShow
//
//Returns: int
////////////////////////////////////////////////////////////////////////////////// 
int PASCAL WinMain (
	HINSTANCE hInstance, 
	HINSTANCE hPrevInstance,
	LPSTR lpszCmdParam, 
	int nCmdShow)

{
	static char szAppName[] = "Dial";
	HWND        hwnd;
	MSG         msg;
	WNDCLASS    wndclass;
	RECT rect;
	int width,height;
	char strSys[200];
	TC_ITEM TabCtrlItem;

	HINSTANCE hLib;

	Unused(lpszCmdParam);

	if (!hPrevInstance)
	{
		wndclass.style         = CS_HREDRAW | CS_VREDRAW;
		wndclass.lpfnWndProc   = WndProc;
		wndclass.cbClsExtra    = 0 ;
		wndclass.cbWndExtra    = DLGWINDOWEXTRA;
		wndclass.hInstance     = hInstance;
		wndclass.hIcon         = LoadIcon (hInstance, "IDI_Dial");
		wndclass.hCursor       = LoadCursor (NULL, IDI_APPLICATION);
		wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
		wndclass.lpszMenuName  = NULL;
		wndclass.lpszClassName = szAppName;

		RegisterClass (&wndclass);
	}

	GetSystemDirectory(strSys,200);
	strcat(strSys,"\\comctl32.dll");
	hLib = LoadLibrary(strSys);

	hInst = hInstance;
	hwnd = CreateDialog(hInstance, "DIAL", 0, NULL);
	hGWnd=hwnd;
	
	TabCtrlItem.mask = TCIF_TEXT;
    TabCtrlItem.pszText = "电话拨号";
	TabCtrl_InsertItem(GetDlgItem(hwnd,IDC_DIALTAB), 0, &TabCtrlItem );
    TabCtrlItem.pszText = "模拟呼出";
	TabCtrl_InsertItem(GetDlgItem(hwnd,IDC_DIALTAB), 1, &TabCtrlItem );
    TabCtrlItem.pszText = "单机自测";
	TabCtrl_InsertItem(GetDlgItem(hwnd,IDC_DIALTAB), 2, &TabCtrlItem );
	//create the detail pages
	FARPROC lpProc;
	lpProc = MakeProcInstance((FARPROC)TelephoneWndProc, hInstance);
	hPropPage[0] = CreateDialog(hInstance,"TELEPHONE",GetDlgItem(hwnd,IDC_DIALTAB),(DLGPROC)lpProc);
	lpProc = MakeProcInstance((FARPROC)SimulateWndProc, hInstance);
	hPropPage[1]  = CreateDialog(hInstance,"SIMULATE",GetDlgItem(hwnd,IDC_DIALTAB),(DLGPROC)lpProc);
	lpProc = MakeProcInstance((FARPROC)SelfWndProc, hInstance);
	hPropPage[2]  = CreateDialog(hInstance,"SELF",GetDlgItem(hwnd,IDC_DIALTAB),(DLGPROC)lpProc);

	GetWindowRect(GetDlgItem(hwnd,IDC_DIALTAB),&rect);
	width=rect.right-rect.left;
	height=rect.bottom-rect.top;
	width-=20;
	height-=40;
	MoveWindow(hPropPage[0] ,10,30,width,height,true);
	MoveWindow(hPropPage[1] ,10,30,width,height,true);
	MoveWindow(hPropPage[2] ,10,30,width,height,true);

	SetWindowText(GetDlgItem(hPropPage[1],IDC_CODEEDIT),"12345");
	SetWindowText(GetDlgItem(hPropPage[2],IDC_CODEEDIT1),"12345");

	ShowWindow (hwnd, nCmdShow);
	hVisable=hPropPage[0] ;
	ShowWindow(hVisable,nCmdShow);

	bHaveLoadDriver=yzInitSystem();
	if(!bHaveLoadDriver) PostQuitMessage(0);

	UpdateWindow(hwnd);

	lpProc = MakeProcInstance((FARPROC)TimerProc, hInstance);
	SetTimer(hwnd,ID_TIME,100,(TIMERPROC)lpProc);
	nDialType=0;
	///////////////////////////////////////////////////////////////
	while (GetMessage(&msg, NULL, 0, 0)) 
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}
	return msg.wParam;
}
VOID CALLBACK TimerProc(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime)
{ 
	if(idEvent!=ID_TIME) return;
	if(nDialType==0) 
	{
		yzDoTrunkWork0();
		yzDoUserWork();
	}
	else if(nDialType==1) yzDoTrunkWork1();
	else if(nDialType==2) yzDoTrunkWork2();
}

/////////////////////////////////////////////////////////////////////////
//WndProc
//
//Purpose: The window procedure
//
//Parameters: HWND hwnd, UINT message, UINT wParam, LONG lParam
//
//Returns: long
///////////////////////////////////////////////////////////////////////////  
long PASCAL WndProc (HWND hwnd,UINT message, UINT wParam,LONG lParam)
{
	if(( message == WM_NOTIFY)&&(wParam==1016))
	{
		ChangeShowPage();
	}
	
	switch(message)
	{
		
		HANDLE_MSG(hwnd, WM_DESTROY, Dial_OnDestroy);
		HANDLE_MSG(hwnd, WM_ACTIVATE, Dial_OnActivate);
		HANDLE_MSG(hwnd,WM_PAINT,Dial_OnPaint);
		HANDLE_MSG(hwnd, WM_COMMAND, Dial_OnCommand);
		HANDLE_MSG(hwnd,WM_INITDIALOG,Dial_OnInitDialog);
	default:
			return DefWindowProc (hwnd, message, wParam, lParam);
	}
}
void Dial_OnActivate(
	HWND hwnd,
	UINT state,
	HWND hwndActDeact,
	BOOL fMinimized)

{
	return;
}

void Dial_OnDestroy(HWND hwnd)
{
	if(bHaveLoadDriver) yzExitSystem();
	KillTimer(hwnd,ID_TIME);
	PostQuitMessage (0);
}
void Dial_OnPaint( HWND hWnd) 
{ 
	PAINTSTRUCT ps; 
	HDC hDC;
    RECT rc;

    GetClientRect(hWnd, &rc);
    
    hDC = BeginPaint(hWnd, &ps);
	FillRect(hDC,&rc,(HBRUSH)GetStockObject(LTGRAY_BRUSH ));
    EndPaint(hWnd, &ps);
}

void Dial_OnCommand(HWND hwnd,int id,HWND hwndCtl,UINT codeNotify)
{
	
	if(id==IDC_EXITBUTTON)
	{
		if(bHaveLoadDriver) yzExitSystem();
		PostQuitMessage(0);
	}
}						   
BOOL Dial_OnInitDialog(HWND hwnd,HWND hwndFocus,long lInitParam)
{
	return (FALSE);
}
void ChangeShowPage()
{
	int nSel;
	nSel=TabCtrl_GetCurSel(GetDlgItem(hGWnd,IDC_DIALTAB));
	if(hVisable==hPropPage[nSel]) return;
	if(hVisable!=NULL)
	{
		KillTimer(hGWnd,ID_TIME);
		yzResetProcedure();
		ShowWindow(hVisable,SW_HIDE);
		ShowWindow(hPropPage[nSel],SW_SHOWNA);
		hVisable=hPropPage[nSel];
		FARPROC lpProc = MakeProcInstance((FARPROC)TimerProc, hInstance);
		nDialType=nSel;
		yzSetChannelType();
		SetTimer(hGWnd,ID_TIME,100,(TIMERPROC)lpProc); 
	}
}
long PASCAL TelephoneWndProc (HWND hwnd,UINT message,UINT wParam,LONG lParam)
{
	WORD wID;
	if(message!=WM_COMMAND) return DefWindowProc (hPropPage[0], message, wParam, lParam);
	wID = LOWORD(wParam);
	return 0;
}
long PASCAL SimulateWndProc (HWND hwnd,UINT message,UINT wParam,LONG lParam)
{
	WORD wID;
	if(message!=WM_COMMAND) return DefWindowProc (hPropPage[1], message, wParam, lParam);;
	wID = LOWORD(wParam);
	if(wID==IDC_DIALBUTTON)
	{
		char buf[20];
		int nLength;
		char buf1[20];
		nLength=0;
		GetWindowText(GetDlgItem(hwnd,IDC_CODEEDIT),buf,20);
		for(int i=0;i<20;i++)
		{
			if( ((buf[i]>='0')&&(buf[i]<='9')) 
				|| (buf[i]=='*') 
				|| (buf[i]=='#') 
				|| (buf[i]==',') 
				|| ((buf[i]>='a')&&(buf[i]<='f')) 
				|| ((buf[i]>='A')&&(buf[i]<='F')) )
			{
				buf1[nLength]=buf[i];
				nLength++;
			}
			if(buf[i]==0) break;
		}
		if(nLength==20) nLength=19;
		buf1[nLength]=0;

		if(nLength<DialData.DialLen) MessageBox(NULL,"被叫号码长度不够!","Error",MB_OK);
		else
		{
			SetWindowText(GetDlgItem(hwnd,IDC_CODEEDIT),buf1);
			yzCallOut(buf1);			
		}
	}
	return 0;
}
long PASCAL SelfWndProc (HWND hwnd,UINT message,UINT wParam,LONG lParam)
{
	WORD wID;
	if(message!=WM_COMMAND) return DefWindowProc (hPropPage[2], message, wParam, lParam);;
	wID = LOWORD(wParam);
	if(wID==IDC_DIALBUTTON1)
	{
		if(TotalTrunk<60)
		{
			MessageBox(NULL,"少于60个通道,不支持单机测试.","Note",MB_OK);
			return 0;
		}
		char buf[20];
		int nLength;
		char buf1[20];
		nLength=0;
		GetWindowText(GetDlgItem(hwnd,IDC_CODEEDIT1),buf,20);
		for(int i=0;i<20;i++)
		{
			if( ((buf[i]>='0')&&(buf[i]<='9')) 
				|| (buf[i]=='*') 
				|| (buf[i]=='#') 
				|| (buf[i]==',') 
				|| ((buf[i]>='a')&&(buf[i]<='f')) 
				|| ((buf[i]>='A')&&(buf[i]<='F')) )
			{
				buf1[nLength]=buf[i];
				nLength++;
			}
			if(buf[i]==0) break;
		}
		if(nLength==20) nLength=19;
		buf1[nLength]=0;

		if(nLength<DialData.DialLen) MessageBox(NULL,"被叫号码长度不够!","Error",MB_OK);
		else
		{
			SetWindowText(GetDlgItem(hwnd,IDC_CODEEDIT1),buf1);
			yzCallOut(buf1);			
		}
		
	}
	return 0;
}

⌨️ 快捷键说明

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