📄 cprintpreview.cpp
字号:
nCharChars = CMemory::MemCharNext( pLine, nLineLen, &pLine[i] ) - &pLine[i];
if( 0 == nCharChars ){ // 0バイト文字?
nCharChars = 1;
}
if( nCharChars == 1 ){ // 1バイト文字
if( MODE_SINGLEBYTE == nPreviousChars ){
// 引き続き1バイト文字。
if( TAB == pLine[i] ){ // タブ文字
if( 0 < i - nBgn ){
// タブ文字の前までを描画。
::ExtTextOut(
hdc,
x + nPosX * m_pPrintSetting->m_nPrintFontWidth,
y - ( m_pPrintSetting->m_nPrintFontHeight - nAscentHan ),
0,
NULL,
&pLine[nBgn], i - nBgn,
m_pnDx
);
nPosX += ( i - nBgn ); // 実際の文字数と、バイト数の差を埋める。
}
nPosX += ( nTabSpace - nPosX % nTabSpace );
nBgn = i + 1; // スキャン中の次のバイト
}
}else{
/* 2バイト文字から、1バイト文字に切り替わったとき
2バイト文字の塊を描画。
*/
if( 0 < i - nBgn ){
::SelectObject( hdc, hFontZen );
::ExtTextOut(
hdc,
x + nPosX * m_pPrintSetting->m_nPrintFontWidth,
y - ( m_pPrintSetting->m_nPrintFontHeight - nAscentZen ),
0,
NULL,
&pLine[nBgn], i - nBgn,
m_pnDx
);
::SelectObject( hdc, hFontHan );
nPosX += ( i - nBgn );
}
nBgn = i;
nPreviousChars = MODE_SINGLEBYTE;
if( TAB == pLine[i] ){ // タブ文字
nPosX += ( nTabSpace - nPosX % nTabSpace );
nBgn = i + 1;
}
}
}else{ // 1バイト文字
if( MODE_SINGLEBYTE == nPreviousChars ){
if( 0 < i - nBgn ){
::ExtTextOut(
hdc,
x + nPosX * m_pPrintSetting->m_nPrintFontWidth,
y - ( m_pPrintSetting->m_nPrintFontHeight - nAscentHan ),
0,
NULL,
&pLine[nBgn], i - nBgn,
m_pnDx
);
nPosX += ( i - nBgn );
}
nBgn = i;
nPreviousChars = MODE_DOUBLEBYTE;
}
++i;
}
}
if( 0 < i - nBgn ){
if( MODE_DOUBLEBYTE == nPreviousChars ){ /* 2バイト文字描画 */
::SelectObject( hdc, hFontZen );
::ExtTextOut(
hdc,
x + nPosX * m_pPrintSetting->m_nPrintFontWidth,
y - ( m_pPrintSetting->m_nPrintFontHeight - nAscentZen ),
0,
NULL,
&pLine[nBgn], i - nBgn,
m_pnDx
);
::SelectObject( hdc, hFontHan );
}else{ /* 1バイト文字描画。フォントは標準で1バイト文字用。 */
::ExtTextOut(
hdc,
x + nPosX * m_pPrintSetting->m_nPrintFontWidth,
y - ( m_pPrintSetting->m_nPrintFontHeight - nAscentHan ),
0,
NULL,
&pLine[nBgn], i - nBgn,
m_pnDx
);
}
}
return;
}
/* 印刷プレビューフォント(半角)を設定する
typedef struct tagLOGFONT {
LONG lfHeight;
LONG lfWidth;
LONG lfEscapement;
LONG lfOrientation;
LONG lfWeight;
BYTE lfItalic;
BYTE lfUnderline;
BYTE lfStrikeOut;
BYTE lfCharSet;
BYTE lfOutPrecision;
BYTE lfClipPrecision;
BYTE lfQuality;
BYTE lfPitchAndFamily;
TCHAR lfFaceName[LF_FACESIZE];
} LOGFONT;
*/
void CPrintPreview::SetPreviewFontHan( LOGFONT* lf )
{
m_lfPreviewHan = *lf;
// PrintSettingからコピー
m_lfPreviewHan.lfHeight = m_pPrintSetting->m_nPrintFontHeight;
m_lfPreviewHan.lfWidth = m_pPrintSetting->m_nPrintFontWidth;
strcpy(m_lfPreviewHan.lfFaceName, m_pPrintSetting->m_szPrintFontFaceHan);
}
void CPrintPreview::SetPreviewFontZen( LOGFONT* lf )
{
m_lfPreviewZen = *lf;
// PrintSettingからコピー
m_lfPreviewZen.lfHeight = m_pPrintSetting->m_nPrintFontHeight;
m_lfPreviewZen.lfWidth = m_pPrintSetting->m_nPrintFontWidth;
strcpy(m_lfPreviewZen.lfFaceName, m_pPrintSetting->m_szPrintFontFaceZen );
}
int CALLBACK CPrintPreview::MyEnumFontFamProc(
ENUMLOGFONT* pelf, // pointer to logical-font data
NEWTEXTMETRIC* pntm, // pointer to physical-font data
int nFontType, // type of font
LPARAM lParam // address of application-defined data
)
{
CPrintPreview* pCPrintPreview = (CPrintPreview*)lParam;
if( 0 == strcmp( pelf->elfLogFont.lfFaceName, pCPrintPreview->m_pPrintSetting->m_szPrintFontFaceHan ) ){
pCPrintPreview->SetPreviewFontHan(&pelf->elfLogFont);
}
if( 0 == strcmp( pelf->elfLogFont.lfFaceName, pCPrintPreview->m_pPrintSetting->m_szPrintFontFaceZen ) ){
pCPrintPreview->SetPreviewFontZen(&pelf->elfLogFont);
}
return 1;
}
/*!
印刷プレビューに必要なコントロールを作成する
*/
void CPrintPreview::CreatePrintPreviewControls( void )
{
int nCxHScroll = ::GetSystemMetrics( SM_CXHSCROLL );
int nCyHScroll = ::GetSystemMetrics( SM_CYHSCROLL );
int nCxVScroll = ::GetSystemMetrics( SM_CXVSCROLL );
int nCyVScroll = ::GetSystemMetrics( SM_CYVSCROLL );
/* 印刷プレビュー 操作バー */
m_hwndPrintPreviewBar = ::CreateDialogParam(
m_pParentWnd->m_hInstance, // handle to application instance
MAKEINTRESOURCE( IDD_PRINTPREVIEWBAR ), // identifies dialog box template name
m_pParentWnd->m_hWnd, // handle to owner window
(DLGPROC)CPrintPreview::PrintPreviewBar_DlgProc, // pointer to dialog box procedure
(LPARAM)this
);
/* 縦スクロールバーの作成 */
m_hwndVScrollBar = ::CreateWindowEx(
0L, /* no extended styles */
"SCROLLBAR", /* scroll bar control class */
(LPSTR) NULL, /* text for window title bar */
WS_VISIBLE | WS_CHILD | SBS_VERT, /* scroll bar styles */
0, /* horizontal position */
0, /* vertical position */
200, /* width of the scroll bar */
CW_USEDEFAULT, /* default height */
m_pParentWnd->m_hWnd, /* handle of main window */
(HMENU) NULL, /* no menu for a scroll bar */
m_pParentWnd->m_hInstance, /* instance owning this window */
(LPVOID) NULL /* pointer not needed */
);
SCROLLINFO si;
si.cbSize = sizeof( si );
si.fMask = SIF_ALL | SIF_DISABLENOSCROLL;
si.nMin = 0;
si.nMax = 29;
si.nPage = 10;
si.nPos = 0;
si.nTrackPos = 1;
::SetScrollInfo( m_hwndVScrollBar, SB_CTL, &si, TRUE );
::ShowScrollBar( m_hwndVScrollBar, SB_CTL, TRUE );
/* 横スクロールバーの作成 */
m_hwndHScrollBar = ::CreateWindowEx(
0L, /* no extended styles */
"SCROLLBAR", /* scroll bar control class */
(LPSTR) NULL, /* text for window title bar */
WS_VISIBLE | WS_CHILD | SBS_HORZ, /* scroll bar styles */
0, /* horizontal position */
0, /* vertical position */
200, /* width of the scroll bar */
CW_USEDEFAULT, /* default height */
m_pParentWnd->m_hWnd, /* handle of main window */
(HMENU) NULL, /* no menu for a scroll bar */
m_pParentWnd->m_hInstance, /* instance owning this window */
(LPVOID) NULL /* pointer not needed */
);
si.cbSize = sizeof( si );
si.fMask = SIF_ALL | SIF_DISABLENOSCROLL;
si.nMin = 0;
si.nMax = 29;
si.nPage = 10;
si.nPos = 0;
si.nTrackPos = 1;
::SetScrollInfo( m_hwndHScrollBar, SB_CTL, &si, TRUE );
::ShowScrollBar( m_hwndHScrollBar, SB_CTL, TRUE );
/* サイズボックスの作成 */
m_hwndSizeBox = ::CreateWindowEx(
WS_EX_CONTROLPARENT/*0L*/, /* no extended styles */
"SCROLLBAR", /* scroll bar control class */
(LPSTR) NULL, /* text for window title bar */
WS_VISIBLE | WS_CHILD | SBS_SIZEBOX | SBS_SIZEGRIP, /* scroll bar styles */
0, /* horizontal position */
0, /* vertical position */
200, /* width of the scroll bar */
CW_USEDEFAULT, /* default height */
m_pParentWnd->m_hWnd, /* handle of main window */
(HMENU) NULL, /* no menu for a scroll bar */
m_pParentWnd->m_hInstance, /* instance owning this window */
(LPVOID) NULL /* pointer not needed */
);
::ShowWindow( m_hwndPrintPreviewBar, SW_SHOW );
/* WM_SIZE 処理 */
RECT rc1;
::GetClientRect( m_pParentWnd->m_hWnd, &rc1 );
OnSize( SIZE_RESTORED, MAKELONG( rc1.right - rc1.left, rc1.bottom - rc1.top ) );
return;
}
/*!
印刷プレビューに必要だったコントロールを破棄する
*/
void CPrintPreview::DestroyPrintPreviewControls( void )
{
/* 印刷プレビュー 操作バー 削除 */
if ( m_hwndPrintPreviewBar ){
::DestroyWindow( m_hwndPrintPreviewBar );
m_hwndPrintPreviewBar = NULL;
}
/* 印刷プレビュー 垂直スクロールバーウィンドウ 削除 */
if( m_hwndVScrollBar ){
::DestroyWindow( m_hwndVScrollBar );
m_hwndVScrollBar = NULL;
}
/* 印刷プレビュー 水平スクロールバーウィンドウ 削除 */
if( m_hwndHScrollBar ){
::DestroyWindow( m_hwndHScrollBar );
m_hwndHScrollBar = NULL;
}
/* 印刷プレビュー サイズボックスウィンドウ 削除 */
if ( m_hwndSizeBox ){
::DestroyWindow( m_hwndSizeBox );
m_hwndSizeBox = NULL;
}
}
/* ダイアログプロシージャ */
INT_PTR CALLBACK CPrintPreview::PrintPreviewBar_DlgProc(
HWND hwndDlg, // handle to dialog box
UINT uMsg, // message
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
CPrintPreview* pCPrintPreview;
switch( uMsg ){
case WM_INITDIALOG:
// Modified by KEITA for WIN64 2003.9.6
::SetWindowLongPtr( hwndDlg, DWLP_USER, lParam );
return TRUE;
default:
// Modified by KEITA for WIN64 2003.9.6
pCPrintPreview = ( CPrintPreview* )::GetWindowLongPtr( hwndDlg, DWLP_USER );
if( NULL != pCPrintPreview ){
return pCPrintPreview->DispatchEvent_PPB( hwndDlg, uMsg, wParam, lParam );
}else{
return FALSE;
}
}
}
/* 印刷プレビュー 操作バーにフォーカスを当てる */
void CPrintPreview::SetFocusToPrintPreviewBar( void )
{
if( NULL != m_hwndPrintPreviewBar ){
::SetFocus( m_hwndPrintPreviewBar );
}
}
/* 印刷プレビュー 操作バー ダイアログのメッセージ処理 */
INT_PTR CPrintPreview::DispatchEvent_PPB(
HWND hwndDlg, // handle to dialog box
UINT uMsg, // message
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
WORD wNotifyCode;
WORD wID;
HWND hwndCtl;
CMemory cMemBuf;
char szHelpFile[_MAX_PATH];
switch( uMsg ){
case WM_INITDIALOG:
// Modified by KEITA for WIN64 2003.9.6
::SetWindowLongPtr( hwndDlg, DWLP_USER, lParam );
return TRUE;
case WM_COMMAND:
wNotifyCode = HIWORD(wParam); /* 通知コード */
wID = LOWORD(wParam); /* 項目ID、コントロールID またはアクセラレータID */
hwndCtl = (HWND) lParam; /* コントロールのハンドル */
switch( wNotifyCode ){
/* ボタン/チェックボックスがクリックされた */
case BN_CLICKED:
switch( wID ){
case IDC_BUTTON_PRINTERSELECT:
// From Here 2003.05.03 かろと
// PRINTDLGを初期化
PRINTDLG pd;
memset( &pd, 0, sizeof(PRINTDLG) );
pd.Flags = PD_PRINTSETUP | PD_NONETWORKBUTTON;
pd.hwndOwner = m_pParentWnd->m_hWnd;
if (TRUE == m_cPrint.PrintDlg( &pd, &m_pPrintSetting->m_mdmDevMode )) {
// 用紙サイズと用紙方向を反映させる 2003.05.03 かろと
m_pPrintSetting->m_nPrintPaperSize = m_pPrintSetting->m_mdmDevMode.dmPaperSize;
m_pPrintSetting->m_nPrintPaperOrientation = m_pPrintSetting->m_mdmDevMode.dmOrientation;
/* 印刷プレビュー スクロールバー初期化 */
InitPreviewScrollBar();
OnChangePrintSetting();
::InvalidateRect( m_pParentWnd->m_hWnd, NULL, TRUE );
}
// To Here 2003.05.03 かろと
break;
case IDC_BUTTON_PRINTSETTING:
m_pParentWnd->OnPrintPageSetting();
break;
case IDC_BUTTON_ZOOMUP:
/* プレビュー拡大縮小 */
OnPreviewZoom( TRUE );
break;
case IDC_BUTTON_ZOOMDOWN:
/* プレビュー拡大縮小 */
OnPreviewZoom( FALSE );
break;
case IDC_BUTTON_PREVPAGE:
/* 前ページ */
OnPreviewGoPreviousPage( );
break;
case IDC_BUTTON_NEXTPAGE:
/* 次ページ */
OnPreviewGoNextPage( );
break;
case IDC_BUTTON_HELP:
/* ヘルプファイルのフルパスを返す */
::GetHelpFilePath( szHelpFile );
/* 印刷プレビューのヘルプ */
//Stonee, 2001/03/12 第四引数を、機能番号からヘルプトピック番号を調べるようにした
::WinHelp( hwndDlg, szHelpFile, HELP_CONTEXT, ::FuncID_To_HelpContextID(F_PRINT_PREVIEW) );
break;
case IDOK:
/* 印刷実行 */
OnPrint();
return TRUE;
case IDCANCEL:
/* 印刷プレビューモードのオン/オフ */
m_pParentWnd->PrintPreviewModeONOFF();
return TRUE;
}
break; /* BN_CLICKED */
}
break; /* WM_COMMAND */
}
return FALSE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -