?? ledscreedlg.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)
}
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
//設(shè)置列表視圖擴(kuò)展風(fēng)格
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,"顯示標(biāo)識",LVCFMT_CENTER,219);
m_textcolor=RGB(0,0,0); //初始化顏色值為黑色
m_spin1.SetBuddy(GetDlgItem(IDC_EDIT2)); //設(shè)置停留時間編輯控件為Spin控件的伙伴窗口
m_spin1.SetRange(0,15); //設(shè)置停留時間數(shù)據(jù)范圍為1-255
m_text_style.SetCurSel(0); //設(shè)置文本信息為文本類型的默認(rèn)選項
m_show_style.SetCurSel(0); //設(shè)置快速打出為文本類型的默認(rèn)選項
//串口設(shè)置
m_Comm.SetCommPort(1); //選擇COM1
m_Comm.SetInputMode(1); //輸入方式為二進(jìn)制方式
m_Comm.SetInBufferSize(1024); //設(shè)置輸入緩沖區(qū)大小,單位Byte
m_Comm.SetOutBufferSize(1024); //設(shè)置輸出緩沖區(qū)大小,單位Byte
m_Comm.SetSettings("9600, n, 8, 1"); //波特率9600,無校驗,8個數(shù)據(jù)位,1個停止位
if(!m_Comm.GetPortOpen()) //打開串口
m_Comm.SetPortOpen(TRUE);
m_Comm.SetRThreshold(1); //表示有一個字符引發(fā)一個事件
m_Comm.SetInputLen(0); //設(shè)置當(dāng)前接收區(qū)數(shù)據(jù)長度為0
m_Comm.GetInput(); //先預(yù)讀緩沖區(qū)以清除殘留數(shù)據(jù) */
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(); //獲取編輯框當(dāng)前字體
LOGFONT logfont;
tempfont->GetLogFont(&logfont);
CFontDialog fontdlg(&logfont); //初始化字體信息
if(fontdlg.DoModal()==IDOK)
{
m_font.Detach();
LOGFONT temp;
fontdlg.GetCurrentFont(&temp); //獲取當(dāng)前字體信息
m_font.CreateFontIndirect(&temp); //直接創(chuàng)建字體
m_edit.SetFont(&m_font); //設(shè)置字體
}
}
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); //創(chuàng)建顏色對話框
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(); //獲取文本信息組合框當(dāng)前項目索引
int x=m_show_style.GetCurSel(); //獲取顯示方式組合框當(dāng)前項目索引
CString strID; //strID為文本信息組合框字符串
CString show; //show為顯示方式組合框當(dāng)字符串
pWnd->GetWindowText(strValue); //得到編輯框中的內(nèi)容
if(strValue.IsEmpty())
MessageBox("請輸入文本內(nèi)容","提示",MB_ICONINFORMATION);
else
{
m_text_style.GetLBText(n,strID); //獲取文本信息組合框當(dāng)前項字符串
m_show_style.GetLBText(x,show); //獲取顯示方式組合框當(dāng)前項字符串
m_list.InsertItem(0,strID); //文本信息組合框內(nèi)容寫入文本信息區(qū)
m_list.SetItemText(0,2,show); //顯示方式組合框內(nèi)容寫入文本信息區(qū)
m_list.SetItemText(0,3,strValue); //編輯框內(nèi)容寫入文本信息區(qū)
SetDlgItemText(IDC_EDIT1,""); //清除編輯框內(nèi)容
}
}
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(); //返回值表示串口發(fā)生的事件
switch(nEvent)
{
case 2: //事件值為2,表示接收緩沖區(qū)內(nèi)有字符
vResponse=m_Comm.GetInput(); //讀緩沖區(qū)
safearray_inp=vResponse; //VARIANT型變量轉(zhuǎn)換為ColeSafeArray型變量
len=safearray_inp.GetOneDimSize(); //得到有效數(shù)據(jù)長度
for(k=0;k<len;k++)
safearray_inp.GetElement(&k,rxdata+k); //轉(zhuǎn)換為BYTE型數(shù)組
frame_start=*(char*)(rxdata+0);
// if(frame_start==255)
// {
for(k=0;k<len;k++) //將數(shù)組轉(zhuǎn)換為CString型變量
{
BYTE bt=*(char*)(rxdata+k); //字符型
strtemp.Format("%02x",bt); //將字符以十六進(jìn)制方式送入臨時變量strtemp存放
receive+=strtemp;
}
length=receive.GetLength();
// }
// else
// {
// receive.Empty();
// }
strtemp.Empty(); //清空strtemp;
m_Comm.SetInBufferCount(0); //清空接收緩沖區(qū)
UpdateData(FALSE);
break;
case 3: //CTS線狀態(tài)發(fā)生了變化
break;
case 4: //DSR線狀態(tài)發(fā)生了變化
break;
case 5: //CD線狀態(tài)發(fā)生了變化
break;
case 6: //Ring Indicator發(fā)生了變化
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); //讀取列表框中要發(fā)送的數(shù)據(jù),存儲在str中
int Len=str.GetLength(); //發(fā)送內(nèi)容的長度
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); //發(fā)送55FF0000
Sleep(1000); //延時1s
length=receive.GetLength();
if(length!=0)
{
if(strcmp(receive,sucess)==0)
MessageBox("發(fā)送成功!","提示",MB_ICONINFORMATION);
else if(strcmp(receive,error1)==0)
MessageBox("前導(dǎo)碼錯誤,請重新發(fā)送!","提示",MB_ICONINFORMATION);
else if(strcmp(receive,error2)==0)
MessageBox("屏號錯誤,請重新發(fā)送!","提示",MB_ICONINFORMATION);
else if(strcmp(receive,error3)==0)
MessageBox("校驗錯誤,請重新發(fā)送!","提示",MB_ICONINFORMATION);
else
MessageBox("發(fā)送錯誤!","提示",MB_ICONINFORMATION);
}
else
MessageBox("通訊失敗!","提示",MB_ICONINFORMATION);
//漢字內(nèi)碼提取
for(int i=0;i<Len;i++)
{
ch=(TBYTE)str[i];
senddata.Add(ch);
}
m_Comm.SetOutput(COleVariant(senddata)); //發(fā)送數(shù)據(jù)
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -