// LCDDisplayDlg.cpp: 实现文件 // #include "pch.h" #include "framework.h" #include "LCDDisplayTest.h" #include "LCDDisplayTestDlg.h" #include "afxdialogex.h" #include "../MyLib/Functions.hpp" #ifdef _DEBUG #define new DEBUG_NEW #endif // 用于应用程序“关于”菜单项的 CAboutDlg 对话框 class CAboutDlg : public CDialogEx { public: CAboutDlg(); // 对话框数据 #ifdef AFX_DESIGN_TIME enum { IDD = IDD_ABOUTBOX }; #endif protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持 // 实现 protected: DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialogEx(IDD_ABOUTBOX) { } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx) END_MESSAGE_MAP() // CLCDDisplayTestDlg 对话框 CLCDDisplayTestDlg::CLCDDisplayTestDlg(CWnd* pParent /*=nullptr*/) : CDialogEx(IDD_LCDDISPLAY_DIALOG, pParent) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CLCDDisplayTestDlg::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); DDX_Control(pDX, IDC_STATIC_DISPLAY, m_lcd_display); DDX_Control(pDX, IDC_MFCCOLORBUTTON1, m_color_button1); DDX_Control(pDX, IDC_MFCCOLORBUTTON2, m_color_button2); } BEGIN_MESSAGE_MAP(CLCDDisplayTestDlg, CDialogEx) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_BUTTON1, &CLCDDisplayTestDlg::OnBnClickedButton1) ON_BN_CLICKED(IDC_BUTTON2, &CLCDDisplayTestDlg::OnBnClickedButton2) ON_BN_CLICKED(IDC_BUTTON3, &CLCDDisplayTestDlg::OnBnClickedButton3) ON_BN_CLICKED(IDC_BUTTON4, &CLCDDisplayTestDlg::OnBnClickedButton4) ON_BN_CLICKED(IDC_BUTTON5, &CLCDDisplayTestDlg::OnBnClickedButton5) ON_BN_CLICKED(IDC_BUTTON6, &CLCDDisplayTestDlg::OnBnClickedButton6) ON_BN_CLICKED(IDC_BUTTON_CONVERT, &CLCDDisplayTestDlg::OnBnClickedButtonConvert) ON_BN_CLICKED(IDC_BUTTON_CLEAR, &CLCDDisplayTestDlg::OnBnClickedButtonClear) ON_WM_TIMER() ON_BN_CLICKED(IDC_BUTTON7, &CLCDDisplayTestDlg::OnBnClickedButton7) ON_BN_CLICKED(IDC_BUTTON8, &CLCDDisplayTestDlg::OnBnClickedButton8) END_MESSAGE_MAP() // CLCDDisplayTestDlg 消息处理程序 BOOL CLCDDisplayTestDlg::OnInitDialog() { CDialogEx::OnInitDialog(); // 将“关于...”菜单项添加到系统菜单中。 // IDM_ABOUTBOX 必须在系统命令范围内。 ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX < 0xF000); CMenu* pSysMenu = GetSystemMenu(FALSE); if (pSysMenu != nullptr) { BOOL bNameValid; CString strAboutMenu; bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX); ASSERT(bNameValid); if (!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } } // 设置此对话框的图标。 当应用程序主窗口不是对话框时,框架将自动 // 执行此操作 SetIcon(m_hIcon, TRUE); // 设置大图标 SetIcon(m_hIcon, FALSE); // 设置小图标 // TODO: 在此添加额外的初始化代码 SetTimer(0, 20, NULL); SetTimer(1, 100, NULL); m_lcd_display.displayarray[1][2] = 1; return TRUE; // 除非将焦点设置到控件,否则返回 TRUE } void CLCDDisplayTestDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialogEx::OnSysCommand(nID, lParam); } } // 如果向对话框添加最小化按钮,则需要下面的代码 // 来绘制该图标。 对于使用文档/视图模型的 MFC 应用程序, // 这将由框架自动完成。 void CLCDDisplayTestDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // 用于绘制的设备上下文 SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); // 使图标在工作区矩形中居中 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; // 绘制图标 dc.DrawIcon(x, y, m_hIcon); } else { CDialogEx::OnPaint(); } } //当用户拖动最小化窗口时系统调用此函数取得光标 //显示。 HCURSOR CLCDDisplayTestDlg::OnQueryDragIcon() { return static_cast(m_hIcon); } void CLCDDisplayTestDlg::OnBnClickedButton1() { // TODO: 在此添加控件通知处理程序代码 m_lcd_display.Clear(); } char str1[] = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_"; unsigned int font3_5[128] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x007720,0x002770, // ▲▼ 0x000000,0x020222,0x000055,0x017574,0x036736,0x051245,0x053730,0x000122, // ! " # $ % & ' 0x021112,0x024442,0x052725,0x022722,0x012200,0x000700,0x020000,0x012244, // ( ) * + , - . / 0x075557,0x022222,0x071747,0x074747,0x044755,0x074717,0x075717,0x044557, // 0 1 2 3 4 5 6 7 0x075757,0x074757,0x002020,0x012020,0x042124,0x007070,0x012421,0x020452, // 8 9 : ; < = > ? 0x025752,0x055752,0x035353,0x071117,0x035553,0x071717,0x011717,0x075517, // @ A B C D E F G 0x055755,0x072227,0x032227,0x055355,0x071111,0x055575,0x055535,0x025552, // H I J K L M N O 0x011353,0x065552,0x055353,0x034216,0x022227,0x075555,0x025555,0x057555, // P Q R S T U V W 0x055255,0x022255,0x071247,0x071117,0x042211,0x074447,0x000052,0x070000, // X Y Z [ \ ] ^ _ 0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000, 0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000, 0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000, 0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000, }; unsigned long long font5_7[128] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000, // ▲▼ 0x000000000000,0x00400410e384,0x00000000a6db,0x00015f29f500, // ! " # 0x0043d4385784,0x0186421084c3,0x016255085080,0x00000000430c, // $ % & ' 0x004081041084,0x004210410204,0x0112847c4291,0x0001047c4100, // ( ) * + 0x00230c000000,0x0000007c0000,0x00c300000000,0x000042108400, // , - . / // , 0x00e45355944e,0x00e104104184,0x01f08421044e,0x00e45039044e, // 0 1 2 3 0x01e21f24a308,0x00e45040f05f,0x00e4513c108c,0x00410410841f, // 4 5 6 7 0x00e45139144e,0x00e41079144e,0x00030c00c300,0x00330c00c300, // 8 9 : ; 0x008102042108,0x00001f01f000,0x002108408102,0x00400421044e, // < = > ? 0x01e04d55544e,0x01145f451284,0x00f4513d144f,0x00e44104144e, // @ A B C 0x00f45145144f,0x01f0413c105f,0x0010413c105f,0x00e45174144e, // D E F G 0x0114517d1451,0x00e10410410e,0x00614410410e,0x0112450c5251, // H I J K 0x01f041041041,0x0114555556d1,0x011459553451,0x00e45145144e, // L M N O 0x0010413d144f,0x01625545144e,0x0112453d144f,0x00e45038144e, // P Q R S 0x00410410411f,0x00e451451451,0x004291451451,0x00a555551451, // T U V W 0x01144a10a451,0x00410410a451,0x01f04210841f,0x00e08208208e, // X Y Z [ 0x000408102040,0x00e20820820e,0x000000011284,0x01f000000000, // \ ] ^ _ 0x000000204082,0x00058924e000,0x0003d144f041,0x00038104e000, // ` a b c 0x00079145e410,0x0003817d1380,0x00208208f08c,0x00620e249380, // d e f g 0x000249247041,0x000384106004,0x00614410e004,0x0002450c5241, // h i j k 0x000382082082,0x000451555280,0x0002492491c0,0x000391451380, // l m n o 0x0010472491c0,0x00820e249380,0x000082092340,0x000390302700, // p q r s 0x00070411e100,0x000389249000,0x000085249000,0x000295551000, // t u v w 0x00024a1c9000,0x00620e28a000,0x0003c210f000,0x008104084108, // x y z { 0x004104004104,0x002104204102,0x000000000352,0x000000000000, // | } ~ }; char str2[] = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; void CLCDDisplayTestDlg::OnBnClickedButton2() { // TODO: 在此添加控件通知处理程序代码 //m_lcd_display.displayarray[3][4] = 1; //5*3 (6*4) m_lcd_display.Clear(); int l = strlen(str1); for (int i = 0; i < 10; i++) { for (int j = 0; j < 32; j++) { int index = (i * 32 + j) % l; char ch = str1[index]; int dots = font3_5[ch]; for (int m = 0; m < 5; m++) { int line = dots & 0xf; int mask = 1; for (int n = 0; n < 3; n++) { if (line&mask) { m_lcd_display.displayarray[i * 6 + m][j * 4 + n] = 1; } mask <<= 1; } dots >>= 4; } } } m_lcd_display.RedrawWindow(); } void CLCDDisplayTestDlg::OnBnClickedButton3() { // TODO: 在此添加控件通知处理程序代码 //7*5 (8*6) m_lcd_display.Clear(); int l = strlen(str2); for (int i = 0; i < 8; i++) { for (int j = 0; j < 21; j++) { int index = (i * 21 + j) % l; char ch = str2[index]; long long dots = font5_7[ch]; for (int m = 0; m < 7; m++) { int line = dots & 0x3f; int mask = 1; for (int n = 0; n < 5; n++) { if (line&mask) { m_lcd_display.displayarray[i * 8 + m][j * 6 + n] = 1; } mask <<= 1; } dots >>= 6; } } } m_lcd_display.RedrawWindow(); } void CLCDDisplayTestDlg::OnBnClickedButton4() { // TODO: 在此添加控件通知处理程序代码 //12*7 (13*8) m_lcd_display.Clear(); for (int i = 0; i < 5; i++) { for (int j = 0; j < 16; j++) { for (int m = 0; m < 12; m++) { for (int n = 0; n < 7; n++) { m_lcd_display.displayarray[i * 13 + m][j * 8 + n] = 1; } } } } m_lcd_display.RedrawWindow(); } void CLCDDisplayTestDlg::OnBnClickedButton5() { // TODO: 在此添加控件通知处理程序代码 //15*7 (16*8) m_lcd_display.Clear(); for (int i = 0; i < 4; i++) { for (int j = 0; j < 16; j++) { for (int m = 0; m < 15; m++) { for (int n = 0; n < 7; n++) { m_lcd_display.displayarray[i * 16 + m][j * 8 + n] = 1; } } } } m_lcd_display.RedrawWindow(); } void CLCDDisplayTestDlg::OnBnClickedButton6() { char aa[] = "12"; m_lcd_display.SetTextMode(LCDDisplay1::TextMode5_7); m_lcd_display.putText(aa); m_lcd_display.putText(str2); m_lcd_display.RedrawWindow(); // TODO: 在此添加控件通知处理程序代码 } DWORD dlgitemIDs[48] = { IDC_CHECK1,IDC_CHECK2,IDC_CHECK3,IDC_CHECK4,IDC_CHECK5,IDC_CHECK6, IDC_CHECK7,IDC_CHECK8,IDC_CHECK9,IDC_CHECK10,IDC_CHECK11,IDC_CHECK12, IDC_CHECK13,IDC_CHECK14,IDC_CHECK15,IDC_CHECK16,IDC_CHECK17,IDC_CHECK18, IDC_CHECK19,IDC_CHECK20,IDC_CHECK21,IDC_CHECK22,IDC_CHECK23,IDC_CHECK24, IDC_CHECK25,IDC_CHECK26,IDC_CHECK27,IDC_CHECK28,IDC_CHECK29,IDC_CHECK30, IDC_CHECK31,IDC_CHECK32,IDC_CHECK33,IDC_CHECK34,IDC_CHECK35,IDC_CHECK36, IDC_CHECK37,IDC_CHECK38,IDC_CHECK39,IDC_CHECK40,IDC_CHECK41,IDC_CHECK42, IDC_CHECK43,IDC_CHECK44,IDC_CHECK45,IDC_CHECK46,IDC_CHECK47,IDC_CHECK48 }; static int xtoi(const char * hexstr, int len) { int len1 = len; if (len <= 0) len1 = (int)strlen(hexstr); int j = 0; for (int i = 0; i < len1; i++) { unsigned char ch = hexstr[i]; if (ch >= '0'&&ch <= '9') { int k = ch - '0'; j = j * 16 + k; continue; } if (ch >= 'A'&&ch <= 'F') { int k = ch - 'A' + 10; j = j * 16 + k; continue; } if (ch >= 'a'&&ch <= 'f') { int k = ch - 'a' + 10; j = j * 16 + k; continue; } if (ch == ' ' || ch == ' ') { continue; } break; } return j; } static unsigned char reversebyte(unsigned char b) { b = (b & 0xF0) >> 4 | (b & 0x0F) << 4; b = (b & 0xCC) >> 2 | (b & 0x33) << 2; b = (b & 0xAA) >> 1 | (b & 0x55) << 1; return b; } void CLCDDisplayTestDlg::OnBnClickedButtonConvert() { // TODO: 在此添加控件通知处理程序代码 long long fontdots = 0; unsigned char dots[48]; for (int i = 0; i < 48; i++) { fontdots <<= 1; dots[i]= ((CButton *)GetDlgItem(dlgitemIDs[47-i]))->GetCheck(); if (dots[i]) fontdots|= 1; } CString s1; s1.Format(_T("0x%04x%08x"), fontdots>>32, fontdots); GetDlgItem(IDC_EDIT_HEX)->SetWindowText(s1); } void CLCDDisplayTestDlg::OnBnClickedButtonClear() { // TODO: 在此添加控件通知处理程序代码 for (int i = 0; i < 48; i++) { ((CButton *)GetDlgItem(dlgitemIDs[i]))->SetCheck(0); } } void CLCDDisplayTestDlg::OnTimer(UINT_PTR nIDEvent) { // TODO: 在此添加消息处理程序代码和/或调用默认值 if (nIDEvent == 0) { KillTimer(0); DelayInit(); } else if (nIDEvent == 1) { UpdateDisplay(); } else { } CDialogEx::OnTimer(nIDEvent); } int CLCDDisplayTestDlg::DelayInit() { // TODO: 在此处添加实现代码. return 0; } char str3[] = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ "; char str4[] = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~_"; int CLCDDisplayTestDlg::UpdateDisplay() { // TODO: 在此处添加实现代码. static int nCount = 0; CStringA sa; CStringA sb; CTime time1; time1 = time1.GetTickCount(); int hour=0, min=0, sec=0; hour=time1.GetHour(), min=time1.GetMinute(), sec=time1.GetSecond(); char aa[] = "12"; char bb[] = " "; // m_lcd_display.Clear(false); // m_lcd_display.SetTextMode(LCDDisplay1::TextMode5_7); nCount += 1; static int lastsec = 0; if (sec != lastsec) { sa.Format("%02d:%02d:%02d", hour,min,sec); m_lcd_display.putTextXY(13,4, sa); // m_lcd_display.putText(str3); m_lcd_display.RedrawWindow(); lastsec = sec; } return 0; } void CLCDDisplayTestDlg::OnBnClickedButton7() { // TODO: 在此添加控件通知处理程序代码 CString s1,s2; GetDlgItemText(IDC_EDIT3, s1); CStringA s1A; s1A = s1; CStringA resstrs[100]; int j = Split(s1A, " ", resstrs); s1.Empty(); for (int i = 0; i < j; i++) { int k = xtoi(resstrs[i], 2); k = reversebyte(k); s1.AppendFormat(_T("%02x "), k); } s2 = s1; SetDlgItemText(IDC_EDIT4, s2); } void CLCDDisplayTestDlg::OnBnClickedButton8() { // TODO: 在此添加控件通知处理程序代码 COLORREF bkcolor, fntcolor; bkcolor=m_color_button1.GetColor(); fntcolor = m_color_button2.GetColor(); m_lcd_display.SetBkColor(bkcolor); m_lcd_display.SetFontColor(fntcolor); }