📄 tdaemondlg.cpp
字号:
// tDaemonDlg.cpp : implementation file
//
#include "stdafx.h"
#include "tDaemon.h"
#include "tDaemonDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CtDaemonDlg dialog
CtDaemonDlg::CtDaemonDlg(CWnd* pParent /*=NULL*/)
: CDialog(CtDaemonDlg::IDD, pParent),
m_call(&m_line)
{
//{{AFX_DATA_INIT(CtDaemonDlg)
m_nAreaEnd = 0;
m_nAreaStart = 0;
m_nCountryEnd = 0;
m_nCountryStart = 0;
m_nPhoneNoEnd = 0;
m_nPhoneNoStart = 0;
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CtDaemonDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CtDaemonDlg)
DDX_Control(pDX, IDC_LOG, m_editLog);
DDX_Control(pDX, IDC_STOP, m_btnStop);
DDX_Control(pDX, IDC_START, m_btnStart);
DDX_Text(pDX, IDC_AREA_END, m_nAreaEnd);
DDX_Text(pDX, IDC_AREA_START, m_nAreaStart);
DDX_Text(pDX, IDC_COUNTRY_END, m_nCountryEnd);
DDX_Text(pDX, IDC_COUNTRY_START, m_nCountryStart);
DDX_Text(pDX, IDC_NO_END, m_nPhoneNoEnd);
DDX_Text(pDX, IDC_NO_START, m_nPhoneNoStart);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CtDaemonDlg, CDialog)
//{{AFX_MSG_MAP(CtDaemonDlg)
ON_WM_SYSCOMMAND()
ON_BN_CLICKED(IDC_START, OnStart)
ON_BN_CLICKED(IDC_STOP, OnStop)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CtDaemonDlg message handlers
bool CtDaemonDlg::OpenValidLine()
{
DWORD nLines = ::TfxGetNumLines();
for( DWORD nLineID = 0; nLineID < nLines; nLineID++ )
{
CtLineDevCaps ldc;
if( TSUCCEEDED(ldc.GetDevCaps(nLineID)) &&
(ldc.GetBearerModes() & LINEBEARERMODE_VOICE) &&
(ldc.GetMediaModes() & LINEMEDIAMODE_DATAMODEM) &&
(ldc.GetLineFeatures() & LINEFEATURE_MAKECALL) &&
TSUCCEEDED(m_line.Open(nLineID, this)) ) // Outbound calls only
{
return true;
}
}
return false;
}
BOOL CtDaemonDlg::OnInitDialog()
{
// Check for a suitable line and open it
if( !OpenValidLine() )
{
AfxMessageBox(IDS_NO_MODEM);
EndDialog(IDABORT);
return FALSE;
}
// Initialize current country and area code
CtPhoneNo pno;
pno.ResetToLocation();
m_nCountryStart = m_nCountryEnd = pno.GetCountryCodeNum();
m_nAreaStart = m_nAreaEnd = atol(pno.GetAreaCode());
// Set suggested phone number range
m_nPhoneNoStart = 1000000;
m_nPhoneNoEnd = 9999999;
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CtDaemonDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CDialog(IDD_ABOUT).DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
void CtDaemonDlg::OnStart()
{
m_btnStart.EnableWindow(FALSE);
m_btnStop.EnableWindow(TRUE);
if( UpdateData(TRUE) )
{
m_nCountry = m_nCountryStart;
m_nArea = m_nAreaStart;
m_nPhoneNo = m_nPhoneNoStart;
m_editLog.SetWindowText("");
Dial();
}
}
void CtDaemonDlg::OnStop()
{
if( m_call.GetHandle() )
{
m_nPhoneNo = m_nPhoneNoEnd;
m_nArea = m_nAreaEnd;
m_nCountry = m_nCountryEnd;
if( TPENDING(m_call.Drop()) ) return;
}
m_btnStart.EnableWindow(TRUE);
m_btnStop.EnableWindow(FALSE);
}
void CtDaemonDlg::DialNext()
{
m_nPhoneNo++;
if( m_nPhoneNo > m_nPhoneNoEnd )
{
m_nPhoneNo = m_nPhoneNoStart;
m_nArea++;
if( m_nArea > m_nAreaEnd )
{
m_nArea = m_nAreaStart;
m_nCountry++;
if( m_nCountry > m_nCountryEnd )
{
// We're done
OnStop();
return;
}
}
}
Dial();
}
// Caller responsible for setting flags (if they are other than zero)
// and calling delete[] on result when buffer is no longer needed.
LINECALLPARAMS* AllocateCallParams(
LPCSTR pszAddress = 0,
LPCSTR pszCalledParty = 0,
LPCSTR pszComment = 0)
{
// Calculate LINECALLPARAMS sizes
size_t cbAddress = (pszAddress && *pszAddress ? strlen(pszAddress) + 1 : 0);
size_t cbCalledParty = (pszCalledParty && *pszCalledParty ? strlen(pszCalledParty) + 1 : 0);
size_t cbComment = (pszComment && *pszComment ? strlen(pszComment) + 1 : 0);
size_t cbCallParams = sizeof(LINECALLPARAMS) + cbAddress + cbCalledParty + cbComment;
// Allocate LINECALLPARAMS structure
LINECALLPARAMS* pCallParams = (LINECALLPARAMS*)(new BYTE[cbCallParams]);
if( pCallParams )
{
ZeroMemory(pCallParams, cbCallParams);
pCallParams->dwTotalSize = cbCallParams;
// Fill in a LINECALLPARAMS structure
// pszAddress
pCallParams->dwDisplayableAddressSize = cbAddress;
if( cbAddress )
{
pCallParams->dwDisplayableAddressOffset = sizeof(LINECALLPARAMS);
char* psz = (char*)((BYTE*)pCallParams + pCallParams->dwDisplayableAddressOffset);
strcpy(psz, pszAddress);
}
else
{
pCallParams->dwDisplayableAddressOffset = 0;
}
// pszCalledParty
pCallParams->dwCalledPartySize = cbCalledParty;
if( cbCalledParty )
{
pCallParams->dwCalledPartyOffset = sizeof(LINECALLPARAMS) + cbAddress;
char* psz = (char*)((BYTE*)pCallParams + pCallParams->dwCalledPartyOffset);
strcpy(psz, pszCalledParty);
}
else
{
pCallParams->dwCalledPartyOffset = 0;
}
// pszComment
pCallParams->dwCommentSize = cbComment;
if( cbComment )
{
pCallParams->dwCommentOffset = sizeof(LINECALLPARAMS) + cbAddress + cbCalledParty;
char* psz = (char*)((BYTE*)pCallParams + pCallParams->dwCommentOffset);
strcpy(psz, pszComment);
}
else
{
pCallParams->dwCommentOffset = 0;
}
}
return pCallParams;
}
void CtDaemonDlg::Dial()
{
CString sCountry; sCountry.Format("%d", m_nCountry);
CString sArea; sArea.Format("%d", m_nArea);
CString sPhoneNo; sPhoneNo.Format("%d", m_nPhoneNo);
CtPhoneNo pno(sCountry, sArea, sPhoneNo);
CtTranslateOutput to;
TRESULT tr;
tr = to.TranslateAddress(m_line.GetDeviceID(),
pno.GetTranslatable(0),
0,
// Don't let incoming calls interrupt
LINETRANSLATEOPTION_CANCELCALLWAITING);
if( TSUCCEEDED(tr) )
{
CString sDisplayable = to.GetDisplayableString();
CString sDialable = to.GetDialableString();
// Allocate a LINECALLPARAMS structure
LINECALLPARAMS* pCallParams = AllocateCallParams(sDisplayable);
if( pCallParams )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -