www.pudn.com > dizibutton.zip > SButton.cpp


// SButton.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "¶¤×Ó°´Å¥.h" 
#include "SButton.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CSButton 
 
CSButton::CSButton() 
{ 
	 
} 
 
CSButton::~CSButton() 
{ 
} 
 
 
BEGIN_MESSAGE_MAP(CSButton, CButton) 
	//{{AFX_MSG_MAP(CSButton) 
	ON_WM_LBUTTONDOWN() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CSButton message handlers 
 
void CSButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)  
{ 
	CRect client=lpDrawItemStruct->rcItem; 
	CDC *pDC=CDC::FromHandle(lpDrawItemStruct->hDC); 
 
	DWORD state=lpDrawItemStruct->itemState; 
	CBrush brush; 
	brush.CreateSolidBrush(::GetSysColor(COLOR_BTNFACE)); 
    pDC->FillRect(client,&brush); 
	//pDC->Draw3dRect(client,::GetSysColor(COLOR_BTNFACE),::GetSysColor(COLOR_3DDKSHADOW)); 
	if(m_state) 
	{ 
		pDC->StretchBlt(client.left,client.top,client.Width(),client.Height(),&memdc,0,0,24,21,SRCCOPY); 
		GetParent()->SetWindowPos(&CWnd::wndTopMost,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE); 
	} 
	else 
	{ 
		pDC->StretchBlt(client.left,client.top,client.Width(),client.Height(),&memdc2,0,0,24,21,SRCCOPY); 
		GetParent()->SetWindowPos(&CWnd::wndNoTopMost,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE); 
	} 
 
 
 
} 
 
void CSButton::OnLButtonDown(UINT nFlags, CPoint point)  
{ 
	m_state=!m_state; 
	CButton::OnLButtonDown(nFlags, point); 
} 
 
void CSButton::PreSubclassWindow()  
{ 
	m_state=FALSE; 
	bitmap.LoadBitmap(IDB_BITMAP1); 
	bitmap2.LoadBitmap(IDB_BITMAP2); 
	CDC *pDC=GetDC(); 
	memdc.CreateCompatibleDC(pDC); 
	memdc.SelectObject(&bitmap); 
	memdc2.CreateCompatibleDC(pDC); 
	memdc2.SelectObject(&bitmap2); 
    CButton::PreSubclassWindow(); 
}