📄 cleddlg.cpp
字号:
// CLedDlg.cpp : implementation file
//
#include "stdafx.h"
#include "CLed.h"
#include "CLedDlg.h"
#include <conio.h>
#include <stdio.h>
#include <math.h>
#include "led.h"
#include <time.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)
virtual BOOL OnInitDialog();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// m_Note.Insert(0,"Maxim7221数码管驱动程序 测试版,采用VC++6.0开发。");
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCLedDlg dialog
CCLedDlg::CCLedDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCLedDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCLedDlg)
m_NumInput = 0.0;
//}}AFX_DATA_INIT
Is_ShutDown=false;
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CCLedDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCLedDlg)
DDX_Text(pDX, IDC_NUMINPUT, m_NumInput);
DDV_MinMaxDouble(pDX, m_NumInput, 0.000, 100000.000);
DDX_Control(pDX, IDC_DISLED, m_DisLed);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCLedDlg, CDialog)
//{{AFX_MSG_MAP(CCLedDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_TEST, OnTest)
ON_BN_CLICKED(IDC_SHUTDOWN, OnShutdown)
ON_BN_CLICKED(IDC_ABOUT, OnAbout)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCLedDlg message handlers
BOOL CCLedDlg::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
bool bResult = InitializeWinIo();
//设置成红色的颜色
COLORREF BkColor=RGB(0,0,0);
COLORREF REDColor=RGB(255,0,0);
m_DisLed.SetColor(BkColor,REDColor);
return TRUE; // return TRUE unless you set the focus to a control
}
void CCLedDlg::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 CCLedDlg::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();
}
led.Init();
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CCLedDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
BOOL CCLedDlg::DestroyWindow()
{
ShutdownWinIo();
return CDialog::DestroyWindow();
}
void CCLedDlg::Display()
{
/**/
UpdateData(true);
double a,b;
a=modf(m_NumInput,&b);
a*=1000;
led.DisplayNum(m_NumInput);
m_DisLed.Format("%05d.%03d",(int)b,(int)a);
/*
time_t start, finish;
double result, elapsed_time;
time( &start );
CString abc;
for(double i=0;i<100000;i+=1)
{
double a,b;
a=modf(i,&b);
a*=1000;
m_DisLed.Format("%05d.%03d",(int)b,(int)a);
UpdateWindow();
led.DisplayNum(i);
}
time( &finish );
elapsed_time = difftime( finish, start );
abc.Format("运行了 %6.0f 秒", elapsed_time );
//统计结果1000000次用了1029s、1031s,在取消屏幕显示的前提下。
//没有取消屏幕显示,用了1374s
//基本上是1ms能够刷新一次(8位数据)。
AfxMessageBox(abc);
*/
}
void CCLedDlg::OnOK()
{
Display();
/*
short ab=0xffff;
for(int i=0;i<16;i++)
{
ab<<=1;
CString dd;
dd.Format("%X",ab);
AfxMessageBox(dd);
}
*/
}
void CCLedDlg::OnTest()
{
unsigned char TEST_MODE0[]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0};
unsigned char TEST_MODE1[]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
led.SendData(TEST_MODE1);
Sleep(1000);
led.SendData(TEST_MODE0);
}
void CCLedDlg::OnShutdown()
{
unsigned char ShutDown0[]={0,0,0,0,1,1,0,0,1,1,1,1,1,1,1,0};
unsigned char ShutDown1[]={0,0,0,0,1,1,0,0,1,1,1,1,1,1,1,1};
Is_ShutDown = !Is_ShutDown;
if(Is_ShutDown == FALSE)
{
led.Init();
SetDlgItemText(IDC_SHUTDOWN,_T("关断"));
}
else
{
SetDlgItemText(IDC_SHUTDOWN,_T("启动"));
led.SendData(ShutDown1);
led.SendData(ShutDown0);
}
}
void CCLedDlg::OnAbout()
{
CAboutDlg dlg;
dlg.DoModal();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -