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

📄 ledscreedlg.cpp

📁 闹钟程序很好的啊
💻 CPP
字号:
// LEDSCREEDlg.cpp : implementation file
//

#include "stdafx.h"
#include "LEDSCREE.h"
#include "LEDSCREEDlg.h"
#include "PASSWORD.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()

/////////////////////////////////////////////////////////////////////////////
// CLEDSCREEDlg dialog

CLEDSCREEDlg::CLEDSCREEDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CLEDSCREEDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CLEDSCREEDlg)
	m_edit2 = 0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CLEDSCREEDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CLEDSCREEDlg)
	DDX_Control(pDX, IDC_SHOW, m_show_style);
	DDX_Control(pDX, IDC_TEXT_STYLE, m_text_style);
	DDX_Control(pDX, IDC_SPIN1, m_spin1);
	DDX_Control(pDX, IDC_LIST3, m_list3);
	DDX_Control(pDX, IDC_LIST2, m_list2);
	DDX_Control(pDX, IDC_EDIT1, m_edit);
	DDX_Control(pDX, IDC_LIST1, m_list);
	DDX_Text(pDX, IDC_EDIT2, m_edit2);
	DDV_MinMaxInt(pDX, m_edit2, 0, 15);
	DDX_Control(pDX, IDC_MSCOMM1, m_Comm);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CLEDSCREEDlg, CDialog)
	//{{AFX_MSG_MAP(CLEDSCREEDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_STYLE, OnStyle)
	ON_BN_CLICKED(IDC_COLOR, OnColor)
	ON_WM_CTLCOLOR()
	ON_BN_CLICKED(IDC_SET_PARAMETER, OnSetParameter)
	ON_NOTIFY(UDN_DELTAPOS, IDC_SPIN1, OnDeltaposSpin1)
	ON_BN_CLICKED(IDC_ENTER, OnEnter)
	ON_BN_CLICKED(IDC_DELTEXT, OnDeltext)
	ON_BN_CLICKED(IDC_CREATE_TEXT, OnCreateText)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLEDSCREEDlg message handlers

BOOL CLEDSCREEDlg::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
	
	// TODO: Add extra initialization here
	
	//设置列表视图扩展风格
	m_list.SetExtendedStyle(LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_ONECLICKACTIVATE);
	m_list2.SetExtendedStyle(LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_ONECLICKACTIVATE);
	m_list3.SetExtendedStyle(LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_ONECLICKACTIVATE);

	//向列表视图中添加列
	m_list.InsertColumn(0,"信息类型",LVCFMT_CENTER,70);
	m_list.InsertColumn(1,"幕号",LVCFMT_CENTER,80);
	m_list.InsertColumn(2,"显示方式",LVCFMT_CENTER,170);
	m_list.InsertColumn(3,"文本信息",LVCFMT_CENTER,292);

	m_list2.InsertColumn(0,"信息类型",LVCFMT_CENTER,70);
	m_list2.InsertColumn(1,"幕号",LVCFMT_CENTER,80);
	m_list2.InsertColumn(2,"显示方式",LVCFMT_CENTER,170);
	m_list2.InsertColumn(3,"图形路径",LVCFMT_CENTER,292);

	m_list3.InsertColumn(1,"显示顺讯",LVCFMT_CENTER,219);
	m_list3.InsertColumn(2,"显示标识",LVCFMT_CENTER,219);
   
	m_textcolor=RGB(0,0,0);								//初始化颜色值为黑色

	m_spin1.SetBuddy(GetDlgItem(IDC_EDIT2));			//设置停留时间编辑控件为Spin控件的伙伴窗口
	m_spin1.SetRange(0,15);								//设置停留时间数据范围为1-255

	m_text_style.SetCurSel(0);							//设置文本信息为文本类型的默认选项
	m_show_style.SetCurSel(0);							//设置快速打出为文本类型的默认选项
	
	
	
	//串口设置
	m_Comm.SetCommPort(1);							//选择COM1
	m_Comm.SetInputMode(1);							//输入方式为二进制方式
	m_Comm.SetInBufferSize(1024);					//设置输入缓冲区大小,单位Byte
	m_Comm.SetOutBufferSize(1024);					//设置输出缓冲区大小,单位Byte
	m_Comm.SetSettings("9600, n, 8, 1");			//波特率9600,无校验,8个数据位,1个停止位
	if(!m_Comm.GetPortOpen())						//打开串口
		m_Comm.SetPortOpen(TRUE);
	m_Comm.SetRThreshold(1);						//表示有一个字符引发一个事件
	m_Comm.SetInputLen(0);							//设置当前接收区数据长度为0
	m_Comm.GetInput();								//先预读缓冲区以清除残留数据      */

	return TRUE;  // return TRUE  unless you set the focus to a control
}

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

BEGIN_EVENTSINK_MAP(CLEDSCREEDlg, CDialog)
    //{{AFX_EVENTSINK_MAP(CLEDSCREEDlg)
	ON_EVENT(CLEDSCREEDlg, IDC_MSCOMM1, 1 /* OnComm */, OnOnCommMscomm1, VTS_NONE)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()



void CLEDSCREEDlg::OnStyle() 
{
	// TODO: Add your control notification handler code here
	CFont* tempfont=m_edit.GetFont();				      //获取编辑框当前字体
	LOGFONT logfont;
	tempfont->GetLogFont(&logfont);			
	CFontDialog fontdlg(&logfont);					      //初始化字体信息
	if(fontdlg.DoModal()==IDOK)
	{
		m_font.Detach();
		LOGFONT temp;
		fontdlg.GetCurrentFont(&temp);					  //获取当前字体信息
		m_font.CreateFontIndirect(&temp);				  //直接创建字体
		m_edit.SetFont(&m_font);						  //设置字体
	}

}

HBRUSH CLEDSCREEDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	
	// TODO: Change any attributes of the DC here
	
	// TODO: Return a different brush if the default is not desired
	if(nCtlColor==CTLCOLOR_EDIT)
	
		pDC->SetTextColor(m_textcolor);
	
	return hbr;
}

void CLEDSCREEDlg::OnColor() 
{
	// TODO: Add your control notification handler code here
    CColorDialog ColorDlg(m_textcolor);						//创建颜色对话框
	if(ColorDlg.DoModal()==IDOK)
	{
		m_textcolor=ColorDlg.GetColor();					//获取用户选择的颜色
		Invalidate();										//重绘窗口

	}
}



void CLEDSCREEDlg::OnSetParameter() 
{
	// TODO: Add your control notification handler code here
	CPASSWORD PASSWORDDlg;
	int Res;
	Res=PASSWORDDlg.DoModal();
}

void CLEDSCREEDlg::OnDeltaposSpin1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
	// TODO: Add your control notification handler code here

	if(pNMUpDown->iDelta>0)									//如果点击的是Spin中的往上按钮
	{
		m_edit2-=1;	
	}
	else													//如果点击的是spin中往下按钮
	{
		m_edit2+=1;
	}

	UpdateData(FALSE);
	*pResult = 0;
}



void CLEDSCREEDlg::OnEnter() 
{
	// TODO: Add your control notification handler code here
	UpdateData(true);
	CWnd* pWnd=(CWnd*)GetDlgItem(IDC_EDIT1);					//得到指向编辑框的窗口指针
	CString strValue;
	int n=m_text_style.GetCurSel();								//获取文本信息组合框当前项目索引
	int x=m_show_style.GetCurSel();								//获取显示方式组合框当前项目索引
	CString strID;												//strID为文本信息组合框字符串
	CString show;												//show为显示方式组合框当字符串
	
	pWnd->GetWindowText(strValue);								//得到编辑框中的内容

	if(strValue.IsEmpty())
		MessageBox("请输入文本内容","提示",MB_ICONINFORMATION);
	else
	{
		m_text_style.GetLBText(n,strID);							//获取文本信息组合框当前项字符串
		m_show_style.GetLBText(x,show);								//获取显示方式组合框当前项字符串
		m_list.InsertItem(0,strID);									//文本信息组合框内容写入文本信息区
		m_list.SetItemText(0,2,show);								//显示方式组合框内容写入文本信息区
		m_list.SetItemText(0,3,strValue);							//编辑框内容写入文本信息区
		SetDlgItemText(IDC_EDIT1,"");								//清除编辑框内容
	}

}

void CLEDSCREEDlg::OnDeltext() 
{
	// TODO: Add your control notification handler code here

	int m_nIndex;
	POSITION pos = m_list.GetFirstSelectedItemPosition();
	m_nIndex = m_list.GetNextSelectedItem(pos);					// 得到项目索引
	
	if(m_nIndex==-1)
	{
		MessageBox("请选择一项再删除!","提示",MB_ICONINFORMATION);
		 return;
	}
	m_list.DeleteItem(m_nIndex); 
 
	UINT flag = LVIS_SELECTED|LVIS_FOCUSED;
	m_list.SetItemState(m_nIndex-1, flag, flag);
 	
}



void CLEDSCREEDlg::OnOnCommMscomm1() 
{
	// TODO: Add your control notification handler code here
	VARIANT vResponse;
	int nEvent,length;	
	COleSafeArray safearray_inp;
	LONG len,k;
	BYTE rxdata[2048];
	BYTE frame_start;
	CString strtemp;
	

	nEvent=m_Comm.GetCommEvent();						//返回值表示串口发生的事件
	
	switch(nEvent)
	{
	case 2:												//事件值为2,表示接收缓冲区内有字符
		
			vResponse=m_Comm.GetInput();				//读缓冲区
			safearray_inp=vResponse;					//VARIANT型变量转换为ColeSafeArray型变量
			len=safearray_inp.GetOneDimSize();			//得到有效数据长度
			for(k=0;k<len;k++)
				safearray_inp.GetElement(&k,rxdata+k);	//转换为BYTE型数组
			frame_start=*(char*)(rxdata+0);
//			if(frame_start==255)
//			{
				for(k=0;k<len;k++)							//将数组转换为CString型变量
				{
					BYTE bt=*(char*)(rxdata+k);				//字符型
					strtemp.Format("%02x",bt);				//将字符以十六进制方式送入临时变量strtemp存放
					receive+=strtemp;
				}
				length=receive.GetLength();
//			}
//			else
//			{
//				receive.Empty();
//			}

		strtemp.Empty();								//清空strtemp;
		m_Comm.SetInBufferCount(0);						//清空接收缓冲区
		UpdateData(FALSE);
		break;
		
	case 3:					//CTS线状态发生了变化
		break;
	case 4:					//DSR线状态发生了变化
		break;
	case 5:					//CD线状态发生了变化
		break;
	case 6:					//Ring Indicator发生了变化
		break;
	}
//	UpdateData(FALSE);

}


void CLEDSCREEDlg::OnCreateText() 
{
	// TODO: Add your control notification handler code here
	UpdateData(true);
	CString str;
	CByteArray YSend,senddata;
	int m_nIndex,length;
	TBYTE ch;
	CString m_strQuwei;
	POSITION pos = m_list.GetFirstSelectedItemPosition();
	m_nIndex = m_list.GetNextSelectedItem(pos);					// 得到项目索引
 
	if(m_nIndex==-1)
	{
		MessageBox("请选择一项生成文本!","提示",MB_ICONINFORMATION);
		 return;
	}
	str=m_list.GetItemText(m_nIndex,3);							//读取列表框中要发送的数据,存储在str中	
	int Len=str.GetLength();										//发送内容的长度
	

	CString sucess,error1,error2,error3;
	sucess="ff0455";
	error1="ff0155";
	error2="ff0255";
	error3="ff0355";
	unsigned char chData[4];
	chData[0]=0x55;
	chData[1]=0xFF;
	chData[2]=0x00;
	chData[3]=0x00;

	YSend.RemoveAll();
	for(int j=0;j<4;j++)
		YSend.Add(chData[j]);
	COleVariant var(YSend);
	m_Comm.SetOutput(var);							//发送55FF0000

	Sleep(1000);									//延时1s


	length=receive.GetLength();

	if(length!=0)
	{

		if(strcmp(receive,sucess)==0)
			MessageBox("发送成功!","提示",MB_ICONINFORMATION);
		else if(strcmp(receive,error1)==0)
			MessageBox("前导码错误,请重新发送!","提示",MB_ICONINFORMATION);
		else if(strcmp(receive,error2)==0)
			MessageBox("屏号错误,请重新发送!","提示",MB_ICONINFORMATION);
		else if(strcmp(receive,error3)==0)
			MessageBox("校验错误,请重新发送!","提示",MB_ICONINFORMATION);
		else
			MessageBox("发送错误!","提示",MB_ICONINFORMATION);	
	}
	else
		MessageBox("通讯失败!","提示",MB_ICONINFORMATION);



	
		//汉字内码提取
	for(int i=0;i<Len;i++)
	{
		ch=(TBYTE)str[i];		
		senddata.Add(ch);
	}
		
		m_Comm.SetOutput(COleVariant(senddata));				//发送数据

}

⌨️ 快捷键说明

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