ksg_print.cpp

来自「对日本KSG震动探测仪器编写的伴侣服务代码」· C++ 代码 · 共 1,072 行 · 第 1/3 页

CPP
1,072
字号
// (Version 1.00 :: 10-Mar-1999 :: Harutoshi Yoshida)
/*===================================================================
	恔搙忣曬僱僢僩儚乕僋僔僗僥儉
	-----------------------------------
		報嶞娭學 Module
	-----------------------------------
	Program Name        : KSG_Print.CPP
	Program Start       : 05-Jan-1999
	Program Completed   : 
===================================================================*/

#include "stdafx.h"
#include "KSG.h"
#include "KSGDoc.h"
#include "KSGView.h"

#include "msflexgrid.h"
#include "Dlg_Mag.h"
#include "Dlg_LogInfo.h"

#include "C_Proc.h"
#include "C_File.h"
#include "C_Work.h"
#include "KSG_File.h"

//-----( 掕悢愰尵 )-----
#define		MAX_COL	15							// 僌儕僢僪嵟戝悢

//-----( 曄悢愰尵 )-----
HFONT		mOldFont;							// 尦偺 Font 曐懚梡
CFont		mPrtFont[3];						// 報嶞梡 Font
												//  [0]:S
												//  [1]:M
												//  [2]:L
int			Print_w;							// 報嶞(僋儔僀傾儞僩椞堟)暆
int			Print_h;							// 報嶞(僋儔僀傾儞僩椞堟)崅偝
int			Print_FontS[3] = {					// 報嶞僼僅儞僩僒僀僘
			0,									//  S
			0,									//  M
			0									//  L
};
CRect		Print_Ofs;							// 報嶞梡忋壓嵍塃僆僼僙僢僩

struct		S_ParPrt {							// 僷儔儊乕僞報嶞僥乕僽儖
	char	Msg[31];							//  昞帵僨乕僞
	int		cID;								//  僐儞僩儘乕儖俬俢
	int		Pos;								//  昞帵埵抲
};
struct		S_ParPrt ParPrtData[29] = {
			// 012345678901234567890123456789
	#if ATSUGI
	/*00*/	{ "Paramater File搊榐撪梕        " , -1                , 0 },
	/*01*/	{ "尰峴 HOST ID                  " , IDC_EDT_PR01      , 1 },
	/*02*/	{ "尰峴 抂枛 ID                  " , IDC_EDT_PR02      , 1 },
	/*03*/	{ "怴婯 HOST ID                  " , IDC_EDT_PR03      , 1 },
	/*04*/	{ "怴婯 抂枛 ID                  " , IDC_EDT_PR04      , 1 },
	/*05*/	{ "Trigger壛懍搙                 " , IDC_EDT_PR05      , 1 },
	/*06*/	{ "Trigger恔搙                   " , IDC_EDT_PR06      , 1 },
	/*07*/	{ "捠曬桪愭                      " , IDC_EDT_PR07      , 1 },
	/*08*/	{ "揹榖斣崋侾(桪愭)              " , IDC_EDT_PR08      , 1 },
	/*09*/	{ "Retry夞悢                     " , IDC_EDT_PR09      , 1 },
	/*10*/	{ "Retry娫妘(昩)                 " , IDC_EDT_PR10      , 1 },
	/*11*/	{ "敪恑曽幃                      " , IDC_EDT_PR11      , 1 },
	/*12*/	{ "捠曬桪愭恔搙                  " , IDC_EDT_PR12      , 1 },
	/*13*/	{ "捠曬懸婡帪娫                  " , IDC_EDT_PR13      , 1 },
	/*14*/	{ "梊旛                          " , IDC_EDT_PR14      , 1 },
	/*15*/	{ "庴怣帪崗                      " , IDC_STC_DATETIME  , 0 },
	/*16*/	{ "庴怣Paramater File搊榐撪梕    " , -1                , 0 },
	/*17*/	{ "HOST ID                       " , IDC_STC_PR01      , 1 },
	/*18*/	{ "抂枛 ID                       " , IDC_STC_PR02      , 1 },
	/*19*/	{ "Trigger壛懍搙                 " , IDC_STC_PR03      , 1 },
	/*20*/	{ "Trigger恔搙                   " , IDC_STC_PR04      , 1 },
	/*21*/	{ "捠曬桪愭                      " , IDC_STC_PR05      , 1 },
	/*22*/	{ "揹榖斣崋侾(桪愭)              " , IDC_STC_PR06      , 1 },
	/*23*/	{ "Retry夞悢                     " , IDC_STC_PR07      , 1 },
	/*24*/	{ "Retry娫妘(昩)                 " , IDC_STC_PR08      , 1 },
	/*25*/	{ "敪恑曽幃                      " , IDC_STC_PR09      , 1 },
	/*26*/	{ "捠曬桪愭恔搙                  " , IDC_STC_PR10      , 1 },
	/*27*/	{ "捠曬懸婡帪娫                  " , IDC_STC_PR11      , 1 },
	/*28*/	{ "梊旛                          " , IDC_STC_PR12      , 1 }
	#else
	/*00*/	{ "Paramater File搊榐撪梕        " , -1                , 0 },
	/*01*/	{ "尰峴 HOST ID                  " , IDC_EDT_I_01      , 1 },
	/*02*/	{ "尰峴 抂枛 ID                  " , IDC_EDT_I_02      , 1 },
	/*03*/	{ "怴婯 HOST ID                  " , IDC_EDT_I_03      , 1 },
	/*04*/	{ "怴婯 抂枛 ID                  " , IDC_EDT_I_04      , 1 },

	/*05*/	{ "Trigger壛懍搙                 " , IDC_EDT_I_05      , 1 },
	/*06*/	{ "Trigger恔搙                   " , IDC_EDT_I_06      , 1 },
	/*07*/	{ "怴帺嬊俬俹                    " , IDC_EDT_I_07      , 1 },
	/*08*/	{ "怴儂僗僩俬俹                  " , IDC_EDT_I_08      , 1 },
	/*09*/	{ "愙懕姶恔婍悢                  " , IDC_EDT_I_09      , 1 },
	/*10*/	{ "婲摦幉巜掕                    " , IDC_EDT_I_10      , 1 },
	/*11*/	{ "俧俹俽應抧宯                  " , IDC_EDT_I_11      , 1 },
	/*12*/	{ "battery廩1                    " , IDC_EDT_I_12      , 1 },
	/*13*/	{ "battery廩2                    " , IDC_EDT_I_13      , 1 },
	/*14*/	{ "battery廩3                    " , IDC_EDT_I_14      , 1 },
	/*15*/	{ "battery廩4                    " , IDC_EDT_I_15      , 1 },
	/*16*/	{ "battery曻1                    " , IDC_EDT_I_16      , 1 },
	/*17*/	{ "battery曻2                    " , IDC_EDT_I_17      , 1 },
	/*18*/	{ "battery曻3                    " , IDC_EDT_I_18      , 1 },
	/*19*/	{ "battery曻4                    " , IDC_EDT_I_19      , 1 },
	/*20*/	{ "retry夞悢                     " , IDC_EDT_I_20      , 1 },
	/*21*/	{ "retry娫妘                     " , IDC_EDT_I_21      , 1 },
	/*22*/	{ "敪怣曽幃                      " , IDC_EDT_I_22      , 1 },
	/*23*/	{ "                              " , -1                , 0 },
	/*24*/	{ "                              " , -1                , 0 },
	/*25*/	{ "                              " , -1                , 0 },
	/*26*/	{ "                              " , -1                , 0 },
	/*27*/	{ "                              " , -1                , 0 },
	/*28*/	{ "                              " , -1                , 0 }
	#endif
};

/*=====================================
	報嶞偺棳傟

	侾丏Print_req = ?;
		報嶞梫媮No.傪僙僢僩
	俀丏print_task()偑 Print_req 傪娔帇
			pKSGView->PostMessage(WM_PRINT_EXEC, NULL, NULL);
			(FormView偵 儊僢僙乕僕億僗僩)
	俁丏LRESULT CKSGView::OnPrintExec(WPARAM wParam, LPARAM lParam)	(FormView)
			CView::OnFilePrint();  /  CView::OnFilePrintPreview();
			(View偵懳偟報嶞梫媮)
	係丏BOOL CKSGView::OnPreparePrinting(CPrintInfo* pInfo)			(FormView)
			(報嶞弨旛)
	俆丏void CKSGView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)	(FormView)
			BeforePrint(pDC, pInfo);
			(報嶞慜張棟)
	俇丏void CKSGView::OnPrint(CDC* pDC, CPrintInfo* pInfo)			(FormView)
			GridPrintExec(pDC, pInfo);摍
			(報嶞幚峴)
	俈丏void CKSGView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)	(FormView)
			AfterPrint(pDC, pInfo);
			(報嶞屻張棟)
=====================================*/

/*=====================================
						m:10-Dec-1998
@p	<< 昤夋僄儕傾寁嶼 >>
堷悢丗	pDC
栠抣丗	側偟
=====================================*/
void	PrintAreaCalc(CDC* pDC, CPrintInfo* pInfo)
{
	int		left, top, right, bottom;

	left   = pInfo->m_rectDraw.left;
	top    = pInfo->m_rectDraw.top;
	right  = pInfo->m_rectDraw.right;
	bottom = pInfo->m_rectDraw.bottom;

	Print_w = right  - left;
	Print_h = bottom - top;
}

/*=====================================
						m:13-Jan-1999
@p	<< 僼僅儞僩嶌惉 >>
堷悢丗
栠抣丗	側偟
=====================================*/
void	MakeFont(CDC *pDC)
{
	TEXTMETRIC	tm;
	CFont*		bkupFont;
	int			i;

	for (i=0; i<3; i++) {
		mPrtFont[i].CreateFont(Print_FontS[i], 0, 0, 0, FW_NORMAL,FALSE,FALSE,0,
			SHIFTJIS_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
			DEFAULT_PITCH,"俵俽 僑僔僢僋");
	}

	bkupFont = (CFont*)pDC->SelectObject(&mPrtFont[0]);
	mOldFont = (HFONT)bkupFont->GetSafeHandle();
	pDC->GetTextMetrics(&tm);
}

/*=====================================
						m:13-Jan-1999
@p	<< 僼僅儞僩嶍彍 >>
堷悢丗
栠抣丗	側偟
=====================================*/
void	DeleteFont(CDC* pDC)
{
	int i;

	// 僼僅儞僩傪尦偵栠偡
	pDC->SelectObject(CFont::FromHandle(mOldFont));
	// 僼僅儞僩僆僽僕僃僋僩偺嶍彍
	for (i=0; i<3; i++) {
		mPrtFont[i].DeleteObject();
	}
}

/*=====================================
						m:14-Jan-1999
@p	<< 僼僅儞僩僒僀僘僙僢僩 >>
堷悢丗	size_x			墶僒僀僘
		size_y			廲僒僀僘
栠抣丗	側偟
=====================================*/
void	SetFontSize(int size_x, int size_y)
{
	int	s, m, l;

	if (size_x > size_y) {
		m = size_y;
	}
	else {
		m = size_x;
	}
	l = (int)(m * 1.25);
	s = (int)(m * 0.75);
	if ((s%2) == 1) s --;
	if ((m%2) == 1) m --;
	if ((l%2) == 1) l --;
	if (s < 2)      s = 2;
	if (m < 2)      m = 2;
	if (l < 2)      l = 2;
	Print_FontS[FONT_S] = s;
	Print_FontS[FONT_M] = m;
	Print_FontS[FONT_L] = l;
}

/*=====================================
						m:13-Jan-1999
@p	<< 報嶞梡僼僅儞僩僒僀僘庢摼(僌儕僢僪梡) >>
堷悢丗	pInfo
		pGrid			僌儕僢僪億僀儞僞
		cols			Col悢
		rows			Row悢
栠抣丗	側偟
=====================================*/
void	GetGridFontSize(CPrintInfo* pInfo, CMSFlexGrid* pGrid, int cols, int rows)
{
	CString		cbuf;
	int			col, tmpx, tmpy, max, width;
	int			tmp[2], col_w[MAX_COL], col_m[MAX_COL];

	// 僌儕僢僪暆妋擣
	pGrid->SetRow(0);
	width = 0;
	for (col=0; col<cols; col++) {
		pGrid->SetCol(col);
		col_w[col] = pGrid->GetColWidth(col);
		cbuf = pGrid->GetText();
		col_m[col] = strlen(cbuf) + 2;
		width += col_w[col];
	}
	// 斾棪偑嵟彫偺傕偺傪専嶕
	max = col_m[0];
	if (col_m[0] != 0) {
		tmp[0] = col_w[0] / col_m[0];
	}
	else {
		tmp[0] = col_w[0];
	}
	for (col=1; col<cols; col++) {
		if (col_m[col] != 0) {
			tmp[1] = col_w[col] / col_m[col];
			if (tmp[1] < tmp[0]) {
				tmp[0] = tmp[1];
				max = col_m[col];
			}
		}
	}
	// 僼僅儞僩僒僀僘寁嶼
	tmpx = (((Print_w-Print_Ofs.left-Print_Ofs.right) * tmp[0]) / width) * 2;
												// * 2 ->  墶曽岦偼廲曽岦偺 1/2
	tmpy = (Print_h-Print_Ofs.top-Print_Ofs.bottom) / rows;
	SetFontSize(tmpx, tmpy);					// 僼僅儞僩僒僀僘妋掕
}

/*=====================================
						m:14-Dec-1998
@p	<< Daigram梡僼僅儞僩僒僀僘庢摼 >>
	奺僄儕傾偺乭壛懍搙丒丒丒乭偑夋柺偺敿暘偵側傞傛偆偵愝掕(62暥帤)
	偙偺夋柺偼墶僒僀僘偺傒傪寁嶼偟傑偡
堷悢丗	側偟
栠抣丗	側偟
=====================================*/
void	GetDiagramFontSize()
{
	int ww, tmpx;

	if (Print_num == DSP_DIAG) {
		ww = Print_w;
	}
	else {
		ww = Area_w;
	}
	tmpx = ww / 62;
	SetFontSize(tmpx, tmpx);					// 僼僅儞僩僒僀僘妋掕
}

/*=====================================
						m:14-Dec-1998
@p	<< 僷儔儊乕僞梡僼僅儞僩僒僀僘庢摼 >>
	嵟戝??暥帤偑廂傑傞傛偆偵寁嶼偡傞
	偙偺夋柺偼墶僒僀僘偺傒傪寁嶼偟傑偡
堷悢丗	側偟
栠抣丗	側偟
=====================================*/
void	GetParameterFontSize()
{
	int		tmpx, l_off, r_off;

	l_off = (int)(Print_w  * 0.02);
	r_off = (int)(Print_w  * 0.02);

	tmpx = ((Print_w-l_off-r_off) / 82) * 2;
	SetFontSize(tmpx, tmpx);					// 僼僅儞僩僒僀僘妋掕
}

/*=====================================
						m:04-Jan-1999
@p	<< 報嶞慜張棟 >>
堷悢丗	pDC
		pInfo
栠抣丗	側偟
旛峫丗	DMORIENT_LANDSCAPE		報嶞曽岦(墶)
		DMORIENT_PORTRAIT		報嶞曽岦(廲)
=====================================*/
void	BeforePrint(CDC* pDC, CPrintInfo* pInfo)
{
    CWnd*		pWnd;
	LPDEVMODE	pDev;
	int			last, dir;

	pDev = ((CPrintDialog*)pInfo->m_pPD)->GetDevMode();
	switch (Print_num) {
	// ver 1.30
	case DSP_MAP:
		dir = DMORIENT_LANDSCAPE;
		last = 1;
		break;
	
	case DSP_DIAG:								// 攇宍僨乕僞丒僌儔僼昞帵
		dir = DMORIENT_LANDSCAPE;
		last = 1;
		break;
	case DSP_PAR:								// 僷儔儊乕僞愝掕丒嶲徠
		dir = DMORIENT_PORTRAIT;
		last = 1;
		break;
	case DSP_MAG:								// 嵟怴丒恔搙堦棗昞帵
		dir = DMORIENT_LANDSCAPE;
		last = Print_dat[4];
		break;
	case DSP_ENT:								// 娤應揰搊榐堦棗
		dir = DMORIENT_LANDSCAPE;
		last = 1;
		break;
	case DSP_LGI:								// 捠怣寢壥堦棗

⌨️ 快捷键说明

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