⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dialdlg._cp

📁 串口调试助手的源代码
💻 _CP
📖 第 1 页 / 共 3 页
字号:
// DialDlg.cpp : implementation file
//

#include "stdafx.h"
#include "step6.h"

#include "tapiconn.h"
#include "DialDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

// Reasons why a line device might not be usable by TapiComm.
#define LINENOTUSEABLE_ERROR            1
#define LINENOTUSEABLE_NOVOICE          2
#define LINENOTUSEABLE_NODATAMODEM      3
#define LINENOTUSEABLE_NOMAKECALL       4
#define LINENOTUSEABLE_ALLOCATED        5
#define LINENOTUSEABLE_INUSE            6
#define LINENOTUSEABLE_NOCOMMDATAMODEM  7

    CString	szCountryName = _T("");
    CString	szAreaCode = _T("Not Valid");
    CString	szPhoneNumber = _T("Not Valid");
    static DWORD dwUsedDeviceID = MAXDWORD;
    static BOOL bUsedCountryAndArea = FALSE;
    static BOOL bHistoryValid = FALSE;

/////////////////////////////////////////////////////////////////////////////
// CDialDlg dialog


CDialDlg::CDialDlg(CTapiConnection*  pConn, CWnd* pParent /*=NULL*/)
	: CDialog(CDialDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDialDlg)
	m_strCanonicalNumber = _T("");
	m_strDialableNumber = _T("");
	m_strDisplayableNumber = _T("");
	//}}AFX_DATA_INIT

	m_lpDeviceConfig = NULL;
	m_pConn = pConn;
}


void CDialDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDialDlg)
	DDX_Control(pDX, IDC_CALLINGCARD, m_callingCard);
	DDX_Control(pDX, IDC_DIAL, m_dialButton);
	DDX_Control(pDX, IDC_DIALINGPROPERTIES, m_dialingProperties);
	DDX_Control(pDX, IDC_CONFIGURELINE, m_configureLine);
	DDX_Control(pDX, IDC_LOCATION, m_locationBox);
	DDX_Control(pDX, IDC_USEDIALINGRULES, m_useDialingRules);
	DDX_Control(pDX, IDC_COUNTRYCODE, m_countryCode);
	DDX_Control(pDX, IDC_LINEICON, m_lineIcon);
	DDX_Control(pDX, IDC_AREACODE, m_areaCode);
	DDX_Control(pDX, IDC_PHONENUMBER, m_phoneNumber);
	DDX_Control(pDX, IDC_TAPILINE, m_tapiLineBox);
	DDX_Text(pDX, IDC_CANONICALNUMBER, m_strCanonicalNumber);
	DDX_Text(pDX, IDC_DIALABLENUMBER, m_strDialableNumber);
	DDX_Text(pDX, IDC_DISPLAYABLENUMBER, m_strDisplayableNumber);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDialDlg, CDialog)
	//{{AFX_MSG_MAP(CDialDlg)
	ON_CBN_SELENDOK(IDC_TAPILINE, OnSeleTapiline)
	ON_BN_CLICKED(IDC_CONFIGURELINE, OnConfigureline)
	ON_CBN_SELENDOK(IDC_COUNTRYCODE, OnSeleCountrycode)
	ON_EN_CHANGE(IDC_AREACODE, OnChangeAreacode)
	ON_EN_CHANGE(IDC_PHONENUMBER, OnChangePhonenumber)
	ON_BN_CLICKED(IDC_USEDIALINGRULES, OnUsedialingrules)
	ON_CBN_CLOSEUP(IDC_LOCATION, OnCloseupLocation)
	ON_BN_CLICKED(IDC_DIALINGPROPERTIES, OnDialingproperties)
	ON_BN_CLICKED(IDC_DIAL, OnDial)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDialDlg message handlers

BOOL CDialDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();

	DWORD	dwCountryID = 0;

	// Initialize the Dialog Box. Lots to do here.
	FillTAPILine();
	if (m_lpDeviceConfig)
	{
		::LocalFree(m_lpDeviceConfig);
		m_lpDeviceConfig = NULL;
	}

	// If there is a valid history, use it to initialize the controls.
	if (bHistoryValid)
	{
		FillLocationInfo(NULL, NULL, NULL);
		FillCountryCodeList(0);

		m_countryCode.SelectString(-1, szCountryName);
		m_phoneNumber.SetWindowText(szPhoneNumber);
                    
		m_useDialingRules.SetCheck(bUsedCountryAndArea);
		m_tapiLineBox.SetCurSel(m_dwDeviceID);
	}
	else
	{
		FillLocationInfo(NULL, &dwCountryID, &szAreaCode);//szAreaCode);
		FillCountryCodeList(dwCountryID);
		m_useDialingRules.SetCheck(FALSE);
	}

	m_areaCode.SetWindowText(szAreaCode);

	UseDialingRules();
	DisplayPhoneNumber();
	VerifyAndWarnUsableLine();

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDialDlg::OnSeleTapiline() 
{
	if (m_lpDeviceConfig)
	{
		LocalFree(m_lpDeviceConfig);
		m_lpDeviceConfig = NULL;
	}
	DisplayPhoneNumber();
	VerifyAndWarnUsableLine();
}

void	CDialDlg::OnConfigureline() 
{
	DWORD	dwDeviceID = m_tapiLineBox.GetCurSel();
	PreConfigureDevice(dwDeviceID);
	DisplayPhoneNumber();
}

void CDialDlg::OnSeleCountrycode() 
{
	DisplayPhoneNumber();
}

void CDialDlg::OnChangeAreacode() 
{
	DisplayPhoneNumber();
}

void CDialDlg::OnChangePhonenumber() 
{
	DisplayPhoneNumber();
}

void CDialDlg::OnUsedialingrules() 
{
	UseDialingRules();
	DisplayPhoneNumber();	
}


void CDialDlg::OnCloseupLocation() 
{
	CString	szCurrentLocation;//[1024];

	int	nCurrentSelection = m_locationBox.GetCurSel();
	m_locationBox.GetLBText(nCurrentSelection, szCurrentLocation);

	// If the user selected a 'location', make it current.
//	CString	_strTemp;

	FillLocationInfo(&szCurrentLocation, NULL, NULL);//_strTemp);
	DisplayPhoneNumber();
}

void	CDialDlg::OnDialingproperties()
{
	long lReturn;

	DWORD	dwDeviceID = m_tapiLineBox.GetCurSel();

	UpdateData(TRUE);
	lReturn = ::lineTranslateDialog(m_pConn->m_hLineApp, dwDeviceID,
		SAMPLE_TAPI_VERSION, GetSafeHwnd(), m_strCanonicalNumber);

	if (lReturn != TAPISUCCESS)
		OutputDebugLineError(lReturn, "lineTranslateDialog: ");

	// The user could have changed the default location, or
	// added or removed a location while in the 'Dialing
	// Properties' dialog.  Refill the Location Info.

	FillLocationInfo(NULL, NULL, NULL);
	DisplayPhoneNumber();
}

void CDialDlg::OnDial() 
{
	// The Dial button has to be enabled and the line has
	// to be currently usable to continue.
	if (!(m_dialButton.IsWindowEnabled() &&
		VerifyAndWarnUsableLine()))
		return;

	DisplayPhoneNumber();

	// Get the displayable and dialable numbers and store
	// them in global variables to be used while dialing.
	UpdateData(TRUE);

	// Store all the relavent information in static
	// variables so they will be available the next time a
	// number is dialed.
	m_countryCode.GetWindowText(szCountryName);
	m_areaCode.GetWindowText(szAreaCode);
	m_phoneNumber.GetWindowText(szPhoneNumber);
	bUsedCountryAndArea = m_useDialingRules.GetCheck();
	bHistoryValid = TRUE;
	m_dwDeviceID = m_tapiLineBox.GetCurSel();
	EndDialog(TRUE);
}

DWORD	CDialDlg::GetDeviceID(void)
{
	return  m_dwDeviceID;
}

//
//  FUNCTION: void FillTAPILine(HWND)
//
//  PURPOSE: Fills the 'TAPI Line' control with the available line devices.
//
//
//  RETURN VALUE:
//    none
//
//  COMMENTS:
//
//    This function enumerates through all the TAPI line devices and
//    queries each for the device name.  The device name is then put into
//    the 'TAPI Line' control.  These device names are kept in order rather
//    than sorted.  This allows "Dial" to know which device ID the user 
//    selected just by the knowing the index of the selected string.
//
//    There are default values if there isn't a device name, if there is
//    an error on the device, or if the device name is an empty string.
//    The device name is also checked to make sure it is null terminated.
//
//    Note that a Legacy API Version is negotiated.  Since the fields in
//    the LINEDEVCAPS structure that we are interested in haven't moved, we
//    can negotiate a lower API Version than this sample is designed for
//    and still be able to access the necessary structure members.
//
//    The first line that is usable by TapiComm is selected as the 'default'
//    line.  Also note that if there was a previously selected line, this
//    remains the default line.  This would likely only occur if this
//    function is called after the dialog has initialized once; for example,
//    if a new line is added.
//
//
void	CDialDlg::FillTAPILine(void)
{
	CWaitCursor	wait;

    DWORD	dwAPIVersion;
    LPLINEDEVCAPS lpLineDevCaps = NULL;
    char szLineUnavail[] = "Line Unavailable";
    char szLineUnnamed[] = "Line Unnamed";
    char szLineNameEmpty[] = "Line Name is Empty";
    LPSTR lpszLineName;
    DWORD dwDefaultDevice = MAXDWORD;

    // Make sure the control is empty.  If it isn't,
    // hold onto the currently selected ID and then reset it.
    if (m_tapiLineBox.GetCount())
    {
        dwDefaultDevice = m_tapiLineBox.GetCurSel();
        m_tapiLineBox.ResetContent();
    }

    for (DWORD  dwDeviceID = 0; dwDeviceID < m_pConn->m_dwNumDevs; ++ dwDeviceID)
    {
        dwAPIVersion = m_pConn->I_lineNegotiateLegacyAPIVersion(dwDeviceID);
        if (dwAPIVersion)
        {
            lpLineDevCaps = m_pConn->I_lineGetDevCaps(lpLineDevCaps,
                dwDeviceID, dwAPIVersion);
            if (lpLineDevCaps)
            {
                if ((lpLineDevCaps->dwLineNameSize) &&
                    (lpLineDevCaps->dwLineNameOffset) &&
                    (lpLineDevCaps->dwStringFormat == STRINGFORMAT_ASCII))
                {
                    // This is the name of the device.
                    lpszLineName = ((char *) lpLineDevCaps) + 
                        lpLineDevCaps->dwLineNameOffset;

                    if (lpszLineName[0] != '\0')
                    {
        // Reverse indented to make this fit

        // Make sure the device name is null terminated.
        if (lpszLineName[lpLineDevCaps->dwLineNameSize -1] != '\0')
        {
            // If the device name is not null terminated, null
            // terminate it.  Yes, this looses the end character.
            // Its a bug in the service provider.
            lpszLineName[lpLineDevCaps->dwLineNameSize-1] = '\0';
            TRACE1("Device name for device 0x%lx is not null terminated.\n",
                dwDeviceID);
        }
                    }
                    else // Line name started with a NULL.
                        lpszLineName = szLineNameEmpty;
                }
                else  // DevCaps doesn't have a valid line name.  Unnamed.
                    lpszLineName = szLineUnnamed;
            }
            else  // Couldn't GetDevCaps.  Line is unavail.
                lpszLineName = szLineUnavail;
        }
        else  // Couldn't NegotiateAPIVersion.  Line is unavail.
            lpszLineName = szLineUnavail;

	   m_tapiLineBox.AddString((LPCTSTR)lpszLineName);

        // If this line is usable and we don't have a default initial
        // line yet, make this the initial line.
        if ((lpszLineName != szLineUnavail) && 
            (dwDefaultDevice == MAXDWORD) &&
            (VerifyUsableLine(dwDeviceID) == TAPISUCCESS))
        {
            dwDefaultDevice = dwDeviceID;
        }
    }

    if (lpLineDevCaps)
	    ::LocalFree(lpLineDevCaps);

    if (dwDefaultDevice == MAXDWORD)
        dwDefaultDevice = 0;

    // Set the initial default line
    m_tapiLineBox.SetCurSel(dwDefaultDevice);
	
}

//
//  PURPOSE: Fill (or refill) the 'Your Location' control
//
//  PARAMETERS:
//    lpszCurrentLocation - Name of current location, or NULL
//    lpdwCountryID - location to store the current country ID or NULL
//    lpszAreaCode - location to store the current area code or NULL
//
//  RETURN VALUE:
//    none
//
//  COMMENTS:
//
//    This function is moderately multipurpose.
//
//    If lpszCurrentLocation is NULL, then the 'Your Location' control
//    is filled with all the locations stored in TAPI and the TAPI 'default' 
//    location is selected.  This is done during initialization and
//    also after the 'Dialing Properties' dialog has been displayed.
//    This last is done because the user can change the current location
//    or add and delete locations while in the 'Dialing Properties' dialog.
//    
//    If lpszCurrentLocation is a valid string pointer, then it is assumed
//    that the 'Your Location' control is already filled and that the user
//    is selecting a specific location.  In this case, all of the existing
//    TAPI locations are enumerated until the specified location is found.
//    At this point, the specified location is set to the current location.
//    
//    In either case, if lpdwCountryID is not NULL, it is filled with the
//    country ID for the current location.  If lpszAreaCode is not NULL, it
//    is filled with the area code defined for the current location.  These
//    values can be used later to initialize other "Dial" controls.
//
//    This function also fills the 'Calling Card' control based on
//    the information stored in the current location.
//
//

void	CDialDlg::FillLocationInfo(CString*  lpszCurrentLocation,
	LPDWORD  lpdwCountryID, CString*  lpszAreaCode)//CString&  lpszAreaCode)
{
	CWaitCursor	wait;

	LPLINETRANSLATECAPS	lpTranslateCaps = NULL;
	DWORD	dwSizeofTranslateCaps = sizeof(LINETRANSLATECAPS);
	long	lReturn;
	DWORD	dwCounter;
	LPLINELOCATIONENTRY	lpLocationEntry;
	LPLINECARDENTRY	lpLineCardEntry = NULL;
	DWORD	dwPreferredCardID = MAXDWORD;

	// First, get the TRANSLATECAPS
	do
	{
		lpTranslateCaps = (LPLINETRANSLATECAPS)CTapiConnection::CheckAndReAllocBuffer(
			(LPVOID)lpTranslateCaps, dwSizeofTranslateCaps);
//            "FillLocationInfo");

		if (lpTranslateCaps == NULL)
			return;

		lReturn = ::lineGetTranslateCaps(m_pConn->m_hLineApp, SAMPLE_TAPI_VERSION, 
			lpTranslateCaps);

		if (m_pConn->HandleLineErr(lReturn))
			;
		else
		{
			OutputDebugLineError(lReturn, 
				"lineGetTranslateCaps unhandled error: ");
			::LocalFree(lpTranslateCaps);
			return;
		}

		if ((lpTranslateCaps->dwNeededSize) >
			(lpTranslateCaps->dwTotalSize))
		{
			dwSizeofTranslateCaps = lpTranslateCaps->dwNeededSize;
			lReturn = -1; // Lets loop again.
		}
	}
	while (lReturn != TAPISUCCESS);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -