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

📄 lcddlg.cpp

📁 EVC实现LCD屏
💻 CPP
字号:
// LCDDlg.cpp : implementation file
//

#include "stdafx.h"
#include "LCDSample.h"
#include "LCDDlg.h"

#include "OlePicture.h"
//#include <vfw.h>

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

/////////////////////////////////////////////////////////////////////////////
// LCDDlg dialog

LCDDlg::LCDDlg(int nBGPeriod, int nFloorNumber, int nDirection, CString strAVIFile, LOGFONT lfTimeFont, COLORREF crTimeColor, CWnd* pParent /*=NULL*/)
	: CDialog(LCDDlg::IDD, pParent)
{
	m_nBGPeriod = nBGPeriod;
	m_nFloorNumber = nFloorNumber;
	m_nDirection = nDirection;
	m_strAVIFile = strAVIFile;
	m_lfTimeFont = lfTimeFont;
	m_crTimeColor = crTimeColor;

	m_nCurrentBGImage = 0;

	// 初始化集合m_BGImages
	CString strExeFile;
	::GetModuleFileName(NULL, strExeFile.GetBuffer(_MAX_PATH), _MAX_PATH);
	strExeFile.ReleaseBuffer();
	int n = strExeFile.ReverseFind ('\\');
	CString strPath = strExeFile.Left(n+1);
	m_BGImages.Add(strPath + "bg0.jpg");
	m_BGImages.Add(strPath + "bg1.jpg");
	m_BGImages.Add(strPath + "bg2.jpg");

	//{{AFX_DATA_INIT(CLCDDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}



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


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


BEGIN_MESSAGE_MAP(LCDDlg, CDialog)
	//{{AFX_MSG_MAP(LCDDlg)
		// NOTE: the ClassWizard will add message map macros here
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// LCDDlg message handlers

BOOL LCDDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// 创建内存DC/位图
	CClientDC dc(this);
	m_dcMem.CreateCompatibleDC(&dc);
	CRect rt;
	GetClientRect(&rt);
	m_bmpMem.CreateCompatibleBitmap(&dc, rt.Width(), rt.Height());
	m_dcMem.SelectObject(&m_bmpMem);

	// 把当前背景图片保存至内存位图
	OlePicture olePicture;
	olePicture.LoadPicture(m_BGImages[m_nCurrentBGImage]);
	olePicture.DrawPicture(m_dcMem.m_hDC, 0, 0);

	// 创建AVI视频窗口
	//m_hAVIWnd = ::MCIWndCreate(m_hWnd, AfxGetInstanceHandle(), MCIWNDF_NOPLAYBAR, m_strAVIFile);
	//RepositionAVIWindow();

	// 启动定时器
	SetTimer(1, m_nBGPeriod*1000, NULL); // 切换背景
	SetTimer(2, 1000, NULL); // 显示时间

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void LCDDlg::SetParameter(int nBGPeriod, int nFloorNumber, int nDirection, CString strAVIFile, LOGFONT lfTimeFont, COLORREF crTimeColor)
{
	m_nBGPeriod = nBGPeriod;
	m_nFloorNumber = nFloorNumber;
	m_nDirection = nDirection;
	m_strAVIFile = strAVIFile;
	m_lfTimeFont = lfTimeFont;
	m_crTimeColor = crTimeColor;

	// 设置AVI视频
	//MCIWndOpen(m_hAVIWnd, (LPCTSTR)m_strAVIFile, 0);
	//RepositionAVIWindow();

	// 设置切换背景的定时器
	SetTimer(1, m_nBGPeriod*1000, NULL);

	Invalidate();
}


void LCDDlg::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// 显示背景图片
	CRect rt;
	GetClientRect(&rt);
	dc.BitBlt(0, 0, rt.Width(), rt.Height(), &m_dcMem, 0, 0, SRCCOPY);

	// 画电梯方向
	GetDlgItem(IDC_DIRECTION)->GetWindowRect(&rt);
	ScreenToClient(&rt);
	OlePicture olePicture;
	olePicture.LoadPicture(NULL, m_nDirection == 0 ? IDB_BITMAP_UP : IDB_BITMAP_DOWN, RT_BITMAP);
	olePicture.DrawPicture(dc.m_hDC, rt.left, rt.top, rt.Width(), rt.Height());

	// 输出电梯楼层
	GetDlgItem(IDC_FLOOR_NUMBER)->GetWindowRect(&rt);
	ScreenToClient(&rt);
	CFont font;
	font.CreatePointFont(560, _T("Microsoft Sans Serif"),&dc);
	dc.SelectObject(&font);
	dc.SetBkMode(TRANSPARENT);
	dc.SetTextColor(RGB(255,128,0));
	CString str;
	str.Format(_T("%d", m_nFloorNumber));
	dc.DrawText(str, &rt, DT_CENTER | DT_VCENTER | DT_SINGLELINE);

	// Do not call CDialog::OnPaint() for painting messages
}

void LCDDlg::OnTimer(UINT nIDEvent) 
{
	if (nIDEvent == 1)
	{
		// 切换背景图片
		m_nCurrentBGImage++;
		if (m_nCurrentBGImage == m_BGImages.GetSize())
			m_nCurrentBGImage = 0;
		OlePicture olePicture;
		olePicture.LoadPicture(m_BGImages[m_nCurrentBGImage]);
		olePicture.DrawPicture(m_dcMem.m_hDC, 0, 0);
		Invalidate();
	}
	else
	{
		// 擦除原来的时间
		CClientDC dc(this);
		CRect rt;
		GetDlgItem(IDC_TIME)->GetWindowRect(&rt);
		ScreenToClient(&rt);
		dc.BitBlt(rt.left, rt.top, rt.Width(), rt.Height(), &m_dcMem, rt.left, rt.top, SRCCOPY);

		// 显示时间
		CFont font;
		font.CreateFontIndirect(&m_lfTimeFont);
		dc.SelectObject(&font);
		dc.SetBkMode(TRANSPARENT);
		dc.SetTextColor(m_crTimeColor);
		//CString str = CTime::GetCurrentTime().Format(_T("%H:%M:%S"));
		//dc.DrawText(str, &rt, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
	}

	CDialog::OnTimer(nIDEvent);
}

/*
void LCDDlg::RepositionAVIWindow()
{
	CRect rt;
	GetDlgItem(IDC_AVI)->GetWindowRect(&rt);
	ScreenToClient(&rt);
	int avi_width, avi_height;
	if (MCIWndCanPlay(m_hAVIWnd))
	{
		// 获取AVI视频的分辨率
		CRect rtAVI;
		MCIWndGetDest(m_hAVIWnd, &rtAVI);
		// 计算缩放尺寸
		int w1 = rt.Width(), h1 = rt.Height();
		int w2 = rtAVI.Width(), h2 = rtAVI.Height();
		if (w1*h2 < w2*h1)
		{
			avi_width  = w1;
			avi_height = h2*w1/w2;
		}
		else
		{
			avi_width  = w2*h1/h2;
			avi_height = h1;
		}
		// 播放视频
		MCIWndPlay(m_hAVIWnd);
	}
	else
	{
		avi_width  = rt.Width();
		avi_height = rt.Height();
	}
	::MoveWindow(m_hAVIWnd, rt.left, rt.top, avi_width, avi_height, TRUE);
}
*/

⌨️ 快捷键说明

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