www.pudn.com > like_MSN_Messenger.rar > ImageTabWnd.cpp


// ImageTabWnd.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "Messenger.h" 
#include "ImageTabWnd.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CImageTabWnd 
 
CImageTabWnd::CImageTabWnd() 
{ 
	m_pBitmapTab = NULL; 
	m_pRectTab = NULL; 
	m_nTabCount = 0; 
	m_nCurrentIndex = 0; 
 
	for(int i=0; i0) 
	//	ptAd = CPoint((rcClient.Width()-m_szBitmapAd.cx)/2, rcClient.Height()-(m_szBitmapBottom.cy+m_szBitmapAd.cy)/2+1); 
	//else 
	//	ptAd = CPoint(0, rcClient.Height()-(m_szBitmapBottom.cy+m_szBitmapAd.cy)/2+1); 
	//DrawPosImage(&m_BitmapAd, &m_MemDC, ptAd); 
	 
	//»­µ½ÏÔʾÆ÷ÉÏ 
	dc.BitBlt(rcClient.left, rcClient.top, rcClient.Width(), rcClient.Height(), &m_MemDC, 0, 0, SRCCOPY); 
 
	m_MemDC.DeleteDC(); 
 
	// Do not call CWnd::OnPaint() for painting messages 
} 
 
void CImageTabWnd::SetTabCount(int nCount) 
{ 
	m_nTabCount = nCount; 
 
	if (m_pBitmapTab) 
		delete []m_pRectTab; 
	m_pBitmapTab = new CBitmap[m_nTabCount]; 
 
	if (m_pRectTab) 
		delete []m_pRectTab; 
	m_pRectTab = new CRect[m_nTabCount]; 
 
} 
 
void CImageTabWnd::SetTabImage(int nIndex, CString strName) 
{ 
	ASSERT(nIndex < m_nTabCount); 
	HBITMAP hBitmap = NULL; 
	hBitmap = (HBITMAP)::LoadImage(NULL, strName, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE|LR_LOADFROMFILE); 
	ASSERT(hBitmap); 
	 
	if (m_pBitmapTab[nIndex].m_hObject) 
		m_pBitmapTab[nIndex].Detach(); 
 
	m_pBitmapTab[nIndex].Attach(hBitmap); 
} 
 
void CImageTabWnd::SetTabImage(int nIndex, UINT nID) 
{ 
	ASSERT(nIndex < m_nTabCount); 
 
	if (m_pBitmapTab[nIndex].m_hObject) 
		m_pBitmapTab[nIndex].Detach(); 
 
	m_pBitmapTab[nIndex].LoadBitmap(nID); 
} 
 
void CImageTabWnd::SetTabRect(int nIndex, CRect rc) 
{ 
	ASSERT(nIndex < m_nTabCount); 
	m_pRectTab[nIndex] = rc; 
} 
 
void CImageTabWnd::SetImage(CBitmap &bitmap, CString strName) 
{ 
	HBITMAP hBitmap = NULL; 
	hBitmap = (HBITMAP)::LoadImage(NULL, strName, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE|LR_LOADFROMFILE); 
	ASSERT(hBitmap); 
 
	if (bitmap.m_hObject) 
		bitmap.Detach(); 
 
	bitmap.Attach(hBitmap); 
} 
 
void CImageTabWnd::SetImage(CBitmap &bitmap, UINT nID) 
{ 
	if (bitmap.m_hObject) 
		bitmap.Detach(); 
 
	bitmap.LoadBitmap(nID); 
} 
 
void CImageTabWnd::SetTopImage(CString strName) 
{ 
	SetImage(m_BitmapTop, strName); 
	SetImageSize(&m_BitmapTop, m_szBitmapTop); 
} 
 
void CImageTabWnd::SetTopImage(UINT nID) 
{ 
	SetImage(m_BitmapTop, nID); 
	SetImageSize(&m_BitmapTop, m_szBitmapTop); 
} 
 
void CImageTabWnd::SetBottomImage(CString strName) 
{ 
	SetImage(m_BitmapBottom, strName); 
	SetImageSize(&m_BitmapBottom, m_szBitmapBottom); 
} 
 
void CImageTabWnd::SetBottomImage(UINT nID) 
{ 
	SetImage(m_BitmapBottom, nID); 
	SetImageSize(&m_BitmapBottom, m_szBitmapBottom); 
} 
 
void CImageTabWnd::SetLeftImage(CString strName) 
{ 
	SetImage(m_BitmapLeft, strName); 
	SetImageSize(&m_BitmapLeft, m_szBitmapLeft); 
} 
 
void CImageTabWnd::SetLeftImage(UINT nID) 
{ 
	SetImage(m_BitmapLeft, nID); 
	SetImageSize(&m_BitmapLeft, m_szBitmapLeft); 
} 
 
void CImageTabWnd::SetRightImage(CString strName) 
{ 
	SetImage(m_BitmapRight, strName); 
	SetImageSize(&m_BitmapRight, m_szBitmapRight); 
} 
 
void CImageTabWnd::SetRightImage(UINT nID) 
{ 
	SetImage(m_BitmapRight, nID); 
	SetImageSize(&m_BitmapRight, m_szBitmapRight); 
} 
 
void CImageTabWnd::SetBkImage(CString strName) 
{ 
	SetImage(m_BitmapBk, strName); 
	SetImageSize(&m_BitmapBk, m_szBitmapBk); 
} 
 
void CImageTabWnd::SetBkImage(UINT nID) 
{ 
	SetImage(m_BitmapBk, nID); 
	SetImageSize(&m_BitmapBk, m_szBitmapBk); 
} 
 
void CImageTabWnd::SetAdImage(CString strName) 
{ 
	SetImage(m_BitmapAd, strName); 
	SetImageSize(&m_BitmapAd, m_szBitmapAd); 
} 
 
void CImageTabWnd::SetAdImage(UINT nID) 
{ 
	SetImage(m_BitmapAd, nID); 
	SetImageSize(&m_BitmapAd, m_szBitmapAd); 
} 
 
void CImageTabWnd::DrawRangeImage(CBitmap *pBitmap, CDC *pDC, CRect rc) 
{ 
	CDC MemDC; 
	BITMAP bm; 
	pBitmap->GetBitmap(&bm); 
 
	int li_Width = bm.bmWidth; 
	int li_Height = bm.bmHeight; 
 
	MemDC.CreateCompatibleDC(pDC); 
	CBitmap* pOldBitmap = MemDC.SelectObject(pBitmap); 
 
	int x=rc.left; 
	int y=rc.top; 
	while (y < (rc.Height()+rc.top))  
 	{ 
 		while(x < (rc.Width()+rc.left))  
 		{ 
			pDC->BitBlt(x, y, li_Width, li_Height, &MemDC, 0, 0, SRCCOPY); 
 			x += li_Width; 
 		} 
		x = rc.left; 
 		y += li_Height; 
 	} 
 
	MemDC.SelectObject(pOldBitmap); 
	MemDC.DeleteDC(); 
} 
 
void CImageTabWnd::DrawPosImage(CBitmap *pBitmap, CDC *pDC, CPoint pt) 
{ 
	CDC MemDC; 
	MemDC.CreateCompatibleDC(pDC); 
	CBitmap *pOldBitmap = (CBitmap*)MemDC.SelectObject(pBitmap); 
 
	BITMAP bm; 
	pBitmap->GetBitmap(&bm); 
	int li_Width = bm.bmWidth; 
	int li_Height = bm.bmHeight; 
 
	pDC->BitBlt(pt.x, pt.y, li_Width, li_Height, &MemDC, 0, 0, SRCCOPY); 
	 
	MemDC.SelectObject(pOldBitmap); 
	MemDC.DeleteDC(); 
} 
 
 
BOOL CImageTabWnd::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)  
{ 
	// TODO: Add your message handler code here and/or call default 
	CPoint pt; 
	GetCursorPos(&pt); 
	ScreenToClient(&pt); 
	for(int i=0; iGetBitmap(&bm); 
 
	sz = CSize(bm.bmWidth, bm.bmHeight); 
} 
 
void CImageTabWnd::OnSize(UINT nType, int cx, int cy)  
{ 
	CWnd::OnSize(nType, cx, cy); 
	 
	// TODO: Add your message handler code here 
	CRect rcClient; 
	GetClientRect(&rcClient); 
	for(int i=0; iGetSafeHwnd()) 
			{ 
				m_pTabDialog[i]->MoveWindow(m_rcDialog, FALSE); 
				UpdateTabWnd(); 
			} 
		} 
	} 
	ShowDialog(); 
} 
 
void CImageTabWnd::SetTabWnd(int nIndex, CDialog *pDlg) 
{ 
	ASSERT(nIndex < m_nTabCount); 
 
	m_pTabDialog[nIndex] = pDlg; 
} 
 
void CImageTabWnd::ShowDialog() 
{ 
	CRect rcClient; 
	GetClientRect(&rcClient); 
	for(int i=0; iShowWindow(SW_HIDE); 
		} 
	} 
	if (m_pTabDialog[m_nCurrentIndex]) 
	{ 
		m_pTabDialog[m_nCurrentIndex]->ShowWindow(SW_SHOW); 
		m_pTabDialog[m_nCurrentIndex]->SetFocus(); 
	} 
} 
 
 
void CImageTabWnd::OnTimer(UINT nIDEvent)  
{ 
	// TODO: Add your message handler code here and/or call default 
	if (m_BitmapAd.m_hObject) 
	{ 
		CRect rcClient; 
		GetClientRect(&rcClient); 
		CRect rcAd; 
		if ((rcClient.Width()-m_szBitmapAd.cx)/2 >0) 
			rcAd = CRect((rcClient.Width()-m_szBitmapAd.cx)/2-2, rcClient.Height()-(m_szBitmapBottom.cy+m_szBitmapAd.cy)/2, 
							(rcClient.Width()+m_szBitmapAd.cx)/2+4, 
							rcClient.Height()+(m_szBitmapBottom.cy-m_szBitmapAd.cy)/2+2); 
		else 
			rcAd = CRect(0, rcClient.Height()-(m_szBitmapBottom.cy+m_szBitmapAd.cy)/2+1,  
							m_szBitmapAd.cx, rcClient.Height()+(m_szBitmapBottom.cy-m_szBitmapAd.cy)/2); 
		InvalidateRect(rcAd, FALSE); 
	} 
	CWnd::OnTimer(nIDEvent); 
} 
 
void CImageTabWnd::PreSubclassWindow()  
{ 
	// TODO: Add your specialized code here and/or call the base class 
	SetTimer(1, 1000, NULL); 
	CWnd::PreSubclassWindow(); 
} 
 
BOOL CImageTabWnd::OnEraseBkgnd(CDC* pDC)  
{ 
	// TODO: Add your message handler code here and/or call default 
	return TRUE; 
	return CWnd::OnEraseBkgnd(pDC); 
} 
 
void CImageTabWnd::UpdateTabWnd() 
{ 
	CRect rcClient; 
	GetClientRect(&rcClient); 
	//TOP 
	InvalidateRect(CRect(0, 0, rcClient.Width(), TITLE_HEIGHT)); 
	//BOTTOM 
	InvalidateRect(CRect(0, rcClient.Height()-m_szBitmapBottom.cy-DIALOG_MARGIN, rcClient.Width(), rcClient.Height())); 
	//LEFT 
	InvalidateRect(CRect(0, 0, m_szBitmapLeft.cx+DIALOG_MARGIN, rcClient.Height())); 
	//RIGHT 
	InvalidateRect(CRect(rcClient.Width()-m_szBitmapRight.cx-DIALOG_MARGIN, 0, rcClient.Width(), rcClient.Height())); 
	 
} 
 
void CImageTabWnd::SetToolTip(int nIndex, CString strTips) 
{ 
	ASSERT(nIndex < m_nTabCount); 
	ASSERT(m_pRectTab[nIndex].IsRectEmpty() == FALSE); 
	m_ToolTip.AddTool(this, strTips, m_pRectTab[nIndex], 12345678); 
	m_ToolTip.SetTipBkColor(RGB(231,236,247)); 
	m_ToolTip.Activate(TRUE); 
} 
 
BOOL CImageTabWnd::PreTranslateMessage(MSG* pMsg)  
{ 
	// TODO: Add your specialized code here and/or call the base class 
	if (m_ToolTip.GetSafeHwnd()) 
		m_ToolTip.RelayEvent( pMsg ); 
	return CWnd::PreTranslateMessage(pMsg); 
} 
 
int CImageTabWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)  
{ 
	if (CWnd::OnCreate(lpCreateStruct) == -1) 
		return -1; 
	 
	// TODO: Add your specialized creation code here 
	if (!m_ToolTip.Create(this)) 
		return -1; 
 
	//ModifyStyleEx(0, WS_EX_CLIENTEDGE); 
	return 0; 
}