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

📄 timectrldlg.cpp

📁 LCD source code, for microcontroller AT89s51
💻 CPP
字号:
// timectrlDlg.cpp : implementation file
//

#include "stdafx.h"
#include "timectrl.h"
#include "timectrlDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTimectrlDlg dialog

CTimectrlDlg::CTimectrlDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTimectrlDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTimectrlDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	
	TRACE("CTimectrlDlg::CTimectrlDlg\r\n");
}

void CTimectrlDlg::DoDataExchange(CDataExchange* pDX)

{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTimectrlDlg)
	DDX_Control(pDX, IDC_CHECK1, m_hex);
	DDX_Control(pDX, IDC_LCD, m_lcd);
	DDX_Control(pDX, IDC_EDIT2, m_ttt);
	DDX_Control(pDX, IDC_EDIT1, m_tme);
	DDX_Control(pDX, IDC_TIME, m_time);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTimectrlDlg, CDialog)
	//{{AFX_MSG_MAP(CTimectrlDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
	ON_MESSAGE(WM_TCHANGE, lcd_change)
	ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTimectrlDlg message handlers

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

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// To match the background color

	
	m_lcd.SetBgColor(RGB(192, 192, 192));
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CTimectrlDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CTimectrlDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CTimectrlDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

BOOL CTimectrlDlg::PreTranslateMessage(MSG* pMsg) 

{
	if(pMsg->message == WM_TCHANGE)
		{
		TRACE("CTimectrlDlg::PreTranslateMessage WM_TCHANGE on %d\r\n", pMsg->wParam);

		int hh = m_time.hour1.num * 10 + m_time.hour2.num;
		int mm = m_time.minute1.num * 10 + m_time.minute2.num;
	
		// Update Edit box
		CString str; str.Format("%02d:%02d", hh, mm);
		m_tme.SetWindowText(str);

		// Do the 12 hour format:
		CString str3("AM"); if(hh > 11) str3 = "PM";
		if(hh > 12) hh -= 12;

		CString str2; str2.Format("%02d:%02d %s", hh, mm, str3);
		m_ttt.SetWindowText(str2);
		}

	if(pMsg->message == WM_OVERFLOW)
		{
		TRACE("CTimectrlDlg::PreTranslateMessage WM_OVERFLOW on %d\r\n", pMsg->wParam);
		}

	if(pMsg->message == WM_UNDERFLOW)
		{
		TRACE("CTimectrlDlg::PreTranslateMessage WM_UNDERFLOW on %d\r\n", pMsg->wParam);
		}

	return CDialog::PreTranslateMessage(pMsg);
}

void CTimectrlDlg::OnChangeEdit1() 

{
	CString str;
	m_tme.GetWindowText(str);

	if(str.GetLength() < 3)
		return;

	// Signs of completion
	if(str[2] != ':')
		return;

	int hh = atoi(str);
	int mm = atoi(str.Mid(3));
	
	TRACE("CTimectrlDlg::OnChangeEdit1 %d %d\r\n", hh, mm);

	m_time.hour1.num = hh / 10;
	m_time.hour2.num = hh % 10;

	m_time.minute1.num = mm / 10;
	m_time.minute2.num = mm % 10;

	m_time.Invalidate();	
}

void CTimectrlDlg::lcd_change(WORD wparam, LONG lparam)

{
	TRACE("lcd change on %d\r\n", wparam);
}

void CTimectrlDlg::OnCheck1() 
{
	if(m_hex.GetCheck())
		{
		m_lcd.SetMinMax(0, 15);
		}
	else
		{
		m_lcd.SetMinMax(0, 9);
		}
}

⌨️ 快捷键说明

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