ソースメモ

  0 78 152



  
class LboxPrintText  
{
public:
	BOOL ChangePageFont( LPTSTR lpFont, int nPoint );
	BOOL ColPrint( int nCol, int nRow, LPTSTR lpData );
	BOOL NextPage( void  );
	BOOL EndPrint( void  );
	void HandleClear( void );
	BOOL StartPrint( HWND hOwner, LPTSTR lpDocName );
	LboxPrintText();
	virtual ~LboxPrintText();

	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;
};
  

  
LboxPrintText::LboxPrintText()
{
	this->hDC = NULL; 
}

LboxPrintText::~LboxPrintText()
{
	this->HandleClear();
	this->hPageFont = NULL;
	this->hPageFontOld = NULL;
}

void LboxPrintText::HandleClear( void )
{
	if ( this->hDevMode != NULL ) {
		GlobalFree( this->hDevMode );
		this->hDevMode = NULL;
	}
	if ( this->hDevNames != NULL ) {
		GlobalFree( this->hDevNames );
		this->hDevNames = NULL;
	}
	if ( this->hDC != NULL ) {
		DeleteDC( this->hDC );
		this->hDC = NULL;
	}
}

BOOL LboxPrintText::StartPrint( HWND hOwner, LPTSTR lpDocName )
{
	PRINTDLG pd;
 	TEXTMETRIC tm;
	DOCINFO doc;
	BOOL bRet;

	this->hPageFont = NULL;

	ZeroMemory( &pd, sizeof( PRINTDLG ) );
	pd.lStructSize = sizeof( PRINTDLG );
	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->nOrgPageLength
		- 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;
}

BOOL LboxPrintText::EndPrint( void  )
{
	if ( this->hDC == NULL ) {
		return false;
	}

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

	if ( this->hPageFont != NULL ) {
		SelectObject( this->hDC, this->hPageFontOld );
		DeleteObject( this->hPageFont );
	}

	this->HandleClear();

	return true;
}

BOOL LboxPrintText::NextPage( void  )
{
	if ( this->hDC == NULL ) {
		return false;
	}

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

	return true;
}


BOOL LboxPrintText::ColPrint( int nCol, int nRow, LPTSTR lpData )
{
	if ( this->hDC == NULL ) {
		return false;
	}

	TextOut(
		this->hDC,
		nCol * this->nCharWidth,
		nRow * this->nLinePitch,
		lpData,
		lstrlen( lpData )
	);

	return true;
}

BOOL LboxPrintText::ChangePageFont( LPTSTR lpFont, int nPoint )
{
	int nHeight;

    nHeight = -MulDiv(
		nPoint,
		GetDeviceCaps(this->hDC, LOGPIXELSY),
		72
	);
    this->hPageFont = 
		CreateFont(
			nHeight,
			0, 0, 0, 0, 0, 0, 0,
			128,
			0, 0, 0,
			0x0031,
		lpFont);

    this->hPageFontOld
		= (HFONT)SelectObject(
			this->hDC, this->hPageFont
		);
    
    TEXTMETRIC tm;

    GetTextMetrics( this->hDC, &tm );
    this->nCharWidth = tm.tmAveCharWidth;
    this->nLinePitch = tm.tmHeight;
    this->nPageWidth
		= this->nOrgPageLength
		- this->nPageOffsetWidth * 2
		- this->nCharWidth;
    this->nLines = this->nPageLength / this->nLinePitch - 1;
    this->nPageLength = this->nLinePitch * this->nLines;

	return true;

}
  



  



  
INITCOMMONCONTROLSEX


typedef struct tagINITCOMMONCONTROLSEX {
    DWORD dwSize;
    DWORD dwICC;
} INITCOMMONCONTROLSEX, *LPINITCOMMONCONTROLSEX;

Carries information used to load common control classes from the dynamic-link library (DLL). This structure is used with the InitCommonControlsEx function. 

dwSize 
Size of the structure, in bytes. 
dwICC 
Set of bit flags that indicate which common control classes will be loaded from the DLL. This value can be a combination of the following: ICC_ANIMATE_CLASS  Load animate control class.  
ICC_BAR_CLASSES  Load toolbar, status bar, trackbar, and tooltip control classes.  
ICC_COOL_CLASSES  Load rebar control class.  
ICC_DATE_CLASSES  Load date and time picker control class.  
ICC_HOTKEY_CLASS  Load hot key control class.  
ICC_INTERNET_CLASSES  Load IP address class.  
ICC_LISTVIEW_CLASSES  Load list view and header control classes.  
ICC_PAGESCROLLER_CLASS  Load pager control class.  
ICC_PROGRESS_CLASS  Load progress bar control class.  
ICC_TAB_CLASSES  Load tab and tooltip control classes.  
ICC_TREEVIEW_CLASSES  Load tree view and tooltip control classes.  
ICC_UPDOWN_CLASS  Load up-down control class.  
ICC_USEREX_CLASSES  Load ComboBoxEx class.  
ICC_WIN95_CLASSES  Load animate control, header, hot key, list view, progress bar, status bar, tab, tooltip, toolbar, trackbar, tree view, and up-down control classes.  

Version 4.70 

  



  

  
InitCommonControlsEx


BOOL InitCommonControlsEx(
    LPINITCOMMONCONTROLSEX lpInitCtrls
);

Registers specific common control classes from the common control dynamic-link library (DLL). 

Returns TRUE if successful, or FALSE otherwise. 
lpInitCtrls 
Address of an INITCOMMONCONTROLSEX structure that contains information specifying which control classes will be registered. 
Note The effect of each call to InitCommonControlsEx is cumulative. For example, if InitCommonControlsEx is called with theICC_UPDOWN_CLASS flag, then is later called with theICC_HOTKEY_CLASS flag, the result is that both the up-down and hot key common control classes are registered and available to the application. 

Version 4.70 

  



  

  
// *********************************************************
// メインウインドウ作成イベント
// *********************************************************
void MyClass::WMCreate()
{

	INITCOMMONCONTROLSEX IC;

	IC.dwSize = sizeof( INITCOMMONCONTROLSEX );
	IC.dwICC = ICC_DATE_CLASSES;

	InitCommonControlsEx( &IC );

	Dlg.Open( this, IDD_DIALOG1 );
	this->ReturnValue = -1;
}
  










  infoboard   管理者用   
このエントリーをはてなブックマークに追加





フリーフォントWEBサービス
SQLの窓WEBサービス

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ