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

📄 dialdlg._cp

📁 串口调试助手的源代码
💻 _CP
📖 第 1 页 / 共 3 页
字号:
	// Find the location information in the TRANSLATECAPS
	lpLocationEntry = (LPLINELOCATIONENTRY)
		(((LPBYTE)lpTranslateCaps) + lpTranslateCaps->dwLocationListOffset);

	// If lpszCurrentLocation, then make that location 'current'
	if (lpszCurrentLocation)
	{
		// loop through all locations, looking for a location match
		for (dwCounter = 0; 
			dwCounter < lpTranslateCaps->dwNumLocations;
			++ dwCounter)
		{
			CString	str = ((LPSTR) lpTranslateCaps) + 
				lpLocationEntry[dwCounter].dwLocationNameOffset;
				
			if (str == *lpszCurrentLocation)
/*			if (strcmp((((LPSTR) lpTranslateCaps) + 
				lpLocationEntry[dwCounter].dwLocationNameOffset),
				lpszCurrentLocation) == 0)*/
			{
				// Found it!  Set the current location.
				::lineSetCurrentLocation(m_pConn->m_hLineApp, 
					lpLocationEntry[dwCounter].dwPermanentLocationID);

				// Set the return values.
				if (lpdwCountryID)
					*lpdwCountryID = lpLocationEntry[dwCounter].dwCountryID;

//				if (lpszAreaCode)
//					strcpy(lpszAreaCode, (((LPSTR) lpTranslateCaps) + 
//						lpLocationEntry[dwCounter].dwCityCodeOffset));

				if (lpszAreaCode != NULL)
					*lpszAreaCode = ((LPSTR)lpTranslateCaps) + 
						lpLocationEntry[dwCounter].dwCityCodeOffset;

				// Store the preferred card ID for later use.
				dwPreferredCardID = lpLocationEntry[dwCounter].dwPreferredCardID;
				break;
			}
		}

		// Was a match for lpszCurrentLocation found?
		if (dwPreferredCardID == MAXDWORD)
		{
			TRACE0("lpszCurrentLocation not found\n");
			m_callingCard.SetWindowText(_T("Invalid Location Selected"));
			::LocalFree(lpTranslateCaps);
			return;
		}
	}
	else // fill the combobox and use the TAPI 'current' location.
	{
		// First empty the combobox
		m_locationBox.ResetContent();
//		SendDlgItemMessage(IDC_LOCATION, CB_RESETCONTENT, 0, 0);
    
		// enumerate all the locations
		for (dwCounter = 0; 
			dwCounter < lpTranslateCaps->dwNumLocations;
			++ dwCounter)
		{
			// Put each one into the combobox
			CString	strLocation = (((LPBYTE) lpTranslateCaps) + 
				lpLocationEntry[dwCounter].dwLocationNameOffset);
			m_locationBox.AddString(strLocation);

			// Is this location the 'current' location?
			if (lpLocationEntry[dwCounter].dwPermanentLocationID ==
				lpTranslateCaps->dwCurrentLocationID)
			{
				// Return the requested information
				if (lpdwCountryID)
					*lpdwCountryID = lpLocationEntry[dwCounter].dwCountryID;

				if (lpszAreaCode != 0)
					*lpszAreaCode = ((LPSTR) lpTranslateCaps) + 
						lpLocationEntry[dwCounter].dwCityCodeOffset;
//					strcpy(lpszAreaCode, (((LPSTR) lpTranslateCaps) + 
//						lpLocationEntry[dwCounter].dwCityCodeOffset));

				// Set this to be the active location.
//				SendDlgItemMessage(IDC_LOCATION, CB_SETCURSEL, lReturn, 0);
				m_locationBox.SetCurSel(lReturn);
				dwPreferredCardID = lpLocationEntry[dwCounter].dwPreferredCardID;
			}
		}
	}

	// Now locate the prefered card and display it.

	lpLineCardEntry = (LPLINECARDENTRY)
		(((LPBYTE) lpTranslateCaps) + lpTranslateCaps->dwCardListOffset);

	for (dwCounter = 0; 
		dwCounter < lpTranslateCaps->dwNumCards;
		++ dwCounter)
	{
		if (lpLineCardEntry[dwCounter].dwPermanentCardID == dwPreferredCardID)
		{
			CString	strCardName = ((LPBYTE)lpTranslateCaps) + 
				lpLineCardEntry[dwCounter].dwCardNameOffset;
			m_callingCard.SetWindowText(strCardName);
			break;
		}
	}

	::LocalFree(lpTranslateCaps);
}


//
//  FUNCTION: void UseDialingRules(HWND)
//
//  PURPOSE: Enable/disable Dialing Rule controls
//
//  RETURN VALUE:
//    none
//
//  COMMENTS:
//
//    The sole purpose of this function is to enable or disable
//    the controls that apply to dialing rules if the 
//    "Use Country Code and Area Code" checkbox is checked or unchecked,
//    as appropriate.
//
//
void	CDialDlg::UseDialingRules()
{
	BOOL	bEnableWindow = m_useDialingRules.GetCheck();

	GetDlgItem(IDC_STATICCOUNTRYCODE)->EnableWindow(bEnableWindow);
	GetDlgItem(IDC_STATICAREACODE)->EnableWindow(bEnableWindow);
	GetDlgItem(IDC_STATICLOCATION)->EnableWindow(bEnableWindow);
	GetDlgItem(IDC_STATICCALLINGCARD)->EnableWindow(bEnableWindow);

	m_countryCode.EnableWindow(bEnableWindow);
	m_areaCode.EnableWindow(bEnableWindow);
	m_locationBox.EnableWindow(bEnableWindow);

	m_callingCard.EnableWindow(bEnableWindow);

	if (m_configureLine.IsWindowEnabled())
	{
		m_dialingProperties.EnableWindow(bEnableWindow);
	}
}

//
//  FUNCTION: void DisplayPhoneNumber(HWND)
//
//  PURPOSE: Create, Translate and Display the Phone Number
//
//
//  RETURN VALUE:
//    none
//
//  COMMENTS:
//
//    This function uses the information stored in many other controls
//    to build the phone number, translate it, and display it.  Also
//    makes sure the Dial button is enabled or disabled, based on if the
//    number can be dialed or not.
//
//    There are actually three phone numbers generated during this
//    process:  canonical, dialable and displayable.  Normally, only the
//    displayable number is shown to the user; the other two numbers are
//    to be used by the program internally.  However, for demonstration
//    purposes (and because it is cool for developers to see these numbers),
//    all three numbers are displayed.
//
void	CDialDlg::DisplayPhoneNumber(void)
{
	LPLINETRANSLATEOUTPUT	lpLineTranslateOutput = NULL;
		CString	szTempBuffer;

	// Disable the 'dial' button if there isn't a number to dial
	if (m_phoneNumber.LineLength() == 0)
	{
		m_strCanonicalNumber = _T("");
		m_strDialableNumber = _T("");
		m_strDisplayableNumber = _T("无电话号码");
		UpdateData(FALSE);
		m_dialButton.EnableWindow(FALSE);
		return;
	}

	// If we use the dialing rules, lets make canonical format.
	// Canonical format is explained in the TAPI documentation and the
	// string format needs to be followed very strictly.

	m_strCanonicalNumber = _T("");
	if (m_useDialingRules.GetCheck())
	{
		// First character *has* to be the plus sign.
		m_strCanonicalNumber += '+';

		// The country code *has* to be next.
		// Country code was stored in the string with the country
		// name and needs to be extracted at this point.
		int	i = m_countryCode.GetCurSel();
		m_countryCode.GetLBText(i, szTempBuffer);

		// Country code is at the end of the string, surounded by parens.
		// This makes it easy to identify the country code.

		int	nStart = szTempBuffer.ReverseFind(_T('('));
		int	nEnd = szTempBuffer.Find(_T(')'));
		m_strCanonicalNumber += szTempBuffer.Mid(nStart + 1, nEnd - nStart - 1);

		// Next is the area code.
		m_areaCode.GetWindowText(szTempBuffer);

		// Note that the area code is optional.  If it is included,
		// then it has to be preceeded by *exactly* one space and it
		// *has* to be surrounded by parens.
		if (i)
		{
			m_strCanonicalNumber += _T(" (");
			m_strCanonicalNumber += szTempBuffer;
			m_strCanonicalNumber += _T(')');
		}

		// There has to be *exactly* one space before the rest of the number.
		m_strCanonicalNumber += ' ';

		// At this point, the phone number is appended to the
		// canonical number.  The next step is the same whether canonical
		// format is used or not; just the prepended area code and 
		// country code are different.
	}

	m_phoneNumber.GetWindowText(szTempBuffer);
	m_strCanonicalNumber += szTempBuffer;

	DWORD	dwDeviceID = m_tapiLineBox.GetCurSel();

	// Translate the address!
	lpLineTranslateOutput = I_lineTranslateAddress(
		lpLineTranslateOutput, dwDeviceID, SAMPLE_TAPI_VERSION,
        /*szPreTranslatedNumber*/m_strCanonicalNumber);

	// Unable to translate it?
	if (lpLineTranslateOutput == NULL)
	{
		m_strCanonicalNumber = _T("");
		m_strDialableNumber = _T("");
		m_strDisplayableNumber = _T("非法的电话号码或地区号码");
		UpdateData(FALSE);

		m_dialButton.EnableWindow(FALSE);
		return;
	}

	// Is the selected device useable with TapiComm?
	if (m_pConn->m_dwDeviceID != MAXDWORD)
		m_dialButton.EnableWindow(TRUE);

	// Fill the appropriate phone number controls.
	m_strDialableNumber = ((LPSTR) lpLineTranslateOutput +
		lpLineTranslateOutput->dwDialableStringOffset);

	m_strDisplayableNumber = ((LPSTR) lpLineTranslateOutput +
		lpLineTranslateOutput->dwDisplayableStringOffset);

	UpdateData(FALSE);
	::LocalFree(lpLineTranslateOutput);
}

//
//  FUNCTION: void FillCountryCodeList(HWND, DWORD)
//
//  PURPOSE: Fill the 'Country Code' control
//
//  PARAMETERS:
//    dwDefaultCountryID - ID of the 'default' country to be selected
//
//  RETURN VALUE:
//    none
//
//  COMMENTS:
//
//    This function fills the 'Country Code' control with country names.
//    The country code is appended to the end of the name and the names
//    are added to the control sorted.  Because the country code is
//    embedded in the string along with the country name, there is no need
//    for any of the country information structures to be kept around.  The 
//    country code can be extracted from the selected string at any time.
//
//
void	CDialDlg::FillCountryCodeList(DWORD  dwDefaultCountryID)
{
	CWaitCursor	wait;

	LPLINECOUNTRYLIST	lpLineCountryList = NULL;
	DWORD	dwSizeofCountryList = sizeof(LINECOUNTRYLIST);
	long	lReturn;
	DWORD	dwCountry;
	LPLINECOUNTRYENTRY	lpLineCountryEntries;
	char	szRenamedCountry[256];

	// Get the country information stored in TAPI
	do
	{
		lpLineCountryList = (LPLINECOUNTRYLIST)CTapiConnection::CheckAndReAllocBuffer(
			(LPVOID)lpLineCountryList, dwSizeofCountryList);//,
//            "FillCountryCodeList");

		if (lpLineCountryList == NULL)
			return;

		lReturn = ::lineGetCountry(0, SAMPLE_TAPI_VERSION, lpLineCountryList);

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

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

	// Find the first country entry
	lpLineCountryEntries = (LPLINECOUNTRYENTRY)
		(((LPBYTE)lpLineCountryList) +
		lpLineCountryList->dwCountryListOffset);

	// Now enumerate through all the countries
	for (dwCountry = 0; 
		dwCountry < lpLineCountryList->dwNumCountries;
		++ dwCountry)
	{
		// append the country code to the country name
		wsprintf(szRenamedCountry,"%s -- (%lu)",
			(((LPSTR)lpLineCountryList) +
			lpLineCountryEntries[dwCountry].dwCountryNameOffset),
			lpLineCountryEntries[dwCountry].dwCountryCode);

		// Now put this country name / code string into the combobox
		int	index = m_countryCode.AddString(szRenamedCountry);

		// If this country is the default country, select it.
		if (lpLineCountryEntries[dwCountry].dwCountryID
			== dwDefaultCountryID)
		{
			m_countryCode.SetCurSel(index);
		}
	}
    
	::LocalFree(lpLineCountryList);
	return;
}

//
//  FUNCTION: BOOL VerifyAndWarnUsableLine(HWND)
//
//  PURPOSE: Verifies the line device selected by the user.
//
//  PARAMETERS:
//    hwndDlg - The handle to the current "Dial" dialog.
//
//  RETURN VALUE:
//    Returns TRUE if the currently selected line device is useable
//      by TapiComm.  Returns FALSE if it isn't.
//
//  COMMENTS:
//
//    This function is very specific to the "Dial" dialog.  It gets
//    the device selected by the user from the 'TAPI Line' control and
//    VerifyUsableLine to make sure this line device is usable.  If the
//    line isn't useable, it notifies the user and disables the 'Dial'
//    button so that the user can't initiate a call with this line.
//
//    This function is also responsible for filling in the line specific
//    icon found on the "Dial" dialog.
//
//
BOOL	CDialDlg::VerifyAndWarnUsableLine(void)
{
	// Get the selected line device.
	DWORD	dwDeviceID = m_tapiLineBox.GetCurSel();

	// Get the "comm" device icon associated with this line device.
	HICON	hIcon;;
	long	lReturn = ::lineGetIcon(dwDeviceID, NULL,/*"comm",*/ &hIcon);
	if (lReturn != TAPISUCCESS)
		hIcon = ::AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_lineIcon.SetIcon(hIcon);

	// Verify if the device is usable by TapiComm.
	lReturn = VerifyUsableLine(dwDeviceID);

	// Enable or disable the 'Dial' button, depending on if the line is ok.
	// Make sure there is a number to dial before enabling the button.
	UpdateData(TRUE);
	if (m_strCanonicalNumber.GetLength() == 0)
    {
        m_dialButton.EnableWindow(FALSE);
    }
    else
        m_dialButton.EnableWindow((lReturn == TAPISUCCESS));

    // Any errors on this line prevent us from configuring it
    // or using dialing properties.
    if (lReturn == LINENOTUSEABLE_ERROR)
    {
        m_configureLine.EnableWindow(FALSE);
        m_dialingProperties.EnableWindow(FALSE);
    }
    else
    {
        m_configureLine.EnableWindow(TRUE);
	   if (m_useDialingRules.GetCheck())
            m_dialingProperties.EnableWindow(TRUE);
    }

	switch (lReturn)
	{
	case TAPISUCCESS:
		m_pConn->m_dwDeviceID = dwDeviceID;
		return TRUE;

	case LINENOTUSEABLE_ERROR:
		MessageBox("The selected line is incompatible with the TapiComm sample",
			"Warning",MB_OK);
		break;

	case LINENOTUSEABLE_NOVOICE:
		MessageBox("The selected line doesn't support VOICE capabilities",
			"Warning",MB_OK);
		break;

⌨️ 快捷键说明

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