www.pudn.com > GPS.2.rar > PowerDlg.cpp


// PowerDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "GPS.h" 
#include "PowerDlg.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CPowerDlg dialog 
 
 
CPowerDlg::CPowerDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CPowerDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CPowerDlg) 
		// NOTE: the ClassWizard will add member initialization here 
	//}}AFX_DATA_INIT 
} 
 
 
void CPowerDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CPowerDlg) 
		// NOTE: the ClassWizard will add DDX and DDV calls here 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CPowerDlg, CDialog) 
	//{{AFX_MSG_MAP(CPowerDlg) 
	ON_WM_ERASEBKGND() 
	ON_WM_PAINT() 
	ON_WM_LBUTTONUP() 
	ON_WM_LBUTTONDOWN() 
	ON_WM_KEYDOWN() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CPowerDlg message handlers 
 
BOOL CPowerDlg::OnEraseBkgnd(CDC* pDC)  
{ 
	// TODO: Add your message handler code here and/or call default 
	 
		 
	BITMAP bmpInfo; 
	m_BackScreenBitmap.GetBitmap(&bmpInfo); 
	 
	// Create an in-memory DC compatible with the 
	// display DC we're using to paint 
	CDC dcMemory; 
	dcMemory.CreateCompatibleDC(pDC); 
	 
	 
	// Select the bitmap into the in-memory DC 
	CBitmap* pOldBitmap = dcMemory.SelectObject(&m_BackScreenBitmap); 
	 
	// Find a centerpoint for the bitmap in the client area 
	CRect rect; 
	GetClientRect(&rect); 
	 
	// Copy the bits from the in-memory DC into the on- 
	// screen DC to actually do the painting. Use the centerpoint 
	// we computed for the target offset. 
	pDC->BitBlt(0, 0, bmpInfo.bmWidth, bmpInfo.bmHeight, &dcMemory,  
		0, 0, SRCCOPY); 
	 
	dcMemory.SelectObject(pOldBitmap); 
	return TRUE; 
} 
 
BOOL CPowerDlg::OnInitDialog()  
{ 
	CDialog::OnInitDialog(); 
	 
	// TODO: Add extra initialization here 
	m_Left=0; 
	m_Top=0; 
	m_Width=320; 
	m_Height=240; 
//	m_prePick=-1; 
	m_currentPick=0; 
	m_bIsExecute=FALSE ; 
	 
	::SetWindowPos(this->GetSafeHwnd(),HWND_TOP,m_Left, m_Top,  
		m_Width, m_Height,SWP_SHOWWINDOW); 
	 
	CenterWindow(GetDesktopWindow());	// center to the hpc screen 
	// TODO: Add extra initialization here 
	m_BackScreenBitmap.LoadBitmap(IDB_POWER_BKG); 
 
	SetToolRectangle(); 
	return TRUE;  // return TRUE unless you set the focus to a control 
	              // EXCEPTION: OCX Property Pages should return FALSE 
} 
 
void CPowerDlg::SetToolRectangle() 
{ 
	m_rect [0].SetRect(276,197,309,233); 
//	m_rect [1].SetRect(216,109,248,141); 
	 
} 
 
void CPowerDlg::OnPaint()  
{ 
	CPaintDC dc(this); // device context for painting 
	 
	// TODO: Add your message handler code here 
	DrawInterface(dc); 
	// Do not call CDialog::OnPaint() for painting messages 
} 
 
void CPowerDlg::DrawInterface(CDC &dc) 
{ 
	CDC  memDC ; 
	memDC.CreateCompatibleDC ( &dc ) ; 
	 
	CBitmap*  pBitmap ;		//load all bitmap 
	CBitmap*  pOldBitmap ;	//save old bitmap temp 
	 
	//............................................................. 
	//分配bitmap对象内存 
	pBitmap = new CBitmap ; 
	 
	if ( m_currentPick == 0) 
	{ 
	//黑 
		pBitmap ->LoadBitmap ( IDB_POWER_OK_B ) ; 
		pOldBitmap = memDC.SelectObject ( pBitmap ) ; 
		 
		//将图片COPY到指定的像素位置 
		dc.BitBlt ( m_rect[0].TopLeft().x, m_rect[0].TopLeft().y, 111, 111, &memDC, 0, 0, SRCCOPY ) ; 
	} 
	else 
	{		//白 
		pBitmap ->LoadBitmap ( IDB_POWER_OK_W) ; 
		pOldBitmap = memDC.SelectObject ( pBitmap ) ; 
		 
		//将图片COPY到指定的像素位置 
		dc.BitBlt ( m_rect[0].TopLeft().x, m_rect[0].TopLeft().y, 111, 111, &memDC, 0, 0, SRCCOPY ) ; 
	} 
	 
	 
	memDC.SelectObject ( pOldBitmap ) ; 
	 
	//释放bitmap对象内存 
	delete pBitmap ; 
	 
 
	//............................................................... 
	memDC.DeleteDC ()  ; 
} 
 
void CPowerDlg::OnLButtonUp(UINT nFlags, CPoint point)  
{ 
	CDC* pDC = GetDC () ; 
	CDC  memDC ; 
	memDC.CreateCompatibleDC ( pDC ) ; 
	CBitmap bmp,bmp1 ; 
	CBitmap* pOldBitmap ; 
	bmp1.LoadBitmap ( IDB_POWER_OK_W) ; 
	pOldBitmap = memDC.SelectObject ( &bmp1 ) ; 
	pDC->BitBlt ( m_rect[0].TopLeft().x, m_rect[0].TopLeft().y, m_rect[0].Width(),  
	m_rect[0].Height(), &memDC, 0, 0, SRCCOPY ) ; 
	memDC.SelectObject ( pOldBitmap ) ; 
	 
	memDC.DeleteDC () ; 
	ReleaseDC ( pDC ) ;	 
 
	// TODO: Add your message handler code here and/or call default 
 
	if (m_rect[0].PtInRect (point)) 
	{									 
		OnOK();					 
	} 
} 
 
void CPowerDlg::OnLButtonDown(UINT nFlags, CPoint point)  
{ 
	// TODO: Add your message handler code here and/or call default 
	 
	if (  m_rect[0].PtInRect (point)   ) 
		{									 
			CDC* pDC = GetDC () ; 
			CDC  memDC ; 
			memDC.CreateCompatibleDC ( pDC ) ; 
			CBitmap bmp ; 
			bmp.LoadBitmap ( IDB_POWER_OK_W ) ; 
			CBitmap* pOldBitmap = memDC.SelectObject ( &bmp ) ; 
			pDC->BitBlt ( m_rect[0].TopLeft().x, m_rect[0].TopLeft().y, m_rect[0].Width(),  
							m_rect[0].Height(), &memDC, 0, 0, SRCCOPY ) ; 
			memDC.SelectObject ( pOldBitmap ) ;	 
			ReleaseDC(pDC); 
	} 
} 
 
void CPowerDlg::OnOK()  
{ 
	CDialog::OnOK(); 
} 
 
void CPowerDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)  
{ 
	// TODO: Add your message handler code here and/or call default 
		 
	 
	CDialog::OnKeyDown(nChar, nRepCnt, nFlags); 
}