www.pudn.com > showstr.rar > PrintWnd1.cpp


// PrintWnd1.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "printWnd.h" 
#include "PrintWnd1.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CPrintWnd 
 
CPrintWnd::CPrintWnd() 
{ 
	LOGFONT lf; 
	memset(&lf, 0, sizeof(LOGFONT));       // zero out structure 
	lf.lfHeight = 24;                      // request a 12-pixel-height font 
	lf.lfCharSet = GB2312_CHARSET; 
	lf.lfQuality = ANTIALIASED_QUALITY; 
	lf.lfWeight = 300; 
	strcpy(lf.lfFaceName, "ºÚÌå");        // request a face name "Arial" 
	VERIFY(m_font.CreateFontIndirect(&lf));  // create the font 
	m_count = 0; 
} 
 
CPrintWnd::~CPrintWnd() 
{ 
} 
 
 
BEGIN_MESSAGE_MAP(CPrintWnd, CWnd) 
	//{{AFX_MSG_MAP(CPrintWnd) 
	ON_WM_NCHITTEST() 
	ON_WM_PAINT() 
	ON_WM_TIMER() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
 
///////////////////////////////////////////////////////////////////////////// 
// CPrintWnd message handlers 
BOOL CPrintWnd::CreateWndEx(CWnd *pParent) 
{ 
	const char *strMyClass; 
	try 
	{ 
		strMyClass = AfxRegisterWndClass( 
			CS_VREDRAW | CS_HREDRAW, 
			::LoadCursor(NULL, IDC_ARROW), 
			(HBRUSH) ::GetStockObject(WHITE_BRUSH), 
			::LoadIcon(NULL, IDI_APPLICATION)); 
	} 
	catch (CResourceException* pEx) 
	{ 
		AfxMessageBox( 
			_T("Couldn't register class! (Already registered?)")); 
		pEx->Delete(); 
	} 
	BOOL ret = CWnd::CreateEx(WS_EX_TOOLWINDOW, // Make a client edge label. 
		strMyClass, "Hi", 
		WS_POPUP | WS_VISIBLE, 
		0, 0, 0, 0, pParent->m_hWnd, NULL);	 
	SetFont(&m_font); 
	return ret; 
	 
} 
 
UINT CPrintWnd::OnNcHitTest(CPoint point)  
{ 
 
	return HTCAPTION   ; 
	return CWnd::OnNcHitTest(point); 
} 
 
void CPrintWnd::OnPaint()  
{ 
	CPaintDC dc(this); // device context for painting 
	dc.SelectObject(&m_font); 
	CRect rect; 
	GetClientRect(rect); 
	static CBitmap bmp; 
	static BITMAP bm; 
	if(!bmp.GetSafeHandle()) 
		bmp.LoadBitmap(IDB_MAINBAK); 
	CDC memdc; 
	memdc.CreateCompatibleDC(&dc); 
	memdc.SelectObject(&bmp); 
	bmp.GetBitmap(&bm); 
 
	::SetStretchBltMode(dc,HALFTONE); 
	 
	::StretchBlt(dc,0,0,rect.Width(),rect.Height(),memdc.m_hDC,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY); 
	dc.SetBkMode(15); 
	DrawStr(&dc,rect,m_str); 
} 
 
void CPrintWnd::ShowString(char *_str) 
{ 
	CRect rect; 
	GetParent()->GetWindowRect(rect); 
	GetDrawRect(this,_str,rect); 
	m_str = _str; 
	MoveWindow(rect); 
	ShowWindow(SW_SHOW); 
	Invalidate(); 
	KillTimer(111); 
	SetTimer(111,1000,NULL); 
	m_count = 2; 
} 
void CPrintWnd::DrawStr(CDC *pDC, const CRect &_rect, CString &_str,UINT style) 
{  
	CRect rDraw(_rect); 
	pDC->DrawText(_str,rDraw,DT_CALCRECT|style); 
	if(rDraw.Height() < _rect.Height()) 
	{ 
		int off = 0; 
		if(_str.GetLength()) 
		{ 
			CSize size = pDC->GetTextExtent(_str); 
			size.cx/= _str.GetLength(); 
			off = size.cx; 
		} 
		 
		int w = rDraw.Width(); 
		int h = rDraw.Height(); 
		CPoint pt = _rect.CenterPoint(); 
		rDraw.SetRect(pt,pt); 
		rDraw.InflateRect(w/2 - off,h/2); 
		 
		if((style << sizeof(UINT) * 8 - 1) == 0 )//DT_LEFT 
		{ 
			rDraw.OffsetRect( _rect.left - rDraw.left + off,0); 
		} 
	} 
	pDC->DrawText(_str,rDraw,style); 
	 
} 
void CPrintWnd::GetDrawRect(CWnd *pWnd,CString str, CRect &rect,UINT style) 
{ 
	ASSERT(pWnd); 
	CDC *pDC = pWnd->GetDC(); 
	pDC->SelectObject(&m_font); 
	pDC->DrawText(str,rect,DT_CALCRECT|style);	 
	pWnd->ReleaseDC(pDC); 
} 
 
void CPrintWnd::OnTimer(UINT nIDEvent)  
{ 
	// TODO: Add your message handler code here and/or call default 
	m_count -- ; 
	if(m_count <= 0) 
	{ 
		ShowWindow(SW_HIDE); 
		KillTimer(111); 
		m_count = 0; 
	} 
	if(!IsWindowVisible()) 
		m_count = 0; 
	 
	CWnd::OnTimer(nIDEvent); 
}