コメント |
[[印刷開始]]
戻り値 : true 成功, false 失敗
@DIV
1) BOOL StartPrint( HWND hOwner, LboxString *LDocName );
2) BOOL StartPrint( HWND hOwner, LPTSTR lpDocName, BOOL bDefault );
@END
書式1 では、@C:navy(プリンタ選択ダイアログ)は表示される
書式2 では、bDefault が true の時、デフォルトのプリンタが選択されて、@C:navy(プリンタ選択ダイアログ)は表示されない
@LINE
http://lightbox.on.coocan.jp/image/msdoc.png
[[StartDoc]] http://msdn.microsoft.com/ja-jp/library/cc428765.aspx
[[DOCINFO]] http://msdn.microsoft.com/ja-jp/library/dd183574.aspx
@LINE
@DIV
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;
}
@END
|