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

📄 dlgcloadfont.cpp

📁 传真示例
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	{
		szTmp.Format("   error fx_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 = ATFX_CHTYPE(iBoardHandle);
		switch (iBoardType)
		{
		case DFS_FAX120:
			pBoard->m_szName = "FAX/120";
			break;

		case DFS_FAX40:
			pBoard->m_szName = "VFX/40";
			break;

		case DFS_FAX40E:
			pBoard->m_szName = "VFX/40E";
			break;

		case DFS_FAX40EPLUS:
			pBoard->m_szName = "VFX/40ESC-Plus";
			pBoard->m_szNormalFont = "(none)";
			pBoard->m_szCompressedFont = "(none)";
			break;

		default:
			pBoard->m_szName = "Unknown FAX";
			break;
		}
	}
	fx_close(iBoardHandle);
	return 0;
}

///////////////////////////////////////////////////////////////////////
// Method:
//	int CDlgcLoadFont::DownloadFonts()
//
// Description:
//  Attempt to download all the selected fonts.  This method simply iterates
//  through the boards calling DownloadBoard() for each font.
//
// Inputs : none.
// Outputs: none.
// Returns: 0 on success, non-zero is error.
// Notes  : none.
//
int CDlgcLoadFont::DownloadFonts()
{
	CString szMsg;
	CDlgcLoadFont::CDlgcBoard *pBoard;

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

	m_pStatusDlg->AddString("Downloading Fonts...");
	for (int i=0; i<m_BoardList.GetSize(); i++)
	{
		pBoard = (CDlgcBoard *)m_BoardList[i];
		if (pBoard->IsEscPlus())
		{
			if (pBoard->GetNormalFont() != "(none)")
			{
				szMsg.Format("   Downloading normal font to %s", pBoard->GetName());
				m_pStatusDlg->AddString(szMsg);
				DownloadBoard(pBoard, CDlgcBoard::Normal);
			}
			if (pBoard->GetCompressedFont() != "(none)")
			{
				szMsg.Format("   Downloading compressed font to %s", pBoard->GetName());
				m_pStatusDlg->AddString(szMsg);
				DownloadBoard(pBoard, CDlgcBoard::Compressed);
			}
			m_pStatusDlg->m_Progress.StepIt();
		}
	}

	// Max out meter...
	m_pStatusDlg->m_Progress.SetPos(m_iNumBoards*4);

	return 0;
}

///////////////////////////////////////////////////////////////////////
// Method:
//  int CDlgcLoadFont::DownloadBoard(CDlgcBoard *pBoard, CDlgcBoard::FontType iType)
//
// Description:
//  Attempt to download all the indicated font to the specified board.
//
// Inputs : 
//	CDlgcBoard* pBoard - a pre-initialized CDlgcBoard object.
//  CDlgcBoard::FontType iType - The type of font this is (normal or compressed)
// Outputs: none.
// Returns: 0 on success, non-zero is error.
// Notes  : none.
//
int CDlgcLoadFont::DownloadBoard(CDlgcBoard *pBoard, CDlgcBoard::FontType iType)
{
	CString szMsg;

	// Open the FAX device.
	char szDevice[32];
	strcpy(szDevice, pBoard->m_szDeviceName);
	strcat(szDevice, "C1");
	int faxdev = fx_open(szDevice, NULL);
	if (faxdev == -1)
	{
		m_pStatusDlg->AddString("      Error opening fax channel.");
		return -1;
	}
	m_pStatusDlg->m_Progress.StepIt();

	// Open the font file.
	CString szFilePath;
	if (iType == CDlgcBoard::Normal)
		szFilePath = m_szFontPath + "\\" + pBoard->GetNormalFont();
	else
		szFilePath = m_szFontPath + "\\" + pBoard->GetCompressedFont();

	int hFontFile = dx_fileopen(szFilePath, _O_RDONLY|_O_BINARY);
	if (hFontFile == -1)
	{
		szMsg.Format("      Error opening font file %s.", szFilePath);
		m_pStatusDlg->AddString(szMsg);
		fx_close(faxdev);
		return -1;
	}
	m_pStatusDlg->m_Progress.StepIt();

	// Call the API for load font (synchronous for now...)
	if (fx_loadfont(faxdev, hFontFile, EV_SYNC) == -1)
	{
		int LastError = ATDV_LASTERR(faxdev);
		switch (LastError)
		{
			case EFX_INVALID_FONT:
				m_pStatusDlg->AddString("      - Invalid font file specified.");
				break;

			case EFX_INVALARG:
				m_pStatusDlg->AddString("      - Invalid argument in fx_loadfont().");
				break;

			case EFX_UNSUPPORTED:
				m_pStatusDlg->AddString("      - Fax board must be a EFX40/ESC+.");
				break;

			case EFX_NOTIDLE:
				m_pStatusDlg->AddString("      - Fax board is not idle.");
				break;

			case TFX_FAXERROR:
				m_pStatusDlg->AddString("      - Fax Error.");
				break;

			default:
				szMsg.Format("      - fx_loadfont error: 0x%x %s", ATDV_LASTERR(faxdev), ATDV_ERRMSGP(faxdev));
				m_pStatusDlg->AddString(szMsg);
				break;
		}

		dx_fileclose(hFontFile);
		fx_close(faxdev);
		return -1;
	}
	m_pStatusDlg->m_Progress.StepIt();
	dx_fileclose(hFontFile);
	fx_close(faxdev);
	m_pStatusDlg->AddString("      - download OK.");
	return 0;
}

///////////////////////////////////////////////////////////////////////
// Method:
//	int CDlgcLoadFont::GetSettings()
//
// Description:
//  Read the settings from our private LoadFont.INI file.
//
// Inputs : none.
// Outputs: none.
// Returns: 0 on success, non-zero is error.
// Notes  : none.
//
int CDlgcLoadFont::GetSettings()
{
	m_pStatusDlg->AddString("Reading settings from LoadFont.INI file.");

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

	// Number of boards.
	int iBoardCount = AfxGetApp()->GetProfileInt("Settings", "Board Count", 0);

	// Restore the last saved settings.
	for (int i=0; i<iBoardCount; i++)
	{
		CDlgcBoard *pBoard = new CDlgcBoard;
		CString szSection, rValue;
		
		szSection.Format("dxxxB%d", i+1);
		pBoard->SetDeviceName(szSection);
		rValue = AfxGetApp()->GetProfileString(szSection, "Type","Unknown");
		pBoard->SetName(rValue);

		rValue = AfxGetApp()->GetProfileString(szSection, "Normal Font",
											   "default0.fnt");
		pBoard->SetNormalFont(rValue);

		rValue = AfxGetApp()->GetProfileString(szSection, "Compressed Font",
											   "default3.fnt");
		pBoard->SetCompressedFont(rValue);

		// Add the board to the list.
		m_SettingsList.Add(pBoard);
	}
	return 0;
}

///////////////////////////////////////////////////////////////////////
// Method:
//	int CDlgcLoadFont::SaveSettings()
//
// Description:
//  Writes the settings to our private LoadFont.INI file.
//
// Inputs : none.
// Outputs: none.
// Returns: 0 on success, non-zero is error.
// Notes  : none.
//
int CDlgcLoadFont::SaveSettings()
{
	m_pStatusDlg->AddString("Writing settings to LoadFont.INI file.");

	// Save the font path.
	AfxGetApp()->WriteProfileString("Settings", "Path", m_szFontPath);

	// Now save the number of boards.
	AfxGetApp()->WriteProfileInt("Settings", "Board Count", m_iNumBoards);
	
	// Now save the font settings.
	for (int i=0; i<m_iNumBoards; i++)
	{
		CDlgcBoard *pBoard = (CDlgcBoard*)m_BoardList[i];
		AfxGetApp()->WriteProfileString(pBoard->GetDeviceName(),
										"Type",
										pBoard->GetName());
		AfxGetApp()->WriteProfileString(pBoard->GetDeviceName(),
										"Normal Font",
										pBoard->GetNormalFont());
		AfxGetApp()->WriteProfileString(pBoard->GetDeviceName(),
										"Compressed Font",
										pBoard->GetCompressedFont());
	}
	return 0;
}

///////////////////////////////////////////////////////////////////////
// Method:
//	int CDlgcLoadFont::MergeSettings()
//
// Description:
//  This method compares, board by board, the settings in the .INI file
//  to the settings acquired during initialization.  If the settings
//  match, they are merged into the local copy.  If they diverge, then
//  the m_bDisjointSettings flag is set.
//
// Inputs : none.
// Outputs: none.
// Returns: 0 if successful or -1 if the settings are disjoint.
// Notes  : none.
//
int CDlgcLoadFont::MergeSettings()
{
	m_pStatusDlg->AddString("Comparing previous settings with current ones.");

	// Compare each read setting to the ones acquired during start-up.
	//
	CDlgcBoard localBoard, settingBoard;
	for (int i=0; i<m_BoardList.GetSize(); i++)
	{
		if (m_SettingsList.GetSize() > i)
		{
			localBoard = *(CDlgcBoard*)m_BoardList[i]; 
			settingBoard = *(CDlgcBoard*)m_SettingsList[i];
			if (localBoard == settingBoard)
			{
				// Merge them into our BoardList.
				*(CDlgcBoard*)m_BoardList[i] = *(CDlgcBoard*)m_SettingsList[i];
			}
			else
			{
				// Prevent auto-download.
				m_bDisjointSettings = TRUE;
				CString szMsg;
				szMsg.Format("   - Error merging board index %d", i);
				m_pStatusDlg->AddString(szMsg);
				m_pStatusDlg->AddString("   - configuration mis-match.");
				return -1;
			}
		}
		else
			// Board count differs...
			return -1;
	}
	m_pStatusDlg->AddString("   - configurations match.");
	return 0;
}


///////////////////////////////////////////////////////////////////////
// Method:
//	int CDlgcLoadFont::GetSwitches()
//
// Description:
//  This method checks the command line for start-up switches.
//
// Inputs : none.
// Outputs: none.
// Returns: 0 if successful or -1 in error.
// Notes  : none.
//
int CDlgcLoadFont::GetSwitches()
{
	CString szTmp;

	// Look for the command line switch /auto.
	//
	if (__argc >= 2)
	{
		szTmp = __argv[1];
		szTmp.MakeUpper();
		if (szTmp == "/AUTO")
			m_bAutoDownload = TRUE;
		else
			m_bAutoDownload = FALSE;
	}
	return 0;
}

///////////////////////////////////////////////////////////////////////
// Method:
//  CDlgcLoadFont::CDlgcBoard
//
// Description:
//  This constructor initializes the data members to their defaults.
//
// Inputs : n/a
// Outputs: n/a
// Returns: n/a
// Notes  : none.
//
CDlgcLoadFont::CDlgcBoard::CDlgcBoard()
{
	// Just initialize the member data to some defaults.
	//
	m_szName = "unknown";
	m_szDeviceName = "dxxxB?";
	m_szNormalFont = "n/a";
	m_szCompressedFont = "n/a";
}

///////////////////////////////////////////////////////////////////////
// Method:
//	CDlgcLoadFont::CDlgcBoard::CDlgcBoard(CDlgcBoard& otherBoard)
//
// Description:
//  This is the copy constructor for the CDlgcBoard class.
//
// Inputs : CDlgcBoard &otherBoard - Reference to otherBoard
// Outputs: n/a
// Returns: n/a
// Notes  : none.
//
CDlgcLoadFont::CDlgcBoard::CDlgcBoard(CDlgcBoard& otherBoard)
{
	m_szName = otherBoard.m_szName;
	m_szDeviceName = otherBoard.m_szDeviceName;
	m_szNormalFont = otherBoard.m_szNormalFont;
	m_szCompressedFont = otherBoard.m_szCompressedFont;
}

///////////////////////////////////////////////////////////////////////
// Method:
//	int CDlgcLoadFont::CDlgcBoard::operator == (CDlgcBoard otherBoard)
//
// Description:
//  This method overloads the == operator for the CDlgcBoard class.
//
// Inputs : CDlgcBoard otherBoard - the other CDlgcBoard object to compare.
// Outputs: n/a
// Returns: 1 if they are equal, 0 otherwise.
// Notes  : none.
//
int CDlgcLoadFont::CDlgcBoard::operator == (CDlgcBoard otherBoard)
{
	// They are considered equal if the board and device names are the same.
	if ( (m_szName == otherBoard.m_szName) &&
		 (m_szDeviceName == otherBoard.m_szDeviceName))
		return 1;
	else
		return 0;
}

///////////////////////////////////////////////////////////////////////
// Method:
//	CDlgcLoadFont::CDlgcBoard&
//    CDlgcLoadFont::CDlgcBoard::operator = (CDlgcBoard& otherBoard)
//
// Description:
//  This method overloads the = assignment operator for the CDlgcBoard class.
//
// Inputs : CDlgcBoard& otherBoard - the other CDlgcBoard object to copy.
// Outputs: n/a
// Returns: 1 if they are equal, 0 otherwise.
// Notes  : none.
//
CDlgcLoadFont::CDlgcBoard&
  CDlgcLoadFont::CDlgcBoard::operator = (CDlgcBoard& otherBoard)
{
	// Dupe it.
	m_szName = otherBoard.m_szName;
	m_szDeviceName = otherBoard.m_szDeviceName;
	m_szNormalFont = otherBoard.m_szNormalFont;
	m_szCompressedFont = otherBoard.m_szCompressedFont;
	return *this;
}

///////////////////////////////////////////////////////////////////////
// Method:
//	int CDlgcLoadFont::CDlgcBoard::IsEscPlus()
//
// Description:
//  Simply compares the board name to FAX/40ESC-Plus to indicate whether
//  or not it matches.
//
// Inputs : n/a
// Outputs: n/a
// Returns: 1 if the name matches, 0 otherwise.
// Notes  : none.
//
int CDlgcLoadFont::CDlgcBoard::IsEscPlus()
{
	return m_szName == "VFX/40ESCplus";
}

⌨️ 快捷键说明

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