ソース掲示板




すべてから検索

キーワード   条件 表示 現行ログ 過去ログ トピックス 名前 本文
StartPrint ( No.1 )
日時: 2009/02/21 19:56
名前: lightbox



印刷開始

戻り値 : true 成功, false 失敗

拡張子:
1) BOOL StartPrint( HWND hOwner, LboxString *LDocName );
2) BOOL StartPrint( HWND hOwner, LPTSTR lpDocName, BOOL bDefault );
書式1 では、プリンタ選択ダイアログは表示される 書式2 では、bDefault が true の時、デフォルトのプリンタが選択されて、プリンタ選択ダイアログは表示されない
StartDoc http://msdn.microsoft.com/ja-jp/library/cc428765.aspx DOCINFO http://msdn.microsoft.com/ja-jp/library/dd183574.aspx
拡張子:
BOOL LboxPrint::StartPrint( HWND hOwner, LPTSTR lpDocName, BOOL bDefault )
{
	PRINTDLG pd;
 	TEXTMETRIC tm;
	DOCINFO doc;
	BOOL bRet;

	this->HandleClear();

	ZeroMemory( &pd, sizeof( PRINTDLG ) );
	pd.lStructSize = sizeof( PRINTDLG );
	if ( bDefault ) {
		pd.Flags = PD_RETURNDC | PD_RETURNDEFAULT;
	}
	else {
		pd.Flags = PD_RETURNDC;
	}
	pd.hwndOwner = hOwner;

	bRet = PrintDlg( &pd );
	if ( !bRet ) {
		return false;
	}

	this->hDC = pd.hDC;
    this->hDevMode = pd.hDevMode;
    this->hDevNames = pd.hDevNames;

	// 物理幅
    this->nOrgPageWidth
		= GetDeviceCaps(pd.hDC, PHYSICALWIDTH);
	// 物理高さ
    this->nOrgPageLength
		= GetDeviceCaps(pd.hDC, PHYSICALHEIGHT);
	// 印字可能領域までの位置
    this->nPageOffsetWidth
		= GetDeviceCaps(pd.hDC, PHYSICALOFFSETX);
    this->nPageOffset
		= GetDeviceCaps(pd.hDC, PHYSICALOFFSETY);
	// 印字可能ページ長
    this->nPageLength 
		= this->nOrgPageLength
		- this->nPageOffsetWidth * 2;

    GetTextMetrics(pd.hDC, &tm);
	// 平均文字幅
    this->nCharWidth = tm.tmAveCharWidth;
	// 文字高さ
    this->nLinePitch = tm.tmHeight;
	// 印字可能幅
    this->nPageWidth
		= this->nOrgPageWidth
		- this->nPageOffsetWidth * 2
		- this->nCharWidth;

	// ページあたりの行数
    this->nLines = this->nPageLength / this->nLinePitch - 1;
	// 実際のページ長
    this->nPageLength = this->nLinePitch * this->nLines;

	ZeroMemory( &doc, sizeof( &doc ) );
	doc.cbSize = sizeof( &doc );
	doc.lpszDocName = lpDocName;
	doc.lpszOutput = NULL;
	doc.lpszDatatype = NULL;

	int nRet;

	nRet = StartDoc( pd.hDC, &doc );
	if ( nRet <= 0 ) {
		this->HandleClear();
		return false;
	}

	nRet = StartPage( pd.hDC );
	if ( nRet <= 0 ) {
		this->HandleClear();
		return false;
	}

	return true;
}