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

📄 dlgcloadfont.cpp

📁 传真示例
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// $Header: /LoadFont/DlgcLoadFont.cpp 10    6/24/96 11:05a Stonea $
/********************************************************************
 *  Copyright (c) 1996 Dialogic Corporation
 *  All Rights Reserved             
 *
 *  THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF Dialogic Corp.   
 *  The copyright notice above does not evidence any actual or  
 *  intended publication of such source code.               
 ********************************************************************/

// Class:  CDlgcLoadFont
// 
#include "stdafx.h"
#include "Status.h"
#include "DlgcLoadFont.h"
#include "FontBrowse.h"
#include "srllib.h"
#include "dxxxlib.h"
#include "faxlib.h"
#include <fcntl.h>
#include <io.h>

///////////////////////////////////////////////////////////////////////
// Method:
//  CDlgcLoadFont::CDlgcLoadFont
//
// Description:
//  Creates a CStatus::CDialog object for logging.  By default this window
//  is hidden and only visible when the user enables it via the menu or
//  toolbar or if the application is started with autostart enabled.
//
//  The constructor also identifies the driver, boards, and fonts in the
//  system.  Builds a 
//
// Inputs : n/a
// Outputs: n/a
// Returns: n/a
// Notes  : none.
//
CDlgcLoadFont::CDlgcLoadFont()
{
	// Initialize some variables.
	m_iNumBoards = 0;
	m_bDisjointSettings = FALSE;
	m_bAutoDownload = FALSE;
	m_bDownloadable = FALSE;
	m_szFontPath = "";

	// Check if the /auto parmeter was specified to indicate auto-download...
	//

	// Create our modeless Status dialog box.
	// This is used throughout the CDlgcLoadFont class for logging status
	// information.  By default it is turned off.  It can be viewed by
	// pressing the toolbar button or selecting it from the menu.
	//
	m_pStatusDlg = new CStatus;
	if (!m_pStatusDlg)
		AfxMessageBox("Error creating CStatus dialog box.");
	m_pStatusDlg->Create(CStatus::IDD);

	// Move it to the upper right hand corner of the screen area.
	//
	RECT rectDesk, rectClient;
	::GetWindowRect(GetDesktopWindow(), &rectDesk);
	::GetWindowRect(m_pStatusDlg->m_hWnd, &rectClient);
	m_pStatusDlg->MoveWindow(rectDesk.right-(rectClient.right-rectClient.left),
		                     0,
							 rectClient.right-rectClient.left,
							 rectClient.bottom-rectClient.top);

	// Start the application with the status window hidden.
	m_pStatusDlg->ShowWindow(SW_HIDE);
	m_pStatusDlg->UpdateWindow();

	// Check the command line.
	GetSwitches();

	// Initialize the font path.
	m_szFontPath = AfxGetApp()->GetProfileString("Settings", "Path", "");

	// Now query the system and collect the boards and fonts.
	// If any of GetDriverInfo, GetBoards, or GetFonts return non-zero
	// then downloading is disabled.
	//
	BOOL bDriverErr = FALSE;
	m_bDownloadable = TRUE;
	if (GetDriverInfo() < 0)
	{
		m_bDownloadable = FALSE;
		bDriverErr = TRUE;
		AfxMessageBox("Unable to talk to driver.  You will not be able to download.");
	}
	if (bDriverErr == FALSE)
	{
		if (GetBoards() < 0)
		{
			m_bDownloadable = FALSE;
			AfxMessageBox("No boards found.  You will not be able to download.");
		}
	}

	// Grab the fonts...
	int numFonts = 0;
	long dlgReturn = IDOK;
	do {
		if ((numFonts=GetFonts()) <= 0) {
			// No fonts found.  Bring up a dialog box to browse.
			CFontBrowse dlg;
			if ((dlgReturn=dlg.DoModal()) != IDCANCEL)
			{
				// Store the file name.
				m_szFontPath = dlg.m_EditPath;
				AfxGetApp()->WriteProfileString("Settings",
												"Path",
												m_szFontPath);
			}
		}
	} while ((dlgReturn != IDCANCEL) && (numFonts ==0));
	
	// Try to get previous settings if they exist.  They are stored in the
	// loadfont.ini file.
	//
	GetSettings();
  
	// Merge Settings() automagically detects hardware and previously stored
	// changes and will prevent auto-download if the present and saved
	// hardware do not concur.  Otherwise the settings are merged into the 
	// working m_BoardList board array.
	MergeSettings();

	// Check if the auto-download flag is set.  If so, start downloading
	// if we can.  If the download is successful, quiety dis-appear.  If
	// there was a failure, then make the status box visible and await
	// user interaction.
	//
	if ((m_bAutoDownload == TRUE) && (m_bDownloadable == TRUE))
	{
		m_pStatusDlg->ShowWindow(SW_SHOW);
		m_pStatusDlg->UpdateWindow();
		if (DownloadFonts())
		{
			// Download failure...
			AfxMessageBox("Download failure.  Check the status box.");
		}
		AfxGetMainWnd()->PostMessage(WM_CLOSE);
	}
}

///////////////////////////////////////////////////////////////////////
// Method:
//  CDlgcLoadFont::~CDlgcLoadFont()
//
// Description:
//  Iterate through the board list and free all the CDlgcBoard objects
//  we created.  The CObArray destructor does not do this for us.
//  Delete the CStatus dialog box object.
//
// Inputs : n/a
// Outputs: n/a
// Returns: n/a
// Notes  : none.
//
CDlgcLoadFont::~CDlgcLoadFont()
{
	// Save our present settings.
	SaveSettings();

	// Delete all the boards we created on the heap for our board lists.
	int i;
	for (i=0; i<m_BoardList.GetSize(); i++)
		delete m_BoardList[i];

	for (i=0; i<m_SettingsList.GetSize(); i++)
		delete m_SettingsList[i];

	// Delete the dialog resource.
	if (m_pStatusDlg)
	{
		m_pStatusDlg->DestroyWindow();
		delete m_pStatusDlg;
	}
}

///////////////////////////////////////////////////////////////////////
// Method:
//   int CDlgcLoadFont::GetBoards()
//
// Description:
//  Query the board count from srllib and then open each board and try
//  to identify it.
//  Each CDlgcBoard object will be qualified whether or not it is a
//  FAX board.
//
// Inputs : none.
// Outputs: none.
// Returns: The number of boards found or a negative error number.
// Notes  : This method creates CDlgcBoard objects on the heap.
//          They are destroyed in this class's destructor.
//
int CDlgcLoadFont::GetBoards()
{
	CString szTmp;

	m_pStatusDlg->AddString("Looking for boards...");

	// Ask srllib how many boards there are.
	if (sr_getboardcnt(DEV_CLASS_VOICE, &m_iNumBoards) == -1)
	{
		m_pStatusDlg->AddString("   - sr_getboardcnt() failure.");
		return -1;
	}
	szTmp.Format("   - srllib reports %d board(s).", m_iNumBoards);
	m_pStatusDlg->AddString(szTmp);

	// Setup the progress bar metrics.
	m_pStatusDlg->m_Progress.SetRange(0, m_iNumBoards);
	m_pStatusDlg->m_Progress.SetStep(1);
	m_pStatusDlg->m_Progress.SetPos(0);

	// Go and fetch the boards. Identifying each one if we can.
	//
	for (int iBoard=1; iBoard<=m_iNumBoards; iBoard++)
	{
		CDlgcBoard *pBoard = new CDlgcBoard;
		if (!pBoard)
		{
			m_pStatusDlg->AddString("   - could not create a board object.");
			return -1;
		}

		// Identify and fill in the Board object.
		IdentifyBoard(iBoard, pBoard);

		// Add it to the list.
		m_BoardList.Add(pBoard);

		// Show it in the progress box.
		szTmp.Format("      - %s", pBoard->GetName());
		m_pStatusDlg->AddString(szTmp);

		// Bump our status bar.
		m_pStatusDlg->m_Progress.StepIt();
	}

	// Let the caller know how many boards we found.
	return m_iNumBoards;
}

///////////////////////////////////////////////////////////////////////
// Method:
//  int CDlgcLoadFont::GetFonts()
//
// Description:
//  Read the font directory from our INI file.  If one does not exist,
//  then bring up a modal dialog box to specify the font path then use it.
//  Next, scan the specified directory for all *.fnt files.
//  Check the header of each one and populate one of two string
//  arrays with the font's file name.  The two string arrays represent 
//  a normal or compressed font path and file name.  These lists
//  are used by the CView class for a pop-up menu for font selection on
//  the board grid.
//
// Inputs : none.
// Outputs: none.
// Returns: The number of fonts found or a negative error number.
// Notes  : none.
//
int CDlgcLoadFont::GetFonts()
{
	HANDLE hFileFind;
	WIN32_FIND_DATA FileData;
	CFile FontFile;
	short int buff;
	CString szSearchPath, szTemp, szMsg;
	enum {MaxFonts = 20};

	szMsg.Format("Looking for fonts in %s", m_szFontPath);
	m_pStatusDlg->AddString(szMsg);

	// Setup the progress bar metrics.
	m_pStatusDlg->m_Progress.SetRange(0, MaxFonts);
	m_pStatusDlg->m_Progress.SetStep(1);
	m_pStatusDlg->m_Progress.SetPos(0);

	// Append .fnt to the supplied directory.
	szSearchPath = m_szFontPath + "\\*.fnt";

	// Search for the font files.
	int iNormalCount = 0;
	int iCompressedCount = 0;
	if ((hFileFind=FindFirstFile(szSearchPath, &FileData)) != INVALID_HANDLE_VALUE)
	{
		// Got at least 1 matching file.
		do {
			// Process file and add to appropriate CStringArray.
			szTemp = m_szFontPath + "\\" + FileData.cFileName;
			if (FontFile.Open(szTemp, CFile::modeRead) == TRUE)
			{
				// File has been opened.
				if (FontFile.Read((char *) &buff, sizeof(buff)) == sizeof(buff))
				{
					// Check header to determine font size.
					szTemp = FileData.cFileName;
					szTemp.MakeLower();
					if (buff == 0x10c0)
					{
						NormalFonts.Add(szTemp);
						iNormalCount++;
						//szMsg.Format("   - found normal font: %s", szTemp);
						//m_pStatusDlg->AddString(szMsg);
						m_pStatusDlg->m_Progress.StepIt();
					}

					if (buff == 0x0cc0)
					{
						CompressedFonts.Add(szTemp);
						iCompressedCount++;
						//szMsg.Format("   - found compressed font: %s", szTemp);
						//m_pStatusDlg->AddString(szMsg);
						m_pStatusDlg->m_Progress.StepIt();
					}
				}
				// Close the file.
				FontFile.Close();
			}
			// Get next file
		} while (FindNextFile(hFileFind, &FileData));
		// No more files, close search handle.
		FindClose(hFileFind);
	}

	szMsg.Format("   - found %d normal fonts.", iNormalCount);
	m_pStatusDlg->AddString(szMsg);
	szMsg.Format("   - found %d compressed fonts.", iCompressedCount);
	m_pStatusDlg->AddString(szMsg);

	// All done, max out the meter...
	m_pStatusDlg->m_Progress.SetPos(MaxFonts);
	return iNormalCount+iCompressedCount;
}

///////////////////////////////////////////////////////////////////////
// Method:
//  int CDlgcLoadFont::GetDriverInfo()
//
// Description:
//  Just perform a simple test to see if we can talk to the fax library.
//  It will put the version information into the trace log.
//
// Inputs : none.
// Outputs: none.
// Returns: 0 on success, non-zero is error.
// Notes  : none.
//
int CDlgcLoadFont::GetDriverInfo()
{
	// If the application got this far then the appropriate DLL's
	// have already been found and loaded at startup.
	//
	// So lets verify that we can talk to the driver now.
	m_pStatusDlg->AddString("Checking driver");
	int FaxDev = fx_open("dxxxB1C1", NULL);
	if (FaxDev == -1)
	{
		m_pStatusDlg->AddString("   - Error opening fax channel.");
		return -1;
	}
	else
	{
		CString VersionMsg;
		VersionMsg.Format("   - libfaxmt.dll version: '%s'", ATFX_FXVERSION(FaxDev));
		m_pStatusDlg->AddString(VersionMsg);
	}
	fx_close(FaxDev);
	return 0;
}

///////////////////////////////////////////////////////////////////////
// Method:
//	int CDlgcLoadFont::IdentifyBoard(int iBoardNum, CDlgcBoard *pBoard)
//
// Description:
//  Open the specified board number and try to identify what the board is.
//
// Inputs :
//	int iBoardNum - The index of the board in the host.
// Outputs:
//  CDlgcBoard *pBoard - A pointer to a pre-allocated CDlgcBoard object. 
// Returns: 0 on success, non-zero is error.
// Notes  : none.
//
int CDlgcLoadFont::IdentifyBoard(int iBoardNum, CDlgcBoard *pBoard)
{
	CString szTmp;

	pBoard->m_szDeviceName.Format("dxxxB%d", iBoardNum);

	int iBoardHandle;
	if ( (iBoardHandle=dx_open(pBoard->m_szDeviceName, NULL)) == -1)
	{
		szTmp.Format("   error dx_opening board %s", pBoard->m_szDeviceName);
		m_pStatusDlg->AddString(szTmp);
		m_pStatusDlg->UpdateWindow();
		return -1;
	}
	else
	{
		// We successfully opened the board, now find out what it is.
		int iBoardType = ATDX_BDTYPE(iBoardHandle);
		switch (iBoardType)
		{
		case DI_D20BD:
			pBoard->m_szName = "D/20";
			break;

		case DI_D21BD:
			pBoard->m_szName = "D/21";
			break;

		case DI_D40BD:
			pBoard->m_szName = "D/40";
			break;

		case DI_D41BD:
			pBoard->m_szName = "D/41";
			break;

		case DI_D20CH:
			pBoard->m_szName = "D/20CH";
			break;

		case DI_D21CH:
			pBoard->m_szName = "D/21CH";
			break;

		case DI_D40CH:
			pBoard->m_szName = "D/40CH";
			break;

		case DI_D41CH:
			pBoard->m_szName = "D/41CH";
			break;

		default:
			pBoard->m_szName = "(unknown)";
			break;
		}
	}
	dx_close(iBoardHandle);

	// Now lets see if this is a FAX board.
	char szDevice[32];
	strcpy(szDevice, pBoard->m_szDeviceName);
	strcat(szDevice, "C1");
	if ( (iBoardHandle=fx_open(szDevice, NULL)) == -1)

⌨️ 快捷键说明

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