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

📄 timeoftimedlg.cpp

📁 EVC开发的手持导航的用户操作界面
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// TimeOfTimeDlg.cpp : implementation file
//

#include "stdafx.h"
#include "GPS.h"
#include "TimeOfTimeDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
SYSTEMTIME time2;
/////////////////////////////////////////////////////////////////////////////
// CTimeOfTimeDlg dialog


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


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


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

/////////////////////////////////////////////////////////////////////////////
// CTimeOfTimeDlg message handlers

BOOL CTimeOfTimeDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();

	GetLocalTime(&time2);

	hour  .Format(_T("        %02d"),time2.wHour);
	minute.Format(_T("        %02d"),time2.wMinute);
	second.Format(_T("        %02d"),time2.wSecond);

	// 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_TIMEOFTIME_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 CTimeOfTimeDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	
		m_prePick = m_currentPick ;

	for ( int i = 0 ; i < 7 ; 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_TIMEOFTIME_1_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_TIMEOFTIME_1_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_TIMEOFTIME_2_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 3:
					{
						bmp.LoadBitmap ( IDB_TIMEOFTIME_2_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 4:
					{
						bmp.LoadBitmap ( IDB_TIMEOFTIME_3_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 5:
					{
						bmp.LoadBitmap ( IDB_TIMEOFTIME_3_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 6:
					{
						bmp.LoadBitmap ( IDB_TIMEOFTIME_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_TIMEOFTIME_1_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_TIMEOFTIME_1_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
						
						bmp1.LoadBitmap ( IDB_TIMEOFTIME_2_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 3:
					{
						//load the bitmap
						
						bmp1.LoadBitmap ( IDB_TIMEOFTIME_2_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 4:
					{
						//load the bitmap
						
						bmp1.LoadBitmap ( IDB_TIMEOFTIME_3_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 5:
					{
						//load the bitmap
						
						bmp1.LoadBitmap ( IDB_TIMEOFTIME_3_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 6:
					{
						//load the bitmap
						
						bmp1.LoadBitmap ( IDB_TIMEOFTIME_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 CTimeOfTimeDlg::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CopyBMP(IDB_TIMEOFTIME_1_LEFT_W,0);
	CopyBMP(IDB_TIMEOFTIME_1_RIGHT_W,1);
	CopyBMP(IDB_TIMEOFTIME_2_LEFT_W,2);
	CopyBMP(IDB_TIMEOFTIME_2_RIGHT_W,3);
	CopyBMP(IDB_TIMEOFTIME_3_LEFT_W,4);
	CopyBMP(IDB_TIMEOFTIME_3_RIGHT_W,5);
	CopyBMP(IDB_TIMEOFTIME_OK_W,6);

	
	

	m_bIsExecute = FALSE ;
	for ( int i = 0 ; i < 7 ; i ++ ) 
	{		
		if (  m_rect[i].PtInRect (point)   )
		{
			if ( m_currentPick == i)
			{
				m_bIsExecute =TRUE ;
				switch (i)
				{
				case 0:	
						OnBtnHourLeft();					
						break ;
				case 1:
						OnBtnHourRight();
						break ;
				case 2:
						OnBtnMinuteLeft();	
						break ;
				case 3:	
						OnBtnMinuteRight();
						break ;
				case 4:
						OnBtnSecondLeft();
						break ;
				case 5:
						OnBtnSecondRight();
						break ;
				case 6:	
						OnBtnOK();
						CDialog::OnOK();
						break ;
			
			
				default:
						break ;
				}
			}
		}
		
	}
}

void CTimeOfTimeDlg::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
	
	dc.SetBkMode(TRANSPARENT);
	dc.SetTextColor(RGB(255,0,10));

	
	
	dc.ExtTextOut(121,55,ETO_CLIPPED,CRect(121,55,191,71),hour,NULL);
	dc.ExtTextOut(121,115,ETO_CLIPPED,CRect(121,115,197,135),minute,NULL);
	dc.ExtTextOut(121,176,ETO_CLIPPED,CRect(121,176,197,189),second,NULL);

}

BOOL CTimeOfTimeDlg::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;
}

void CTimeOfTimeDlg::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 CTimeOfTimeDlg::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_TIMEOFTIME_1_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_TIMEOFTIME_1_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 ) ;

⌨️ 快捷键说明

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