ソース掲示板




すべてから検索

キーワード   条件 表示 現行ログ 過去ログ トピックス 名前 本文
印刷オブジェクト
日時: 2007/05/26 13:01
名前: lightbox



プリンタへ印刷する為のクラスです。
lightbox.lib に実装されていますが、何故か標準クラスに記述するのを忘れていました。

拡張子:
// *********************************************************
// コンストラクタ
// *********************************************************
LboxPrint::LboxPrint()
{
	this->hDC = NULL; 
	this->hDevMode = NULL;
	this->hDevNames = NULL;
	this->hPageFont = NULL;
}

// *********************************************************
// デストラクタ
// *********************************************************
LboxPrint::~LboxPrint()
{
	this->HandleClear();
}
拡張子:
class LboxPrint  
{
public:
	BOOL EnumPrinter( LboxListview *Lview );
	BOOL ColPrintBox(
		int nCol, int nRow, int nCol2, int nRow2, UINT nFormat, LboxString *LData );
	BOOL ColPrintBox(
		int nCol, int nRow, int nCol2, int nRow2, UINT nFormat, LPTSTR lpData );
	BOOL ColPaintBox(
		int nCol, int nRow, int nCol2, int nRow2, int r, int g, int b );
	BOOL ColPaintBox( int nCol, int nRow, int nCol2, int r, int g, int b );
	BOOL ColBox( int nCol, int nRow, int nCol2, int nRow2 );
	BOOL ColBox( int nCol, int nRow, int nCol2 );
	BOOL ColFontPrint(
		LboxString *LFont, int nPoint, int nCol, int nRow, LboxString *LData );
	BOOL ColFontPrint(
		LPTSTR lpFont, int nPoint, int nCol, int nRow, LPTSTR lpData );
	BOOL ChangePageFont( LboxString *LFont, int nPoint );
	BOOL ChangePageFont( LPTSTR lpFont, int nPoint );
	BOOL ColPrint( int nCol, int nRow, LboxString *LData );
	BOOL ColPrint( int nCol, int nRow, LPTSTR lpData );
	BOOL NextPage( void  );
	BOOL EndPrint( void  );
	void HandleClear( void );
	BOOL StartPrint( HWND hOwner, LboxString *LDocName );
	BOOL StartPrint( HWND hOwner, LPTSTR lpDocName, BOOL bDefault );
	LboxPrint();
	virtual ~LboxPrint();

	LONG nOrgPageWidth;
	LONG nOrgPageLength;
	LONG nPageWidth;
	LONG nPageLength;
	LONG nPageOffsetWidth;
	LONG nPageOffset;
	LONG nCharWidth;
	LONG nLinePitch;
	LONG nLines;
	HANDLE hDevMode;
	HANDLE hDevNames;
	HDC hDC;
	HFONT hPageFont;
	HFONT hPageFontOld;
	HFONT hPageFontOrg;

	LboxString ErrMessage;
};
メンテナンス

StartPrint ( No.1 )
日時: 2009/02/21 19:56
名前: lightbox


日時: 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;
}
このアーティクルの参照用URLをクリップボードにコピー メンテナンス
NextPage ( No.2 )
日時: 2009/02/21 19:57
名前: lightbox
改ページ

戻り値 : true 成功, false 失敗

拡張子:
BOOL NextPage( void  );
現在のページを終了して、新しいページを作成する
拡張子:
// *********************************************************
// 改ページ
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxPrint::NextPage( void  )
{
	if ( this->hDC == NULL ) {
		return false;
	}

	EndPage( this->hDC );
	StartPage( this->hDC );

	return true;
}

http://msdn.microsoft.com/ja-jp/library/cc428489.aspx http://msdn.microsoft.com/ja-jp/library/cc428765.aspx
このアーティクルの参照用URLをクリップボードにコピー メンテナンス
EndPrint ( No.3 )
日時: 2007/05/26 11:57
名前: lightbox
印刷終了

戻り値 : true 成功, false 失敗

拡張子:
BOOL EndPrint( void  );
拡張子:
// *********************************************************
// 印刷終了
// 戻り値 : true 成功, false 失敗
// *********************************************************
BOOL LboxPrint::EndPrint( void  )
{
	if ( this->hDC == NULL ) {
		return false;
	}

	EndPage( this->hDC );
	EndDoc( this->hDC );

	this->HandleClear();

	return true;
}
拡張子:
// *********************************************************
// 取得ハンドルクリア
// 戻り値 : 無し
// *********************************************************
void LboxPrint::HandleClear( void )
{
	if ( this->hDevMode != NULL ) {
		GlobalFree( this->hDevMode );
		this->hDevMode = NULL;
	}
	if ( this->hDevNames != NULL ) {
		GlobalFree( this->hDevNames );
		this->hDevNames = NULL;
	}
	if ( this->hPageFont != NULL ) {
		SelectObject( this->hDC, this->hPageFontOrg );
		DeleteObject( this->hPageFont );
		this->hPageFont = NULL;
		this->hPageFontOrg = NULL;
	}
	if ( this->hDC != NULL ) {
		DeleteDC( this->hDC );
		this->hDC = NULL;
	}
}
このアーティクルの参照用URLをクリップボードにコピー メンテナンス
ChangePageFont ( No.4 )
日時: 2007/05/26 12:00
名前: lightbox
ページフォント変更

戻り値 : true 成功, false 失敗

拡張子:
BOOL ChangePageFont( LboxString *LFont, int nPoint );
BOOL ChangePageFont( LPTSTR lpFont, int nPoint );
このアーティクルの参照用URLをクリップボードにコピー メンテナンス
ColPrint ( No.5 )
日時: 2007/05/26 12:04
名前: lightbox
文字列の指定位置印刷

戻り値 : true 成功, false 失敗

拡張子:
BOOL ColPrint( int nCol, int nRow, LboxString *LData );
BOOL ColPrint( int nCol, int nRow, LPTSTR lpData );
このアーティクルの参照用URLをクリップボードにコピー メンテナンス
ColFontPrint ( No.6 )
日時: 2007/05/26 12:08
名前: lightbox
フォントの種類とサイズを指定して、文字列を指定位置に印刷

戻り値 : true 成功, false 失敗

拡張子:
BOOL ColFontPrint( LboxString *LFont, int nPoint, int nCol, int nRow, LboxString *LData );
BOOL ColFontPrint( LPTSTR lpFont, int nPoint, int nCol, int nRow, LPTSTR lpData );
このアーティクルの参照用URLをクリップボードにコピー メンテナンス
ColPrintBox ( No.7 )
日時: 2009/02/21 19:58
名前: lightbox
API 関数の DrawText のフォーマット指定を使用して指定領域に文字列を印刷する

戻り値 : true 成功, false 失敗

拡張子:
BOOL ColPrintBox( int nCol, int nRow, int nCol2, int nRow2, UINT nFormat, LboxString *LData );
BOOL ColPrintBox( int nCol, int nRow, int nCol2, int nRow2, UINT nFormat, LPTSTR lpData );

http://msdn.microsoft.com/ja-jp/library/cc428474.aspx
このアーティクルの参照用URLをクリップボードにコピー メンテナンス
ColBox ( No.8 )
日時: 2007/05/26 12:45
名前: lightbox
指定位置にBOX罫線を印刷する

戻り値 : true 成功, false 失敗

拡張子:
BOOL ColBox( int nCol, int nRow, int nCol2 );
BOOL ColBox( int nCol, int nRow, int nCol2, int nRow2 );
このアーティクルの参照用URLをクリップボードにコピー メンテナンス
ColPaintBox ( No.9 )
日時: 2007/05/26 12:40
名前: lightbox
指定範囲を指定色で塗りつぶす

戻り値 : true 成功, false 失敗

拡張子:
BOOL ColPaintBox( int nCol, int nRow, int nCol2, int nRow2, int r, int g, int b );
BOOL ColPaintBox( int nCol, int nRow, int nCol2, int r, int g, int b );
このアーティクルの参照用URLをクリップボードにコピー メンテナンス