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

📄 -

📁 晶体管显示系统时间和数字的方法。
💻
字号:
// 数码管2Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "数码管2.h"
#include "数码管2Dlg.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()

/////////////////////////////////////////////////////////////////////////////
// CMy2Dlg dialog

CMy2Dlg::CMy2Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMy2Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMy2Dlg)
	m_edit1 = _T("");
	m_edit1=_T("0123456789 :|-.AP");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMy2Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMy2Dlg)
	DDX_Text(pDX, IDC_EDIT1, m_edit1);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMy2Dlg, CDialog)
	//{{AFX_MSG_MAP(CMy2Dlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_TIMER()
	ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMy2Dlg message handlers

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

	// Add "About..." menu item to system menu.
m_timeico.set(this,10,60,30,0);
m_timeico.myfun("88888888");
m_shu.set(this,m_edit1.GetLength(),30,100,0);
m_shu.myfun(m_edit1);
SetTimer(1,1000,NULL);
	// 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
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMy2Dlg::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 CMy2Dlg::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 CMy2Dlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CMy2Dlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	if (1==nIDEvent)
	{//表
		static int flag=0;
		CTime curtime=CTime::GetCurrentTime();
		int Sec1=curtime.GetSecond();
		int Sec2=Sec1%10;
		Sec1/=10;
		int minu1=curtime.GetMinute();
		int minu2=minu1%10;
		minu1/=10;
		int hour1=curtime.GetHour();
		char aa='P';
		if (hour1<=12) aa='A';
		int hour2=hour1%10;
		hour1/=10;
		CString kk;
		
		if (0==flag) {
			kk.Format("%c%d%d|%d%d|%d%d",aa,hour1,hour2,minu1,minu2,Sec1,Sec2);
			flag=1;}
		else {
			kk.Format("%c%d%d|%d%d:%d%d",aa,hour1,hour2,minu1,minu2,Sec1,Sec2);
			flag=0;}
		m_timeico.myfun(kk);
	}	
	CDialog::OnTimer(nIDEvent);
}

void CMy2Dlg::OnChangeEdit1() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	// TODO: Add your control notification handler code here
	UpdateData(true);
	m_shu.set(this,m_edit1.GetLength(),30,100,0);
	m_shu.myfun(m_edit1);
	
}

mytime::~mytime()
{
	for(int i=0;i<num;i++)
	delete *(m_pictur+i);
}
mytime::mytime()
{
m_time=_T("");
num=0;
}
void mytime::set(CDialog *parent,int tnum,int tx,int ty,int tspace)
{
	CMy2Dlg *mypar=(CMy2Dlg*)parent;
	for(int i=0;i<num;i++)// 删除以前分配的
		delete *(m_pictur+i);
	// 设置各成员变量
	num=tnum; x=tx;y=ty;space=tspace;
	for(int j=0;j<num;j++)//重新分配
	  m_pictur[j]=new(CStatic);
	for(int k=0;k<num;k++)
	{
		//确定显示位置
		CRect aa1(x+k*(space+12),y,40+x+k*(space+12),40+y);
		m_pictur[k]->Create(NULL,SS_ICON,aa1,mypar,1);// 创建静态图标控件
		m_pictur[k]->ShowWindow(true);
	}
}
void mytime::myfun(CString temp)
{
	
	m_time=temp;
	int mynum=m_time.GetLength();
	
	for(int k=0;k<num-mynum;k++)//添加前面空图标显示
	{
		CImageList m_imgList;
		m_imgList.Create(IDB_BITMAP1,12, 1, RGB(255,255,255));//创建位图链 每个位图12像素
		HICON myico= m_imgList.ExtractIcon(10);	//取出图标
		m_pictur[k]->SetIcon(myico);//设置显示的图标		
	}
	for(int i=k;i<num;i++)//添加数字图标显示
	{
		CImageList m_imgList;
		m_imgList.Create(IDB_BITMAP1,12, 1, RGB(255,255,255));
		HICON myico= m_imgList.ExtractIcon(change(m_time[i-k]));	
		m_pictur[i]->SetIcon(myico);	
	}	
}
// 映射字符到数字
int mytime::change(char a)
{

	switch(a) 
	{
	case '0':
	case '1':
	case '2':
	case '3':
	case '4':
	case '5':
	case '6':
	case '7':
	case '8':
	case '9':return a-'0';
		break;
	case ' ':return 10;
		break;
	case 'A':return 11;
		break;
	case 'P':return 12;
		break;
	case '.':return 13;
		break;
	case '|':return 14;
		break;
	case ':':return 15;
		break;
	case '-':return 16;
		break;
	default: return 10;
	}
}

⌨️ 快捷键说明

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