⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 timeofzonedlg.cpp

📁 EVC开发的手持导航的用户操作界面
💻 CPP
字号:
// TimeOfZoneDlg.cpp : implementation file
//

#include "stdafx.h"
#include "GPS.h"
#include "TimeOfZoneDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTimeOfZoneDlg dialog


CTimeOfZoneDlg::CTimeOfZoneDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTimeOfZoneDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTimeOfZoneDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CTimeOfZoneDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTimeOfZoneDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CTimeOfZoneDlg, CDialog)
	//{{AFX_MSG_MAP(CTimeOfZoneDlg)
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_PAINT()
	ON_WM_ERASEBKGND()
	ON_WM_KEYDOWN()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTimeOfZoneDlg message handlers

BOOL CTimeOfZoneDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_Left=0;
	m_Top=0;
	m_Width=320;
	m_Height=240;
	::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_TIMEOFZONE_BKG);

	SetToolRectangle();

	m_prePick=-1;
	m_currentPick=0;
	m_bIsExecute=FALSE ;
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CTimeOfZoneDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	
//	AfxMessageBox(L"asdf",MB_OK);
	m_prePick = m_currentPick ;

	for ( int i = 0 ; i < 3 ; i ++ ) 
	{		
		if (  m_rect[i].PtInRect (point)   )
		{									
		
			{	
				
				CDC* pDC = GetDC () ;
				CDC  memDC ;
				memDC.CreateCompatibleDC ( pDC ) ;
				
				CBitmap bmp ;
				
				switch ( m_prePick )
				{
				case 0:
					{//白
						bmp.LoadBitmap ( IDB_TIMEOFZONE_LEFT_W);
						
						CBitmap* pOldBitmap = memDC.SelectObject ( &bmp ) ;
						
						pDC->BitBlt ( m_rect[m_prePick].TopLeft().x, m_rect[m_prePick].TopLeft().y, m_rect[m_prePick].Width(), 
							m_rect[m_prePick].Height(), &memDC, 0, 0, SRCCOPY ) ;
						
						memDC.SelectObject ( pOldBitmap ) ;						
						
						break ;
					}
				case 1:
					{
						bmp.LoadBitmap ( IDB_TIMEOFZONE_RIGHT_W ) ;
						
						CBitmap* pOldBitmap = memDC.SelectObject ( &bmp ) ;
						
						pDC->BitBlt ( m_rect[m_prePick].TopLeft().x, m_rect[m_prePick].TopLeft().y, m_rect[m_prePick].Width(), 
							m_rect[m_prePick].Height(), &memDC, 0, 0, SRCCOPY ) ;
						
						memDC.SelectObject ( pOldBitmap ) ;
						break ;
					}
				case 2:
					{
						bmp.LoadBitmap ( IDB_TIMEOFZONE_OK_W ) ;
						
						CBitmap* pOldBitmap = memDC.SelectObject ( &bmp ) ;
						
						pDC->BitBlt ( m_rect[m_prePick].TopLeft().x, m_rect[m_prePick].TopLeft().y, m_rect[m_prePick].Width(), 
							m_rect[m_prePick].Height(), &memDC, 0, 0, SRCCOPY ) ;
						
						memDC.SelectObject ( pOldBitmap ) ;
						break ;
					}
			
				
				}
				
				CBitmap   bmp1 ;
				switch ( i )
				{
				case 0:
					{			
						//load the bitmap	
						//黑
						bmp1.LoadBitmap ( IDB_TIMEOFZONE_LEFT_B ) ;
						
						CBitmap* pOldBitmap = memDC.SelectObject ( &bmp1 ) ;
						
						pDC->BitBlt ( m_rect[i].TopLeft().x, m_rect[i].TopLeft().y, m_rect[i].Width(), 
							m_rect[i].Height(), &memDC, 0, 0, SRCCOPY ) ;
						
						memDC.SelectObject ( pOldBitmap ) ;
						
						break ;
					}
				case 1:			
					{				
						//load the bitmap
						
						bmp1.LoadBitmap ( IDB_TIMEOFZONE_RIGHT_B) ;
						
						CBitmap* pOldBitmap = memDC.SelectObject ( &bmp1 ) ;
						
						pDC->BitBlt ( m_rect[i].TopLeft().x, m_rect[i].TopLeft().y, m_rect[i].Width(), 
							m_rect[i].Height(), &memDC, 0, 0, SRCCOPY ) ;
						
						memDC.SelectObject ( pOldBitmap ) ;
						
						break ;
					}
				case 2:
					{							
						//load the bitmap
				//		AfxMessageBox(L"asdf",MB_OK);
						bmp1.LoadBitmap ( IDB_TIMEOFZONE_OK_B ) ;
						
						CBitmap* pOldBitmap = memDC.SelectObject ( &bmp1 ) ;
						
						pDC->BitBlt ( m_rect[i].TopLeft().x, m_rect[i].TopLeft().y, m_rect[i].Width(), 
							m_rect[i].Height(), &memDC, 0, 0, SRCCOPY ) ;
						
						memDC.SelectObject ( pOldBitmap ) ;
						
						break ;
					}
			
				}
				
				memDC.DeleteDC () ;
				ReleaseDC ( pDC ) ;
				
				m_currentPick = i ;				
			}	

		}
	}
}

void CTimeOfZoneDlg::OnLButtonUp(UINT nFlags, CPoint point) 
{
	
	CopyBMP(IDB_TIMEOFZONE_LEFT_W,0);
	CopyBMP(IDB_TIMEOFZONE_RIGHT_W,1);
	CopyBMP(IDB_TIMEOFZONE_OK_W,2);

	
	

	m_bIsExecute = FALSE ;
	for ( int i = 0 ; i < 3 ; i ++ ) 
	{		
		if (  m_rect[i].PtInRect (point)   )
		{
			if ( m_currentPick == i)
			{
				m_bIsExecute =TRUE ;
				switch (i)
				{
				case 0:	
						break ;
				case 1:
						break ;
				case 2:
				
						CDialog::OnCancel();
						break ;
				default:
						break ;
				}
			}
		}
		
	}
}

void CTimeOfZoneDlg::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
}

BOOL CTimeOfZoneDlg::OnEraseBkgnd(CDC* pDC) 
{
	// TODO: Add your message handler code here and/or call default
		// 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;
}

void CTimeOfZoneDlg::CopyBMP(int m_map, int i)
{
CDC* pDC = GetDC () ;
	CDC  memDC ;
	memDC.CreateCompatibleDC ( pDC ) ;
	CBitmap bmp,bmp1 ;
	CBitmap* pOldBitmap ;
	bmp1.LoadBitmap ( m_map) ;
	pOldBitmap = memDC.SelectObject ( &bmp1 ) ;
	pDC->BitBlt ( m_rect[i].TopLeft().x, m_rect[i].TopLeft().y, m_rect[i].Width(), 
	m_rect[i].Height(), &memDC, 0, 0, SRCCOPY ) ;
	memDC.SelectObject ( pOldBitmap ) ;
	
	memDC.DeleteDC () ;
	ReleaseDC ( pDC ) ;	
}

void CTimeOfZoneDlg::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_NavRefresh ||  m_currentPick == 0)
	{
	//黑
		pBitmap ->LoadBitmap ( IDB_TIMEOFZONE_LEFT_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_TIMEOFZONE_LEFT_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 ;
	
	//.............................................................
	//分配bitmap对象内存
	pBitmap = new CBitmap ;
	
	if ( m_currentPick == 1 )
	{
	pBitmap ->LoadBitmap ( IDB_TIMEOFZONE_RIGHT_B ) ;
	pOldBitmap = memDC.SelectObject ( pBitmap ) ;
	
	//将图片COPY到指定的像素位置
	dc.BitBlt ( m_rect[1].TopLeft().x, m_rect[1].TopLeft().y, 111, 111, &memDC, 0, 0, SRCCOPY ) ;
	}
	else
	{		
		pBitmap ->LoadBitmap ( IDB_TIMEOFZONE_RIGHT_W ) ;
		pOldBitmap = memDC.SelectObject ( pBitmap ) ;
		
		//将图片COPY到指定的像素位置
		dc.BitBlt ( m_rect[1].TopLeft().x, m_rect[1].TopLeft().y, 111, 111, &memDC, 0, 0, SRCCOPY ) ;
	}

	
	memDC.SelectObject ( pOldBitmap ) ;
	
	//释放bitmap对象内存
	delete pBitmap ;
	
	//...............................................................
	//分配bitmap对象内存
	pBitmap = new CBitmap ;
	
	if ( m_currentPick == 2 )
	{
	pBitmap ->LoadBitmap ( IDB_TIMEOFZONE_OK_B ) ;
	pOldBitmap = memDC.SelectObject ( pBitmap ) ;
	
	//将图片COPY到指定的像素位置
	dc.BitBlt ( m_rect[2].TopLeft().x, m_rect[2].TopLeft().y, 111, 111, &memDC, 0, 0, SRCCOPY ) ;
	}
	else
	{		
		pBitmap ->LoadBitmap ( IDB_TIMEOFZONE_OK_W ) ;
		pOldBitmap = memDC.SelectObject ( pBitmap ) ;
		
		//将图片COPY到指定的像素位置
		dc.BitBlt ( m_rect[2].TopLeft().x, m_rect[2].TopLeft().y, 111, 111, &memDC, 0, 0, SRCCOPY ) ;
	}
	
	memDC.SelectObject ( pOldBitmap ) ;
	
	//释放bitmap对象内存
	delete pBitmap ;
	
	
	//////////////////////
	memDC.DeleteDC ()  ;
}

void CTimeOfZoneDlg::SetToolRectangle()
{
	m_rect [0].SetRect(71,109,104,141);
	m_rect [1].SetRect(216,109,249,141);
	m_rect [2].SetRect(276,198,310,232);

}

void CTimeOfZoneDlg::OnOK() 
{
	switch (m_currentPick)
	{
				case 0:	
						break ;
				case 1:
						break ;
				case 2:
				
						CDialog::OnCancel();
						break ;
				default:
						break ;
	}
		
}

void CTimeOfZoneDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
		
	m_prePick=m_currentPick ;
			
	if ( nChar == VK_UP || nChar == VK_LEFT )
		{
			switch (m_prePick)
					{
					case 0:
						CopyBMP(IDB_TIMEOFZONE_LEFT_B,0);
						CopyBMP(IDB_TIMEOFZONE_RIGHT_W,1);
						CopyBMP(IDB_TIMEOFZONE_OK_W,2);
						m_currentPick = 0 ;
						break ;
					case 1:
						CopyBMP(IDB_TIMEOFZONE_LEFT_B,0);
						CopyBMP(IDB_TIMEOFZONE_RIGHT_W,1);
						CopyBMP(IDB_TIMEOFZONE_OK_W,2);
						m_currentPick = 0 ;
						break ;
					case 2:
						CopyBMP(IDB_TIMEOFZONE_LEFT_W,0);
						CopyBMP(IDB_TIMEOFZONE_RIGHT_B,1);
						CopyBMP(IDB_TIMEOFZONE_OK_W,2);
						m_currentPick = 1 ;
						break ;
			
					}
				}
				
			if ( nChar == VK_DOWN  || nChar == VK_RIGHT)
				{
					switch (m_prePick) 
					{
					case 0:
						CopyBMP(IDB_TIMEOFZONE_LEFT_W,0);
						CopyBMP(IDB_TIMEOFZONE_RIGHT_B,1);
						CopyBMP(IDB_TIMEOFZONE_OK_W,2);
						m_currentPick = 1 ;
						break ;
					case 1:
						CopyBMP(IDB_TIMEOFZONE_LEFT_W,0);
						CopyBMP(IDB_TIMEOFZONE_RIGHT_W,1);
						CopyBMP(IDB_TIMEOFZONE_OK_B,2);
						m_currentPick = 2 ;
						break ;
					case 2:
						CopyBMP(IDB_TIMEOFZONE_LEFT_W,0);
						CopyBMP(IDB_TIMEOFZONE_RIGHT_W,1);
						CopyBMP(IDB_TIMEOFZONE_OK_B,2);
						m_currentPick = 2 ;
						break ;
					}
				}
				
	
	CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -