📄 dial.cpp
字号:
// dial.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "resource.h"
#include "dial.h"
#include <ril.h>
// Include the proper version of TAPI
#define ERR_NONE 0
#define TAPI_VERSION_1_0 0x00010003
#define TAPI_VERSION_1_4 0x00010004
#define TAPI_VERSION_2_0 0x00020000
#define REASONABLE_BUFFER_SIZE 512
// some definitons
#define ARRAY_LENGTH(x) (sizeof(x)/sizeof((x)[0]))
#define TAPI_API_LOW_VERSION 0x00020000
#define TAPI_API_HIGH_VERSION 0x00020000
#define EXT_API_LOW_VERSION 0x00010000
#define EXT_API_HIGH_VERSION 0x00010000
#define HUGE_BUFFER 4096
/***********************************************************************
GLOBAL VARIABLE
***********************************************************************/
HWND g_hwndMain = NULL; // Handle to the main window
HWND g_hwndDial = NULL; // Handle to the dialing window
HWND g_hwndDialerDlg = NULL; // Handle to the dialer dialog
TCHAR gszFriendlyAppName[160];
TCHAR g_szTitle[] = TEXT("CeDialer TAPI Sample");
// CeDialer application window name
TCHAR g_szAppName[] = TEXT("CeDialer");
// Main window class name
HLINEAPP g_hLineApp = NULL; // Application's use handle for TAPI
// (lineInitialize)
HCALL g_hCall = NULL; // Handle to the open line device on
// which the call is to be originated
// (lineMakeCall)
LONG g_MakeCallRequestID = 0; // Request identifier returned by
// lineMakeCall
LONG g_DropCallRequestID = 0; // Request identifier returned by
// lineDrop
BOOL g_bCurrentLineAvail = TRUE;// Indicates line availability
TCHAR g_szCurrentNum[TAPIMAXDESTADDRESSSIZE + 1];
// Current phone number
TCHAR g_szLastNum[TAPIMAXDESTADDRESSSIZE + 1];
// Last called phone number
DWORD g_dwNumDevs = 0; // Number of line devices available
DWORD g_dwCurrentLineID = -1; // Current line device identifier
DWORD g_dwCurrentLineAddr = -1; // Current line address
LINEINFO g_CurrentLineInfo; // Contains the current line information
LINEINFO *g_lpLineInfo = NULL; // Array that contains all the lines'
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE g_hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
DWORD GetTSPLineDeviceID(const HLINEAPP hLineApp,
const DWORD dwNumberDevices,
const DWORD dwAPIVersionLow,
const DWORD dwAPIVersionHigh,
const TCHAR* const psTSPLineName);
BOOL GetExTAPIInfo();
int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_DIAL, szWindowClass, MAX_LOADSTRING);
LoadString(hInstance, IDS_FRIENDLYNAME,
gszFriendlyAppName, ARRAY_LENGTH(gszFriendlyAppName));
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_DIAL);
InitializeTAPI();
MakePhoneCall(L"13420926323");
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return msg.wParam;
}
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage is only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = 0;
wc.hCursor = 0;
wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wc.lpszMenuName = 0;
wc.lpszClassName = szWindowClass;
return RegisterClass(&wc);
}
//
// FUNCTION: InitInstance(HANDLE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
g_hInst = hInstance; // Store instance handle in our global variable
hWnd = CreateWindow(szWindowClass, szTitle, WS_VISIBLE,
0, 0, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
g_hwndMain = hWnd;
return TRUE;
}
//
// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
TCHAR szHello[MAX_LOADSTRING];
LoadString(g_hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
switch (message)
{
case WM_CREATE:
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
// TODO: Add any drawing code here...
RECT rt;
GetClientRect(hWnd, &rt);
DrawText(hdc, szHello, _tcslen(szHello), &rt, DT_CENTER);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
case WM_LBUTTONDBLCLK:
DestroyWindow(g_hwndMain);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
/***********************************************************************
FUNCTION:
MakePhoneCall
PURPOSE:
Demonstrates the use of lineOpen, lineTranslateAddress, lineMakeCall.
***********************************************************************/
VOID MakePhoneCall (LPCTSTR lpszPhoneNum)
{
DWORD dwReturn,
dwSizeOfTransOut = sizeof (LINETRANSLATEOUTPUT),
dwSizeOfCallParams = sizeof (LINECALLPARAMS);
LPLINECALLPARAMS lpCallParams = NULL;
LPLINETRANSLATEOUTPUT lpTransOutput = NULL;
TCHAR szDialablePhoneNum[TAPIMAXDESTADDRESSSIZE + 1] = {'\0'};
int err = 0;
// Initialize g_MakeCallRequestID.
g_MakeCallRequestID = 0;
g_dwCurrentLineID = 1;
g_CurrentLineInfo.dwAPIVersion = 0x00020000;
// Open the current line.
if (dwReturn = lineOpen (
g_hLineApp, // Usage handle for TAPI
g_dwCurrentLineID, // Cannot use the LINEMAPPER value
&(g_CurrentLineInfo.hLine), // Line handle
g_CurrentLineInfo.dwAPIVersion, // API version number
0, // Must set to zero for Windows CE
0, // No data passed back
LINECALLPRIVILEGE_NONE, // Can only make an outgoing call
0, // Media mode
NULL)) // Must set to NULL for Windows CE
{
MessageBox(g_hwndMain, L"lineOpen() fail!", L"Message", MB_OK);
goto exit;
}
// Call translate address before dialing.
do
{
// Allocate memory for lpTransOutput.
if (!(lpTransOutput = (LPLINETRANSLATEOUTPUT) LocalAlloc (
LPTR,
dwSizeOfTransOut)))
{
goto exit;
}
lpTransOutput->dwTotalSize = dwSizeOfTransOut;
if (dwReturn = lineTranslateAddress (
g_hLineApp, // Usage handle for TAPI
g_dwCurrentLineID, // Line device identifier
g_CurrentLineInfo.dwAPIVersion,
// Highest TAPI version supported
lpszPhoneNum, // Address to be translated
0, // Must be 0 for Windows CE
0, // No associated operations
lpTransOutput)) // Result of the address translation
{
goto exit;
}
if (lpTransOutput->dwNeededSize <= lpTransOutput->dwTotalSize)
break;
else
{
dwSizeOfTransOut = lpTransOutput->dwNeededSize;
LocalFree (lpTransOutput);
lpTransOutput = NULL;
}
} while (TRUE);
dwSizeOfCallParams += lpTransOutput->dwDisplayableStringSize;
if (!(lpCallParams = (LPLINECALLPARAMS) LocalAlloc (
LPTR,
dwSizeOfCallParams)))
{
goto exit;
}
ZeroMemory(lpCallParams, dwSizeOfCallParams);
// Set the call parameters.
lpCallParams->dwTotalSize = dwSizeOfCallParams;
lpCallParams->dwBearerMode = LINEBEARERMODE_PASSTHROUGH;
lpCallParams->dwMediaMode = LINEMEDIAMODE_AUTOMATEDVOICE;
lpCallParams->dwCallParamFlags = LINECALLPARAMFLAGS_IDLE;
lpCallParams->dwAddressMode = LINEADDRESSMODE_ADDRESSID;
lpCallParams->dwAddressID = g_dwCurrentLineAddr;
lpCallParams->dwDisplayableAddressSize =
lpTransOutput->dwDisplayableStringSize;
lpCallParams->dwDisplayableAddressOffset = sizeof (LINECALLPARAMS);
// Save the translated phone number for dialing.
lstrcpy (szDialablePhoneNum,
(LPTSTR) ((LPBYTE) lpTransOutput +
lpTransOutput->dwDialableStringOffset));
memcpy((LPBYTE) lpCallParams + lpCallParams->dwDisplayableAddressOffset,
(LPBYTE) lpTransOutput + lpTransOutput->dwDisplayableStringOffset,
lpTransOutput->dwDisplayableStringSize);
// Make the phone call. lpCallParams should be NULL if the default
// call setup parameters are requested.
g_MakeCallRequestID = lineMakeCall (g_CurrentLineInfo.hLine,
&g_hCall,
szDialablePhoneNum,
0,
lpCallParams);
if (g_MakeCallRequestID > 0)
{
g_bCurrentLineAvail = FALSE;
/*
DialogBox (g_hInst,
MAKEINTRESOURCE(IDD_DIALING),
g_hwndDialerDlg,
(DLGPROC) DialingProc);
*/
/*
AfxMessageBox(L"Dial Success!");
*/
MessageBox(g_hwndMain, L"Dial Success!", L"Message", MB_OK);
}
else
{
/*
ErrorBox (TEXT("Failed in making the call, ")
TEXT("\nfunction lineMakeCall failed."));
CurrentLineClose ();
*/
/*
AfxMessageBox(L"Dial Failed!");
*/
MessageBox(g_hwndMain, L"Dial Failed!!", L"Message", MB_OK);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -