📄 cedialer.c
字号:
lpszStatus = TEXT("Ringing");
break;
case LINEDEVSTATE_OUTOFSERVICE:
ErrorBox (TEXT("The line selected is out of service."));
CurrentLineClose ();
if (g_hwndDial)
SendMessage (g_hwndDial, WM_COMMAND, MAKEWPARAM(IDOK,0), 0);
break;
case LINEDEVSTATE_DISCONNECTED:
ErrorBox (TEXT("The line selected is disconnected."));
CurrentLineClose ();
if (g_hwndDial)
SendMessage (g_hwndDial, WM_COMMAND, MAKEWPARAM(IDOK,0), 0);
break;
case LINEDEVSTATE_MAINTENANCE:
ErrorBox (TEXT("The line selected is out for maintenance."));
CurrentLineClose ();
if (g_hwndDial)
SendMessage (g_hwndDial, WM_COMMAND, MAKEWPARAM(IDOK,0), 0);
break;
case LINEDEVSTATE_TRANSLATECHANGE:
break;
case LINEDEVSTATE_REMOVED:
ErrorBox (
TEXT("The Line device has been removed; no action taken."));
break;
case LINEDEVSTATE_REINIT:
{
// This usually means that a service provider has changed in
// such a way that requires TAPI to REINIT. Note that there
// are both soft REINITs and hard REINITs. Soft REINITs do not
// require a full shutdown but an informational change that
// historically required a REINIT to force the application to
// deal with. TAPI API Version 1.3 applications require a
// full REINIT for both hard and soft REINITs.
switch(dwParam2)
{
// This is the hard REINIT. TAPI is waiting for everyone to
// shut down. Our response is to immediately shut down any
// calls, shut down our use of TAPI and notify the user.
case 0:
if (MessageBox (
g_hwndMain,
TEXT("Tapi line configuration has been changed. ")
TEXT("You have to shut down CeDialer to\n")
TEXT("re-initialize the use of tapi.dll. Do ")
TEXT("you want to shut down CeDialer now?"),
TEXT("Warning"),
MB_YESNO) == IDYES)
{
lineShutdown (g_hLineApp);
DestroyWindow (g_hwndMain);
}
break;
case LINE_CREATE:
lineCallbackFunc (hDevice, dwParam2, dwCallbackInstance,
dwParam3, 0, 0);
break;
case LINE_LINEDEVSTATE:
lineCallbackFunc (hDevice, dwParam2, dwCallbackInstance,
dwParam3, 0, 0);
break;
// There might be other reasons to send a soft REINIT.
// No need to shut down for these reasons.
default:
break;
}
}
default:
break;
}
break;
case LINE_REPLY:
// Reply from the lineMakeCall function.
if ((LONG)dwParam1 == g_MakeCallRequestID)
{
// If an error occurred on making the call.
if (dwParam2 != ERR_NONE)
{
if (dwParam2 == LINEERR_CALLUNAVAIL)
ErrorBox (TEXT("The line is not available."));
CurrentLineClose ();
if (g_hwndDial)
SendMessage (g_hwndDial, WM_COMMAND, MAKEWPARAM(IDOK,0), 0);
}
}
// Reply from lineDrop function.
if ((LONG)dwParam1 == g_DropCallRequestID)
{
// Insert code here to deal with this situation.
// ...
}
break;
case LINE_CREATE:
// dwParam1 is the device identifier of the new line.
if (dwParam1 >= g_dwNumDevs)
{
DWORD dwLineID;
LINEINFO *lpLineInfo;
g_dwNumDevs = dwParam1 + 1;
// Allocate a buffer for storing LINEINFO for all the lines.
if (!(lpLineInfo = (LPLINEINFO) LocalAlloc (
LPTR,
sizeof (LINEINFO) * g_dwNumDevs)))
{
break;
}
// Assume we just add a new line, the lines are sequential and
// the new line is the last one.
for (dwLineID = 0; dwLineID < dwParam1; ++dwLineID)
{
lpLineInfo[dwLineID] = g_lpLineInfo[dwLineID];
}
// Get the new line information.
GetLineInfo (dwParam1, &lpLineInfo[dwParam1]);
LocalFree (g_lpLineInfo);
g_lpLineInfo = lpLineInfo;
}
break;
case LINE_CLOSE:
if (g_CurrentLineInfo.hLine == (HLINE) hDevice)
{
CurrentLineClose ();
if (g_hwndDial)
SendMessage (g_hwndDial, WM_COMMAND, MAKEWPARAM(IDOK,0), 0);
}
break;
case LINE_ADDRESSSTATE:
case LINE_CALLINFO:
case LINE_DEVSPECIFIC:
case LINE_DEVSPECIFICFEATURE:
case LINE_GATHERDIGITS:
case LINE_GENERATE:
case LINE_MONITORDIGITS:
case LINE_MONITORMEDIA:
case LINE_MONITORTONE:
case LINE_REMOVE:
case LINE_REQUEST:
default:
break;
}
}
/***********************************************************************
FUNCTION:
DialingProc
PURPOSE:
Processes messages sent to the Dialing dialog box window.
***********************************************************************/
BOOL CALLBACK DialingProc (HWND hwnd, UINT uMsg, WPARAM wParam,
LPARAM lParam)
{
switch (uMsg)
{
case WM_INITDIALOG:
// Set the global handle to the window.
g_hwndDial = hwnd;
// Display the current dialing phone number.
SetDlgItemText (hwnd, IDC_PHONENUM, g_szCurrentNum);
// Set the cursor as a wait cursor.
SetCursor (LoadCursor (NULL, IDC_WAIT));
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
// Drop the line, close the line, and then close the dialog box.
// This is the case when the Hangup button gets pushed.
case IDCANCEL:
// If lineMakeCall succeeds, then drop the call.
if (g_hCall)
{
g_DropCallRequestID = lineDrop (g_hCall, NULL, 0);
lineDeallocateCall (g_hCall);
}
// Close the current phone line.
CurrentLineClose ();
// Close the dialing dialog box.
EndDialog (hwnd, FALSE);
// Invalidate the dialing dialog box window handle.
g_hwndDial = NULL;
// Set the cursor back to an arrow.
SetCursor (0);
return TRUE;
// Close the dialog box. This is the case when the
// application sends a message to close the dialog box.
case IDOK:
// Close the dialing dialog box.
EndDialog (hwnd, TRUE);
// Invalidate the dialing dialog box window handle.
g_hwndDial = NULL;
// Set the cursor back to an arrow.
SetCursor (0);
return TRUE;
}
break;
}
return FALSE;
}
/***********************************************************************
FUNCTION:
CurrentLineClose
PURPOSE:
This function closes the opened line device.
***********************************************************************/
VOID CurrentLineClose ()
{
// Close the current line.
if (g_CurrentLineInfo.hLine)
lineClose (g_CurrentLineInfo.hLine);
// Reinitialize the variables.
g_CurrentLineInfo.hLine = NULL;
g_bCurrentLineAvail = TRUE;
g_hCall = NULL;
}
/***********************************************************************
GetLineInfo
***********************************************************************/
DWORD GetLineInfo (DWORD dwLineID, LPLINEINFO lpLineInfo)
{
DWORD dwSize,
dwReturn;
LPTSTR lpszLineName = NULL;
LPLINEDEVCAPS lpLineDevCaps = NULL;
// Negotiate the API version number. If it fails, return to dwReturn.
if (dwReturn = lineNegotiateAPIVersion (
g_hLineApp, // TAPI registration handle
dwLineID, // Line device to be queried
TAPI_VERSION_1_0, // Least recent API version
TAPI_CURRENT_VERSION, // Most recent API version
&(lpLineInfo->dwAPIVersion), // Negotiated API version
NULL)) // Must be NULL; the provider-
// specific extension is not
// supported on Windows CE
{
goto exit;
}
dwSize = sizeof (LINEDEVCAPS);
// Allocate enough memory for lpLineDevCaps.
do
{
if (!(lpLineDevCaps = (LPLINEDEVCAPS) LocalAlloc (LPTR, dwSize)))
{
dwReturn = LINEERR_NOMEM;
goto exit;
}
lpLineDevCaps->dwTotalSize = dwSize;
if (dwReturn = lineGetDevCaps (g_hLineApp,
dwLineID,
lpLineInfo->dwAPIVersion,
0,
lpLineDevCaps))
{
goto exit;
}
// Stop if the allocated memory is equal to or greater than the
// needed memory.
if (lpLineDevCaps->dwNeededSize <= lpLineDevCaps->dwTotalSize)
break;
dwSize = lpLineDevCaps->dwNeededSize;
LocalFree (lpLineDevCaps);
lpLineDevCaps = NULL;
} while (TRUE);
// Store the line information in *lpLineInfo.
lpLineInfo->dwPermanentLineID = lpLineDevCaps->dwPermanentLineID;
lpLineInfo->dwNumOfAddress = lpLineDevCaps->dwNumAddresses;
lpLineInfo->bVoiceLine =
(lpLineDevCaps->dwMediaModes & LINEMEDIAMODE_INTERACTIVEVOICE);
// Allocate memory for lpszLineName.
if (!(lpszLineName = (LPTSTR) LocalAlloc (LPTR, 512)))
{
dwReturn = LINEERR_NOMEM;
goto exit;
}
// Store the line name in *lpszLineName.
if (lpLineDevCaps->dwLineNameSize >= 512)
{
wcsncpy (
lpszLineName,
(LPTSTR)((LPSTR)lpLineDevCaps + lpLineDevCaps->dwLineNameOffset),
512);
}
else if (lpLineDevCaps->dwLineNameSize > 0)
{
wcsncpy (
lpszLineName,
(LPTSTR)((LPSTR)lpLineDevCaps + lpLineDevCaps->dwLineNameOffset),
lpLineDevCaps->dwLineNameSize);
}
else
wsprintf (lpszLineName, TEXT("Line %d"), dwLineID);
// Copy lpszLineName to lpLineInfo->lpszLineName.
lstrcpy (lpLineInfo->szLineName, lpszLineName);
dwReturn = ERR_NONE;
exit:
if (lpLineDevCaps)
LocalFree (lpLineDevCaps);
if (lpszLineName)
LocalFree (lpszLineName);
return dwReturn;
}
/***********************************************************************
InitializeTAPI
***********************************************************************/
DWORD InitializeTAPI ()
{
DWORD dwLineID,
dwReturn,
dwTimeCount = GetTickCount ();
TCHAR szWarning[] = TEXT("Cannot initialize the application's use\n")
TEXT("of tapi.dll. Quit all other telephony\n")
TEXT("programs, and then try again.");
// Initialize the application's use of Tapi.dll. Keep trying until the
// user cancels or stops getting LINEERR_REINIT.
while ( (dwReturn = lineInitialize (&g_hLineApp,
g_hInst,
(LINECALLBACK) lineCallbackFunc,
g_szAppName,
&g_dwNumDevs)) == LINEERR_REINIT)
{
// Bring up the message box if 5 seconds have passed.
if (GetTickCount () > 5000 + dwTimeCount)
{
if (MessageBox (g_hwndMain, szWarning, TEXT("Warning"),
MB_OKCANCEL) == IDOK)
break;
// Reset the time counter.
dwTimeCount = GetTickCount ();
}
}
// If function "lineInitialize" fails, then return.
if (dwReturn)
return dwReturn;
// If there is no device, then return.
if (g_dwNumDevs == 0)
{
ErrorBox (TEXT("There are no line devices available."));
return LINEERR_NODEVICE;
}
// Allocate buffer for storing LINEINFO for all the available lines.
if (! (g_lpLineInfo = (LPLINEINFO) LocalAlloc (
LPTR,
sizeof (LINEINFO) * g_dwNumDevs)))
{
return LINEERR_NOMEM;
}
// Fill lpLineInfo[] for every line.
for (dwLineID = 0; dwLineID < g_dwNumDevs; ++dwLineID)
{
GetLineInfo (dwLineID, &g_lpLineInfo [dwLineID]);
}
return ERR_NONE;
}
/***********************************************************************
MakePhoneCall
***********************************************************************/
VOID MakePhoneCall (LPCTSTR lpszPhoneNum)
{
DWORD dwReturn,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -