📄 cedialer.c
字号:
dwSizeOfTransOut = sizeof (LINETRANSLATEOUTPUT),
dwSizeOfCallParams = sizeof (LINECALLPARAMS);
LPLINECALLPARAMS lpCallParams = NULL;
LPLINETRANSLATEOUTPUT lpTransOutput = NULL;
TCHAR szDialablePhoneNum[TAPIMAXDESTADDRESSSIZE + 1] = {'\0'};
// Initialize g_MakeCallRequestID.
g_MakeCallRequestID = 0;
// 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
{
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;
}
// Set the call parameters.
lpCallParams->dwTotalSize = dwSizeOfCallParams;
lpCallParams->dwBearerMode = LINEBEARERMODE_VOICE;
lpCallParams->dwMediaMode = LINEMEDIAMODE_DATAMODEM;
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)((LPSTR)lpTransOutput + \
lpTransOutput->dwDisplayableStringOffset));
// Set the cursor as the wait cursor.
SetCursor (LoadCursor (NULL, IDC_WAIT));
// 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);
// Set the cursor back to an arrow.
SetCursor (0);
if (g_MakeCallRequestID > 0)
{
g_bCurrentLineAvail = FALSE;
DialogBoxParam (g_hInst,
MAKEINTRESOURCE(IDD_DIALING),
g_hwndMain,
(DLGPROC) DialingProc, 0);
}
else
{
ErrorBox (TEXT("Failed in making the phone call, function")
TEXT("\nlineMakeCall failed."));
CurrentLineClose ();
}
exit :
if (lpCallParams)
LocalFree (lpCallParams);
if (lpTransOutput)
LocalFree (lpTransOutput);
// If the make call did not succeed but the line was opened,
// then close it.
if ((g_MakeCallRequestID <= 0) && (g_CurrentLineInfo.hLine))
CurrentLineClose ();
return;
}
/***********************************************************************
ConnectUsingProc
***********************************************************************/
BOOL CALLBACK ConnectUsingProc (HWND hwnd, UINT uMsg, WPARAM wParam,
LPARAM lParam)
{
switch (uMsg)
{
case WM_INITDIALOG:
{
// Get the list of lines into the line list box.
InitLineCB (GetDlgItem (hwnd, IDC_LISTLINES),
g_dwCurrentLineID,
g_dwNumDevs);
// Get the list of addresses into the address list box.
InitAddrCB (GetDlgItem (hwnd, IDC_LISTLINES),
GetDlgItem (hwnd, IDC_LISTADDRESSES),
g_dwCurrentLineID,
g_dwCurrentLineAddr);
return TRUE;
}
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case IDC_LISTLINES:
if (HIWORD(wParam) == CBN_SELENDOK)
{
// Update the address box.
InitAddrCB (GetDlgItem (hwnd, IDC_LISTLINES),
GetDlgItem (hwnd, IDC_LISTADDRESSES),
g_dwCurrentLineID,
g_dwCurrentLineAddr);
}
break;
case IDOK:
{
long lIndex;
lIndex = SendDlgItemMessage (hwnd,
IDC_LISTLINES,
CB_GETCURSEL, 0, 0);
// Update the current line identifier.
g_dwCurrentLineID = SendDlgItemMessage (
hwnd,
IDC_LISTLINES,
CB_GETITEMDATA,
(WPARAM) lIndex, 0);
lIndex = SendDlgItemMessage (hwnd,
IDC_LISTADDRESSES,
CB_GETCURSEL, 0, 0);
// Update the current address for the current line.
g_dwCurrentLineAddr = SendDlgItemMessage (
hwnd,
IDC_LISTADDRESSES,
CB_GETITEMDATA,
(WPARAM) lIndex, 0);
// Assign the g_CurrentLineInfo.
g_CurrentLineInfo = g_lpLineInfo [g_dwCurrentLineID];
}
case IDCANCEL:
EndDialog (hwnd, FALSE);
return TRUE;
}
}
}
return FALSE;
}
/***********************************************************************
InitLineCB
***********************************************************************/
BOOL InitLineCB (HWND hwndLineCB, DWORD dwCurrentLine, DWORD dwNumOfDev)
{
DWORD dwItem,
dwLineID,
dwCurrentItem = (DWORD)-1;
// Empty the line combo box.
SendMessage (hwndLineCB, CB_RESETCONTENT, 0, 0);
// Add the device name strings.
for (dwLineID = 0; dwLineID < dwNumOfDev; ++dwLineID)
{
// Add the line name string to the list box of the line combo box.
dwItem = SendMessage (hwndLineCB,
CB_ADDSTRING,
0,
(LPARAM)(g_lpLineInfo[dwLineID].szLineName));
if (dwItem == CB_ERR || dwItem == CB_ERRSPACE)
return FALSE;
// Set the dwLineID associated with the dwItem item.
SendMessage (hwndLineCB, CB_SETITEMDATA, (WPARAM)dwItem,
(LPARAM)dwLineID);
if (dwLineID == dwCurrentLine)
dwCurrentItem = dwItem;
else
{
// If the item we are putting is before the current item, we
// must increment dwCurrentItem to reflect that an item is
// being placed before it, due to sorting.
if (dwCurrentItem != -1 && dwItem <= dwCurrentItem)
++dwCurrentItem;
}
}
if (dwCurrentItem == (DWORD)-1)
dwCurrentItem = 0;
// Select the dwCurrentItem item in the list box of the line
// combo box.
if (SendMessage (hwndLineCB, CB_GETCOUNT, 0, 0) != 0)
{
SendMessage (hwndLineCB, CB_SETCURSEL, (WPARAM)dwCurrentItem, 0);
return TRUE;
}
return FALSE;
}
/***********************************************************************
InitAddrCB
***********************************************************************/
BOOL InitAddrCB (HWND hwndLineCB, HWND hwndAddrCB,
DWORD dwCurrentLine, DWORD dwCurrentAddr)
{
DWORD dwAddr,
dwItem,
dwCurrentItem = (DWORD)-1,
dwLineCBCurrent;
TCHAR szAddrName[512];
if (SendMessage (hwndLineCB, CB_GETCOUNT, 0, 0) == 0)
return FALSE;
// Empty the address list box.
SendMessage (hwndAddrCB, CB_RESETCONTENT, 0, 0);
// Select the current entry in the line box.
dwLineCBCurrent = SendMessage (
hwndLineCB,
CB_GETITEMDATA,
SendMessage (hwndLineCB, CB_GETCURSEL, 0, 0),
0);
// Get all the addresses for this line.
for (dwAddr = 0;
dwAddr < g_lpLineInfo [dwLineCBCurrent].dwNumOfAddress; ++dwAddr)
{
wsprintf (szAddrName, TEXT("Address %d"), dwAddr);
// Add the address name string to the list box of the address
// combo box.
dwItem = SendMessage (hwndAddrCB, CB_ADDSTRING, 0,
(LPARAM)szAddrName);
if (dwItem == CB_ERR || dwItem == CB_ERRSPACE)
return FALSE;
// Set the dwAddr associated with the dwItem item.
SendMessage (hwndAddrCB, CB_SETITEMDATA, (WPARAM)dwItem,
(LPARAM)dwAddr);
if (dwLineCBCurrent == dwCurrentLine)
{
if (dwAddr == dwCurrentAddr)
dwCurrentItem = dwItem;
else
{
// If the item we are putting is before the current item, we
// must increment dwItemCur to reflect that an item is being
// placed before it, due to sorting.
if (dwCurrentItem != -1 && dwItem <= dwCurrentItem)
++dwCurrentItem;
}
}
}
if (dwLineCBCurrent != dwCurrentLine || dwCurrentItem == (DWORD)-1)
dwCurrentItem = 0;
// Select the dwCurrentItem item in the list box of the line
// combo box.
if (SendMessage (hwndAddrCB, CB_GETCOUNT, 0, 0) != 0)
{
SendMessage (hwndAddrCB, CB_SETCURSEL, (WPARAM)dwCurrentItem, 0);
return TRUE;
}
return FALSE;
}
/***********************************************************************
MakeCanonicalNum
***********************************************************************/
BOOL MakeCanonicalNum (LPTSTR lpszPhoneNum)
{
int index,
iLength = 0,
iStartPos = 0;
TCHAR szCanPhoneNum[TAPIMAXDESTADDRESSSIZE + 1];
for (index = 0; index < (int) wcslen (lpszPhoneNum); ++index)
{
if (iswdigit (lpszPhoneNum[index]))
{
lpszPhoneNum[iLength] = lpszPhoneNum[index];
iLength += 1;
}
}
// Terminate the string with NULL.
lpszPhoneNum[iLength] = '\0';
// If the first number is 1, reduce the phone number length by 1.
if (lpszPhoneNum[0] == '1')
{
iLength -= 1;
iStartPos = 1;
}
// If the phone number length is less than 7, return FALSE.
if (iLength < 7)
{
if (iLength == 6 && iStartPos == 1)
{
ErrorBox (TEXT("The first digit can not be 1 for a ")
TEXT("\nlocal phone number."));
return FALSE;
}
ErrorBox (TEXT("There should be at least 7 digits for")
TEXT("\na local phone number."));
return FALSE;
}
if (iLength == 7)
{
//Make the phone number in the format "+1 (xxx) xxx-xxxx"
wcscpy (szCanPhoneNum, TEXT("+1 (425) "));
szCanPhoneNum[9] = lpszPhoneNum[iStartPos];
szCanPhoneNum[10] = lpszPhoneNum[iStartPos + 1];
szCanPhoneNum[11] = lpszPhoneNum[iStartPos + 2];
szCanPhoneNum[12] = '-';
szCanPhoneNum[13] = lpszPhoneNum[iStartPos + 3];
szCanPhoneNum[14] = lpszPhoneNum[iStartPos + 4];
szCanPhoneNum[15] = lpszPhoneNum[iStartPos + 5];
szCanPhoneNum[16] = lpszPhoneNum[iStartPos + 6];
szCanPhoneNum[17] = '\0';
// Copy the newly created phone number back to lpszPhoneNum.
wcscpy (lpszPhoneNum, szCanPhoneNum);
return TRUE;
}
if (iLength == 10)
{
//Make the phone number in the format "+1 (xxx) xxx-xxxx"
wcscpy (szCanPhoneNum, TEXT("+1 ("));
szCanPhoneNum[4] = lpszPhoneNum[iStartPos];
szCanPhoneNum[5] = lpszPhoneNum[iStartPos + 1];
szCanPhoneNum[6] = lpszPhoneNum[iStartPos + 2];
szCanPhoneNum[7] = ')';
szCanPhoneNum[8] = ' ';
szCanPhoneNum[9] = lpszPhoneNum[iStartPos + 3];
szCanPhoneNum[10] = lpszPhoneNum[iStartPos + 4];
szCanPhoneNum[11] = lpszPhoneNum[iStartPos + 5];
szCanPhoneNum[12] = '-';
szCanPhoneNum[13] = lpszPhoneNum[iStartPos + 6];
szCanPhoneNum[14] = lpszPhoneNum[iStartPos + 7];
szCanPhoneNum[15] = lpszPhoneNum[iStartPos + 8];
szCanPhoneNum[16] = lpszPhoneNum[iStartPos + 9];
szCanPhoneNum[17] = '\0';
// Copy the newly created phone number back to lpszPhoneNum.
wcscpy (lpszPhoneNum, szCanPhoneNum);
return TRUE;
}
ErrorBox (TEXT("This is not a valid phone number, please check the\n")
TEXT("phone number and enter again."));
return FALSE;
}
// END CEDIALER.C
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -