📄 dialer.c
字号:
szBuffer+gdwEndSel,
i - ( gdwEndSel ) + 1 );
szBuffer[gdwStartSel] = digits[LOWORD(wParam) - IDD_DBUTTON1];
SendDlgItemMessage(ghWndMain,
IDD_DCOMBO,
WM_SETTEXT,
0,
(LPARAM)szBuffer);
gdwStartSel++;
gdwEndSel = gdwStartSel;
}
SetFocus(GetDlgItem(ghWndMain, IDD_DDIAL));
EnableWindow(GetDlgItem(ghWndMain, IDD_DDIAL), TRUE);
return TRUE;
}
case IDD_DCOMBO:
if (HIWORD(wParam) == CBN_SELENDOK)
{
EnableWindow( GetDlgItem(ghWndMain, IDD_DDIAL), TRUE );
}
if ((HIWORD(wParam) == CBN_SELENDOK) ||
(HIWORD(wParam) == CBN_SELENDCANCEL))
{
(DWORD)SendDlgItemMessage(ghWndMain,
IDD_DCOMBO,
CB_GETEDITSEL,
(WPARAM)&gdwStartSel,
(LPARAM)&gdwEndSel);
return FALSE;
}
if ( HIWORD( wParam ) == CBN_EDITCHANGE )
{
EnableWindow (
GetDlgItem( ghWndMain, IDD_DDIAL ),
(BOOL) GetWindowTextLength (
GetDlgItem (
ghWndMain,
IDD_DCOMBO
)
)
);
return TRUE;
}
break;
case IDD_DSPEEDDIAL1:
case IDD_DSPEEDDIAL2:
case IDD_DSPEEDDIAL3:
case IDD_DSPEEDDIAL4:
case IDD_DSPEEDDIAL5:
case IDD_DSPEEDDIAL6:
case IDD_DSPEEDDIAL7:
case IDD_DSPEEDDIAL8:
{
DWORD cSDEntry = LOWORD( (DWORD) wParam) - IDD_DSPEEDDIAL1 + 1;
char szFieldName [MAXBUFSIZE];
// get information for the speed dial button
// from the INI file
wsprintf(szFieldName, "Name%d", cSDEntry);
GetPrivateProfileString (
"Speed Dial Settings",
szFieldName,
gszNULL,
szName,
TAPIMAXCALLEDPARTYSIZE - 1,
gszINIfilename
);
wsprintf(szFieldName, "%s%d", "Number", cSDEntry);
GetPrivateProfileString (
"Speed Dial Settings",
szFieldName,
gszNULL,
gszSDNumber[cSDEntry],
TAPIMAXDESTADDRESSSIZE - 1,
gszINIfilename
);
// entry not set yet
if( gszSDNumber[cSDEntry][0] == 0 )
{
DialogBoxParam (
ghInst,
MAKEINTRESOURCE(IDD_SD2),
ghWndMain,
(DLGPROC)SpeedDial2Proc,
MAKELPARAM(wParam,0)
);
}
// no line open
// once the currentline has been set
// using the connect proc
// the user must hit dial again
else if ( giCurrentLine == (DWORD)-1)
{
DialogBoxParam (
ghInst,
MAKEINTRESOURCE(IDD_CONNECTUSING),
ghWndMain,
(DLGPROC)ConnectUsingProc,
INVALID_LINE
);
}
// entry is set and valid voice line is open
else
{
// add number to list box combo.
AddToRedialList( gszSDNumber[cSDEntry] );
InitiateCall( gszSDNumber[cSDEntry], szName );
}
break;
}
} // end switch (LOWORD((DWORD)wParam)) { ... }
break; // end case WM_COMMAND
}
case WM_PAINT:
{
PAINTSTRUCT ps;
BeginPaint(ghWndMain, &ps);
if(IsIconic(ghWndMain))
DrawIcon(ps.hdc, 0, 0, hIcon);
else
{
HBRUSH hBrush;
hBrush = GetSysColorBrush( COLOR_3DFACE );
// FillRect(ps.hdc, &ps.rcPaint, GetStockObject(LTGRAY_BRUSH));
FillRect(ps.hdc, &ps.rcPaint, hBrush);
}
EndPaint(ghWndMain, &ps);
return TRUE;
}
case WM_DRAWITEM:
{
LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
BOOL fHighlighted = (BOOL)(SendDlgItemMessage(
ghWndMain,
lpdis->CtlID,
BM_GETSTATE,
0,
0
) & 0x0004);
DrawButton(lpdis->hDC, lpdis->rcItem, fHighlighted);
DrawButtonText(
lpdis->hDC,
lpdis->rcItem,
fHighlighted,
lpdis->CtlID
);
return TRUE;
}
case WM_CTLCOLORLISTBOX:
case WM_CTLCOLORBTN:
case WM_CTLCOLORSTATIC:
SetBkColor((HDC)wParam, GetSysColor(COLOR_BTNFACE));
return (BOOL)((ULONG_PTR)GetSysColorBrush( COLOR_3DFACE ));
default:
;
// return DefDlgProc( hwnd, msg, wParam, lParam );
// return DefWindowProc( hwnd, msg, wParam, lParam );
} // switch (msg) { ... }
return FALSE;
}
//***************************************************************************
//***************************************************************************
//***************************************************************************
VOID AddToRedialList( LPCSTR szNumber )
{
// NLASTDIALED == 10
WORD cNum;
HWND hWndCombo = GetDlgItem(ghWndMain, IDD_DCOMBO);
LRESULT nMatch;
// if valid number
if ( szNumber[0] )
{
// if list box has entries, check if this number
// is already present. If so delete old entry
cNum = (WORD) SendMessage(hWndCombo, CB_GETCOUNT, 0, 0);
if ( cNum != 0 )
{
nMatch = SendMessage ( hWndCombo, CB_FINDSTRING, 0, (LPARAM)szNumber );
if ( nMatch != CB_ERR )
{
SendMessage(hWndCombo, CB_DELETESTRING, nMatch, 0);
}
else
{
// if the list is full, remove oldest
if ( cNum == NLASTDIALED )
{
SendMessage( hWndCombo, CB_DELETESTRING, NLASTDIALED - 1, 0 );
}
}
}
SendMessage(hWndCombo, CB_INSERTSTRING, 0, (LPARAM)szNumber);
SendMessage(hWndCombo, CB_SETCURSEL, 0, 0L);
EnableWindow ( GetDlgItem( ghWndMain, IDD_DDIAL ), TRUE );
}
}
//***************************************************************************
//***************************************************************************
//***************************************************************************
VOID InitiateCall ( LPCSTR szNumber, LPCSTR szName )
{
HLINE hLine = (HLINE)((ULONG_PTR)NULL);
DWORD errCode;
// struct size info
DWORD dwLTPSize = sizeof ( LINETRANSLATEOUTPUT );
DWORD dwNameLen = lstrlen( szName ) + 1;
DWORD dwLCPSize = sizeof( LINECALLPARAMS );
LPLINETRANSLATEOUTPUT lpTransOut = NULL;
LPLINECALLPARAMS lpLineCallParams = NULL;
char szCanNumber[ TAPIMAXDESTADDRESSSIZE ];
// Open a line
errCode = lineOpen (
ghLineApp,
giCurrentLine,
&hLine,
gCurrentLineInfo.dwAPIVersion,
0,
0,
LINECALLPRIVILEGE_NONE,
0,
NULL
);
if (errCode)
{
errString ( ghWndMain, errCode, MB_ICONEXCLAMATION | MB_OK );
goto error;
}
// call translate address before dialing
do
{
lpTransOut = (LPLINETRANSLATEOUTPUT) DialerAlloc( dwLTPSize );
if ( !lpTransOut )
{
errString( ghWndMain, LINEERR_NOMEM, MB_ICONSTOP | MB_OK );
goto error;
}
lpTransOut-> dwTotalSize = dwLTPSize;
if ( !MakeCanonicalNumber( szNumber, szCanNumber ) )
{
lstrcpy( szCanNumber, szNumber );
}
errCode = lineTranslateAddress (
ghLineApp,
giCurrentLine,
gCurrentLineInfo.dwAPIVersion,
szCanNumber,
0,
0,
lpTransOut
);
if ( ((LONG)errCode) < 0 )
{
errString( ghWndMain, errCode, MB_ICONEXCLAMATION | MB_OK );
goto error;
}
if ( lpTransOut-> dwNeededSize <= lpTransOut->dwTotalSize )
{
// ok we are done
break;
}
else
{
dwLTPSize = lpTransOut-> dwNeededSize;
DialerFree ( lpTransOut );
lpTransOut = NULL;
}
} while ( TRUE );
// if number dialed is 911, bring up a warning
if ( Is911( lpTransOut) )
{
INT nRes = errString ( ghWndMain, ERR_911WARN, MB_ICONSTOP | MB_YESNO );
if ( nRes == IDNO )
{
goto error;
}
}
// set call parameters
dwLCPSize += dwNameLen + lpTransOut-> dwDisplayableStringSize;
lpLineCallParams = (LPLINECALLPARAMS) DialerAlloc( dwLCPSize );
if ( !lpLineCallParams )
{
errString( ghWndMain, LINEERR_NOMEM, MB_ICONSTOP | MB_OK );
goto error;
}
lpLineCallParams->dwTotalSize = dwLCPSize;
lpLineCallParams->dwBearerMode = LINEBEARERMODE_VOICE;
lpLineCallParams->dwMediaMode = LINEMEDIAMODE_INTERACTIVEVOICE;
lpLineCallParams->dwCallParamFlags = LINECALLPARAMFLAGS_IDLE;
lpLineCallParams->dwAddressMode = LINEADDRESSMODE_ADDRESSID;
lpLineCallParams->dwAddressID = giCurrentAddress;
if ( szName[ 0 ] )
{
lpLineCallParams->dwCalledPartySize = dwNameLen;
lpLineCallParams->dwCalledPartyOffset = sizeof( LINECALLPARAMS );
lstrcpy (
(LPSTR) lpLineCallParams + sizeof(LINECALLPARAMS),
szName
);
}
lpLineCallParams-> dwDisplayableAddressSize = lpTransOut-> dwDisplayableStringSize;
lpLineCallParams-> dwDisplayableAddressOffset = sizeof( LINECALLPARAMS ) + dwNameLen;
lstrcpy (
(LPSTR) lpLineCallParams + sizeof(LINECALLPARAMS) + dwNameLen,
(LPSTR) lpTransOut + lpTransOut-> dwDisplayableStringOffset
);
// save dialing information
// Free old allocs.
if ( gszCurrentName )
{
DialerFree ( gszCurrentName );
}
if ( gszCurrentNumber )
{
DialerFree ( gszCurrentNumber );
}
// save new stuff
gszCurrentName = (LPSTR) DialerAlloc( dwNameLen );
if ( !gszCurrentName )
{
errString( ghWndMain, LINEERR_NOMEM, MB_ICONSTOP | MB_OK );
goto error;
}
lstrcpy ( gszCurrentName, szName );
gszCurrentNumber = (LPSTR) DialerAlloc( lpTransOut-> dwDisplayableStringSize );
if ( !gszCurrentNumber )
{
errString( ghWndMain, LINEERR_NOMEM, MB_ICONSTOP | MB_OK );
goto error;
}
lstrcpy (
gszCurrentNumber,
(LPSTR) lpTransOut + lpTransOut-> dwDisplayableStringOffset
);
gCurrentLineInfo.hLine = hLine;
ghCall = (HCALL)((ULONG_PTR)NULL);
// finally make the call.
gMakeCallRequestID = 0;
gMakeCallRequestID = lineMakeCall (
hLine,
&ghCall,
(LPSTR) lpTransOut + lpTransOut-> dwDialableStringOffset,
0,
lpLineCallParams
);
// async request ID
// - the call is going out
if ( (LONG) gMakeCallRequestID > 0 )
{
gfCurrentLineAvail = FALSE;
gfMakeCallReplyPending = TRUE;
DialogBoxParam (
ghInst,
MAKEINTRESOURCE(IDD_DIALING),
ghWndMain,
(DLGPROC)DialingProc,
0
);
}
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -