?? cedialer.c
字號(hào):
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//
// Use of this source code is subject to the terms of the Microsoft end-user
// license agreement (EULA) under which you licensed this SOFTWARE PRODUCT.
// If you did not accept the terms of the EULA, you are not authorized to use
// this source code. For a copy of the EULA, please see the LICENSE.RTF on your
// install media.
//
/***********************************************************************
MODULE:
CeDialer.c
ABSTRACT:
This code sample shows how to initialize an application's use
of TAPI, open a line device, negotiate an API version to use,
translate an address into another format, place a call on an
opened line device, close an opened line device, and shut down
an application's use of the line abstraction of the API.
FUNCTIONS:
ConnectUsingProc - Processes messages sent to IDD_CONNECTUSING dialog.
CurrentLineClose - Closes the opened line device.
DialerDlgProc - Processes messages sent to IDD_CEDIALER dialog.
DialingProc - Processes messages sent to IDD_DIALING dialog.
GetLineInfo - Get line information for selected line.
InitAddrCB - Fills address list box on IDD_CONNECTUSING dialog.
InitApplication - Initializes application.
InitializeTAPI - Initializes the application's use of the Tapi.dll.
InitInstance - Instance initialization.
InitLineCB - Fills line list box on IDD_CONNECTUSING dialog.
lineCallbackFunc - Monitors line and call status.
MainWndProc - Processes messages sent to the main window.
MakeCanonicalNum - Converts phone number to canonical address format.
MakePhoneCall - Demonstrates the use of TAPI call functions.
WinMain - Application entry point and initialization.
***********************************************************************/
// 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 TAPI_CURRENT_VERSION TAPI_VERSION_2_0
#define REASONABLE_BUFFER_SIZE 512
#include <windows.h>
#include <aygshell.h>
#include <tapi.h>
#include <strsafe.h>
#include "resource.h"
#include "CeDialer.h"
HINSTANCE g_hInst = NULL; // hInstance of the application
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 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'
// information
#define ErrorBox(_s) MessageBox(g_hwndDialerDlg,_s, \
TEXT("CeDialer Message"),MB_OK)
#define MENU_HEIGHT 26 // Height of menu bar at screen bottom
// Purpose: Determine at runtime if the app is running on a smartphone device
static BOOL IsSmartphone()
{
TCHAR tszPlatform[64];
if (TRUE == SystemParametersInfo(SPI_GETPLATFORMTYPE,
sizeof(tszPlatform)/sizeof(*tszPlatform),tszPlatform,0))
{
if (0 == _tcsicmp(TEXT("Smartphone"), tszPlatform))
{
return TRUE;
}
}
return FALSE;
}
/***********************************************************************
FUNCTION:
DialerDlgProc
PURPOSE:
Processes messages sent to the IDD_CEDIALER dialog box.
***********************************************************************/
BOOL CALLBACK DialerDlgProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch (uMsg)
{
case WM_HOTKEY:
{
UINT uVirt;
//handle "Back" key
uVirt = HIWORD(lParam);
if (uVirt == VK_TBACK)
{
SendMessage(GetDlgItem (hwnd, IDC_PHONENUM), WM_CHAR, VK_BACK, 0);
}
break;
}
case WM_INITDIALOG:
{
SHINITDLGINFO shidi;
SHMENUBARINFO mbi;
g_hwndDialerDlg = hwnd;
// Create OK button in navigation bar and size dialog.
shidi.dwMask = SHIDIM_FLAGS;
shidi.dwFlags = SHIDIF_DONEBUTTON | SHIDIF_SIPDOWN |
SHIDIF_SIZEDLGFULLSCREEN;
shidi.hDlg = hwnd;
SHInitDialog(&shidi);
if (IsSmartphone() == TRUE)
{
memset(&mbi, 0, sizeof(SHMENUBARINFO));
mbi.cbSize = sizeof(SHMENUBARINFO);
mbi.hwndParent = hwnd;
mbi.nToolBarId = IDR_SPMENU;
mbi.hInstRes = g_hInst;
mbi.nBmpId = 0;
mbi.cBmpImages = 0;
if (SHCreateMenuBar(&mbi) == 0)
return FALSE;
}
// ignore the phone key
SendMessage(mbi.hwndMB, SHCMBM_OVERRIDEKEY, VK_TTALK,
MAKELPARAM(SHMBOF_NODEFAULT | SHMBOF_NOTIFY,
SHMBOF_NODEFAULT | SHMBOF_NOTIFY));
// reroute Back key to WM_HOTKEY handler
SendMessage(mbi.hwndMB, SHCMBM_OVERRIDEKEY, VK_TBACK,
MAKELPARAM(SHMBOF_NODEFAULT | SHMBOF_NOTIFY,
SHMBOF_NODEFAULT | SHMBOF_NOTIFY));
// Limit text in phone number field to TAPIMAXDESTADDRESSSIZE.
SendDlgItemMessage (hwnd, IDC_PHONENUM, CB_LIMITTEXT,
(WPARAM)TAPIMAXDESTADDRESSSIZE, 0);
// Initialize the application's use of Tapi.dll. If the function
// fails, terminate the application.
if (InitializeTAPI ())
{
ErrorBox (TEXT("Intilization of Tapi.dll failed."));
if (g_hLineApp)
lineShutdown (g_hLineApp);
DestroyWindow (hwnd);
}
return TRUE;
}
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case IDM_QUIT:
EndDialog(hwnd, IDOK);
break;
case IDM_SELECTLINE:
case IDC_SELECTLINE:
DialogBox (g_hInst,
MAKEINTRESOURCE(IDD_CONNECTUSING),
hwnd,
(DLGPROC) ConnectUsingProc);
return TRUE;
case IDM_DIAL:
case IDC_DIAL:
{
// Check if there is a number entered.
if (SendDlgItemMessage (hwnd,
IDC_PHONENUM,
WM_GETTEXTLENGTH, 0, 0) > 0)
{
// Set the current line if it is not already set.
if (g_dwCurrentLineID == -1)
{
DialogBox (g_hInst,
MAKEINTRESOURCE(IDD_CONNECTUSING),
hwnd,
(DLGPROC) ConnectUsingProc);
}
// Get the number to be dialed.
GetDlgItemText (hwnd,
IDC_PHONENUM,
(LPTSTR) g_szCurrentNum,
TAPIMAXDESTADDRESSSIZE);
// Convert the phone number into a canonical format.
if (!MakeCanonicalNum (g_szCurrentNum))
return TRUE;
// Make the call.
MakePhoneCall (g_szCurrentNum);
// Set the focus on the phone number Edit control.
SetFocus (GetDlgItem (hwnd, IDC_PHONENUM));
// Select the phone number once it is dialed.
SendDlgItemMessage (hwnd, IDC_PHONENUM, EM_SETSEL, 0, -1);
// Save the phone number in the g_szLastNum string.
lstrcpy (g_szLastNum, g_szCurrentNum);
}
return TRUE;
}
case IDC_BUTTON1:
case IDC_BUTTON2:
case IDC_BUTTON3:
case IDC_BUTTON4:
case IDC_BUTTON5:
case IDC_BUTTON6:
case IDC_BUTTON7:
case IDC_BUTTON8:
case IDC_BUTTON9:
case IDC_BUTTON0:
case IDC_BUTTONSTAR:
case IDC_BUTTONPOUND:
{
int iNumOfDigits = 0;
TCHAR *lpszBuffer;
static const TCHAR digits[] = {'1', '2', '3', '4',
'5', '6', '7', '8',
'9', '0', '*', '#'};
lpszBuffer = (TCHAR *)LocalAlloc (LPTR,
(TAPIMAXDESTADDRESSSIZE + 1) * sizeof(TCHAR));
// Clear the current selection.
SendDlgItemMessage (hwnd, IDC_PHONENUM, WM_CLEAR, 0, 0);
iNumOfDigits = SendDlgItemMessage (
hwnd,
IDC_PHONENUM,
WM_GETTEXT,
(WPARAM)TAPIMAXDESTADDRESSSIZE + 1,
(LPARAM)lpszBuffer);
if (iNumOfDigits < TAPIMAXDESTADDRESSSIZE)
{
lpszBuffer[iNumOfDigits] =
digits[LOWORD(wParam) - IDC_BUTTON1];
SendDlgItemMessage (hwnd, IDC_PHONENUM, WM_SETTEXT, 0,
(LPARAM)lpszBuffer);
}
LocalFree (lpszBuffer);
return TRUE;
}
case IDOK:
if (g_lpLineInfo)
LocalFree (g_lpLineInfo);
lineShutdown (g_hLineApp);
DestroyWindow (hwnd);
PostQuitMessage (0);
return TRUE;
}
break;
}
//case WM_DESTROY:
// PostQuitMessage (0);
// return TRUE;
}
return FALSE;
}
/***********************************************************************
FUNCTION:
MainWndProc
PURPOSE:
Processes messages sent to the main window.
***********************************************************************/
BOOL CALLBACK MainWndProc(
HWND hwnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
)
{
switch (uMsg)
{
case WM_CREATE:
// Create dialer dialog box.
DialogBox (g_hInst,
MAKEINTRESOURCE(IDD_CEDIALER),
hwnd,
(DLGPROC) DialerDlgProc);
break;
case WM_DESTROY:
DestroyWindow(g_hwndDialerDlg);
PostQuitMessage (0);
return TRUE;
default:
return DefWindowProc (hwnd, uMsg, wParam, lParam);
}
return FALSE;
}
/***********************************************************************
FUNCTION:
InitInstance
PURPOSE:
Instance initialization.
***********************************************************************/
BOOL InitInstance(
HINSTANCE hInstance,
int nCmdShow
)
{
g_hInst = hInstance;
if (IsSmartphone())
{
DialogBox (g_hInst,
MAKEINTRESOURCE(IDD_CEDIALER_SP),
NULL,
(DLGPROC) DialerDlgProc);
}
else
{
DialogBox (g_hInst,
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -