📄 dialer.c
字号:
(LPCSTR)MAKEINTRESOURCE(IDD_DIALER),
(HWND)NULL,
(DLGPROC)MainWndProc
);
ReadINI();
ButtonFontSetup();
ShowWindow(ghWndMain, SW_SHOW);
UpdateWindow(ghWndMain);
// limit text in Number field to TAPIMAXDESTADDRESSSIZE
SendDlgItemMessage (
ghWndMain,
IDD_DCOMBO,
CB_LIMITTEXT,
(WPARAM)TAPIMAXDESTADDRESSSIZE,
0
);
// 0 (ERR_NONE) error code registers success - otherwise terminate
errCode = InitializeTAPI();
if(errCode)
{
errString(ghWndMain, errCode, MB_APPLMODAL | MB_ICONEXCLAMATION );
DialerCleanup();
return errCode;
}
errCode = lineRegisterRequestRecipient (
ghLineApp,
0, // registration instance
LINEREQUESTMODE_MAKECALL,
TRUE
);
if(errCode)
{
gfRegistered = FALSE;
errString(ghWndMain, errCode, MB_ICONEXCLAMATION | MB_OK );
}
else
{
gfRegistered = TRUE;
}
hAccel = LoadAccelerators(ghInst, gszAppName);
while ( GetMessage( &msg, NULL, 0, 0 ) )
{
if ( ghWndMain == NULL || !IsDialogMessage( ghWndMain, &msg ) )
{
if(!TranslateAccelerator(ghWndMain, hAccel, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
// If: 1) Dialer is a call manager (if not, ignore requests)
// 2) the currently chosen line is available
// 3) there is a Simple TAPI request
// Then: process the request
if ( gfCurrentLineAvail && gfCallRequest )
{
ManageAssistedTelephony();
}
}
DialerCleanup();
CloseHandle( hImHere );
return (int)(msg.wParam);
}
//***************************************************************************
//***************************************************************************
//***************************************************************************
LPVOID DialerAlloc(size_t cbToAlloc)
{
return LocalAlloc(LPTR, cbToAlloc);
}
LPVOID DialerFree(LPVOID lpMem)
{
return LocalFree( lpMem );
}
//***************************************************************************
//***************************************************************************
//***************************************************************************
VOID ReadINI( VOID )
{
WORD cSDEntry, cLastDialed;
DWORD cComma;
POINT ptLeftTop;
char szName[ TAPIMAXCALLEDPARTYSIZE ];
char szTemp[ TAPIMAXCALLEDPARTYSIZE ];
char szNum[MAXBUFSIZE];
char szFieldName[MAXBUFSIZE];
char szPt[MAXBUFSIZE];
// get speed dial settings from INI file
for(cSDEntry = 1; cSDEntry <= NSPEEDDIALS; ++cSDEntry)
{
wsprintf(szFieldName, "Name%d", cSDEntry);
GetPrivateProfileString (
"Speed Dial Settings",
szFieldName,
gszNULL,
szName,
TAPIMAXCALLEDPARTYSIZE - 1,
gszINIfilename
);
wsprintf(szFieldName, "Number%d", cSDEntry);
GetPrivateProfileString (
"Speed Dial Settings",
szFieldName,
gszNULL,
gszSDNumber[cSDEntry],
TAPIMAXDESTADDRESSSIZE - 1,
gszINIfilename
);
if ( !lstrcmp( gszNULL, szName ) )
{
lstrcpy( szName, gszSDNumber[ cSDEntry ] );
}
FitTextToButton( ghWndMain, IDD_DSPEEDDIAL1 + cSDEntry - 1, szName );
AmpersandCompensate( szName, szTemp );
SetDlgItemText (
ghWndMain,
IDD_DSPEEDDIAL1 + cSDEntry - 1,
(LPCSTR)szTemp
); // Label the speed dial button
}
// set up last dialed numbers in combo box (read from INI)
for(cLastDialed = 1; cLastDialed <= NLASTDIALED; ++cLastDialed)
{
wsprintf(szFieldName, "Last dialed %d", cLastDialed);
GetPrivateProfileString (
"Last dialed numbers",
szFieldName,
gszNULL,
szNum,
MAXBUFSIZE - 1,
gszINIfilename
);
if ( szNum[0] ) // i.e. if szNum isn't simply "" - if we read something
// from the INI - put it in the combo box
SendDlgItemMessage(
ghWndMain,
IDD_DCOMBO,
CB_ADDSTRING,
0,
(LPARAM)(LPCSTR)szNum
);
}
// set defaults
ptLeftTop.x = 100;
ptLeftTop.y = 100;
// set the window position based on the INI data
GetPrivateProfileString (
"Preference",
"Main Window Left/Top",
gszNULL,
szPt,
MAXBUFSIZE - 1,
gszINIfilename
);
if ( szPt[0] )
{
cComma = strcspn(szPt, ",");
szPt[cComma] = 0;
ptLeftTop.x = atoi(szPt);
// a possibly absurd check to see that the string
// wasn't akin to "320," with no second entry
if ( *(szPt + cComma + 1 ) )
ptLeftTop.y = atoi( szPt + cComma + 1 );
// check to see that the box is on the screen - the upper left
// must be on the screen, along with a 50x50 box below and to
// the right of it
if ( ptLeftTop.x < 0
|| ptLeftTop.x + 50 >= GetSystemMetrics(SM_CXSCREEN)
|| ptLeftTop.y < 0
|| ptLeftTop.y + 50 >= GetSystemMetrics(SM_CYSCREEN)
)
{
ptLeftTop.x = 100; // set defaults if the box is off of the screen
ptLeftTop.y = 100; // set defaults if the box is off of the screen
}
}
SetWindowPos (
ghWndMain,
NULL,
ptLeftTop.x,
ptLeftTop.y,
0,
0,
SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOREDRAW | SWP_NOZORDER
);
}
//***************************************************************************
//***************************************************************************
//***************************************************************************
VOID ButtonFontSetup(VOID)
{
HDC hdc;
int IDD;
// define the fonts for the buttons
hdc = GetDC(GetDesktopWindow());
ghFontBtn = CreateFont(
(-10)*GetDeviceCaps(hdc, LOGPIXELSY)/72,
0,
0,
0,
FW_BOLD,
FALSE,
FALSE,
FALSE,
ANSI_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
PROOF_QUALITY,
VARIABLE_PITCH | FF_SWISS,
(LPSTR)"Arial"
);
ghFontBtnText = CreateFont(
(-6)*GetDeviceCaps(hdc, LOGPIXELSY)/72,
0,
0,
0,
FW_NORMAL,
FALSE,
FALSE,
FALSE,
ANSI_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
PROOF_QUALITY,
VARIABLE_PITCH | FF_SWISS,
NULL
);
ghFontBtnStar = CreateFont(
(-18)*GetDeviceCaps(hdc, LOGPIXELSY)/72,
0,
0,
0,
FW_BOLD,
FALSE,
FALSE,
FALSE,
SYMBOL_CHARSET,
OUT_TT_PRECIS,
CLIP_DEFAULT_PRECIS,
PROOF_QUALITY,
VARIABLE_PITCH | FF_DONTCARE,
(LPSTR)"Symbol"
);
ReleaseDC(GetDesktopWindow(), hdc);
// set the fonts for the buttons
if(ghFontBtn)
{
// set fonts on number buttons
for(IDD = IDD_DBUTTON1; IDD <= IDD_DBUTTON0; ++IDD)
// the order is IDD_DBUTTON1, 2, 3, ..., 0 (thus from 1 to 0)
SendMessage(
GetDlgItem(ghWndMain, IDD),
WM_SETFONT,
(WPARAM)ghFontBtn,
0L
);
// set fonts on * and # buttons
SendMessage(
GetDlgItem(ghWndMain, IDD_DBUTTONSTAR),
WM_SETFONT,
(WPARAM)ghFontBtnStar,
0L
);
SendMessage(
GetDlgItem(ghWndMain, IDD_DBUTTONPOUND),
WM_SETFONT,
(WPARAM)ghFontBtnStar,
0L
);
}
}
//***************************************************************************
//***************************************************************************
//***************************************************************************
// Draws a 3D button within rcBtn on hDC
VOID DrawButton(HDC hDC, RECT rcBtn, BOOL fHighlighted)
{
HPEN hPenPrev, hPenShadow, hPenHighlight, hPenBlack;
HBRUSH hBrushPrev, hBrushFace;
int RopPrev;
--rcBtn.right;
--rcBtn.bottom;
// set up pens/brush
hPenShadow = CreatePen(PS_SOLID,0,GetSysColor(COLOR_3DSHADOW));
hPenHighlight = CreatePen(PS_SOLID,0,GetSysColor(COLOR_3DHILIGHT));
hPenBlack = GetStockObject(BLACK_PEN);
hBrushFace = GetSysColorBrush(COLOR_3DFACE);
// get current state so we can put it back at the end of DrawButton
hPenPrev = SelectObject(hDC, hPenBlack);
RopPrev = SetROP2(hDC, R2_COPYPEN);
hBrushPrev = SelectObject(hDC, hBrushFace);
PatBlt(
hDC,
rcBtn.left + 1,
rcBtn.top + 1,
rcBtn.right - rcBtn.left - 1,
rcBtn.bottom - rcBtn.top - 1,
PATCOPY
);
if(fHighlighted)
{
SelectObject(hDC, hPenBlack);
MoveToEx(hDC, rcBtn.left, rcBtn.bottom - 1, NULL);
LineTo(hDC, rcBtn.left, rcBtn.top); // _
LineTo(hDC, rcBtn.right, rcBtn.top); // |
SelectObject(hDC, hPenHighlight);
MoveToEx(hDC, rcBtn.right, rcBtn.top, NULL);
LineTo(hDC, rcBtn.right, rcBtn.bottom);
LineTo(hDC, rcBtn.left - 1, rcBtn.bottom); // _|
SelectObject(hDC, hPenShadow);
MoveToEx(hDC, rcBtn.left + 1, rcBtn.bottom - 2, NULL);
LineTo(hDC, rcBtn.left + 1, rcBtn.top + 1);
LineTo(hDC, rcBtn.right - 1, rcBtn.top + 1);
}
else
{
SelectObject(hDC, hPenHighlight);
MoveToEx(hDC, rcBtn.left, rcBtn.bottom - 1, NULL);
LineTo(hDC, rcBtn.left, rcBtn.top); // _
LineTo(hDC, rcBtn.right, rcBtn.top); // |
SelectObject(hDC, hPenBlack);
MoveToEx(hDC, rcBtn.right, rcBtn.top, NULL);
LineTo(hDC, rcBtn.right, rcBtn.bottom);
LineTo(hDC, rcBtn.left - 1, rcBtn.bottom); // _|
SelectObject(hDC, hPenShadow);
MoveToEx(hDC, rcBtn.left + 1, rcBtn.bottom - 1, NULL);
LineTo(hDC, rcBtn.right - 1, rcBtn.bottom - 1);
LineTo(hDC, rcBtn.right - 1, rcBtn.top);
}
// put everything back how it was
SetROP2(hDC, RopPrev);
SelectObject(hDC, hBrushPrev);
SelectObject(hDC, hPenPrev);
DeleteObject(hPenBlack);
DeleteObject(hPenShadow);
DeleteObject(hPenHighlight);
DeleteObject(hBrushFace);
}
//***************************************************************************
//***************************************************************************
//***************************************************************************
VOID DrawButtonText(HDC hDC, RECT rcBtn, BOOL fHighlighted, UINT IDD_Btn)
{
char szLine1[MAXBUFSIZE]; // text in button up to '\n'
LPSTR pszLine2; // text in button after '\n'
int BkModePrev;
HFONT hFontPrev = NULL;
TEXTMETRIC tm;
RECT rcText = rcBtn;
BkModePrev = SetBkMode(hDC, TRANSPARENT);
GetDlgItemText(ghWndMain, IDD_Btn, szLine1, MAXBUFSIZE);
pszLine2 = strstr(szLine1, "\n");
if(pszLine2)
{
*pszLine2 = 0; // 1 -> "TEST1 \n TEST2" becomes "TEST 1 \0"
++pszLine2; // now 2 -> " TEST 2"
}
// now szLine1 points to the null terminated first string and
// pszLine2 points to either the null terminated second string or NULL
// if there was no second string
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -