?? 429testdlg.cpp
字號:
// 429testDlg.cpp : implementation file
//
#include "stdafx.h"
#include "429test.h"
#include "429testDlg.h"
#include "resource.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMy429testDlg dialog
CMy429testDlg::CMy429testDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMy429testDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMy429testDlg)
m_send = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMy429testDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMy429testDlg)
DDX_Control(pDX, IDC_LIST2, m_list2);
DDX_Control(pDX, IDC_LIST1, m_list1);
DDX_Control(pDX, IDC_PROGRESS1, prg);
DDX_Control(pDX, IDC_RADIO1, m_radioSpdH);
DDX_Control(pDX, IDC_RADIO2, m_radioSpdL);
DDX_Text(pDX, IDC_EDIT_SEND, m_send);
DDV_MaxChars(pDX, m_send, 8);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMy429testDlg, CDialog)
ON_WM_CONTEXTMENU()
//{{AFX_MSG_MAP(CMy429testDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnOpen)
ON_BN_CLICKED(IDOK, OnExit)
ON_BN_CLICKED(IDC_SEND, OnSend)
ON_BN_CLICKED(IDC_RECEIVE, OnReceive1)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BUTTON2, OnSave)
ON_WM_DESTROY()
ON_COMMAND(ID_CLOSEWINDOW, OnClosewindow)
ON_COMMAND(ID_CLOSE, OnClose)
ON_BN_CLICKED(IDC_OPEN_FILE, OnOpenFile)
ON_EN_MAXTEXT(IDC_EDIT_SEND, OnMaxtextEditSend)
ON_BN_CLICKED(IDC_CLEAR, OnClear)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_BN_CLICKED(IDC_BUTTON5, OnChangeRate)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMy429testDlg message handlers
BOOL CMy429testDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
m_radioSpdH.SetCheck(1);
CMenu* pMenu;
pMenu=GetMenu();
pMenu->CheckMenuItem(ID_CLOSEWINDOW,MF_CHECKED);
pMenu->CheckMenuItem(ID_COPY,MF_CHECKED);
return TRUE; // return TRUE unless you set the focus to a control
}
// 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 CMy429testDlg::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 CMy429testDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMy429testDlg::OnOpen()
{
if(!DeviceOpen())
CDialog::OnOK();
//AfxMessageBox(,MB_OK);
SetDlgItemText(IDC_STATIC_STATUS1,"設備打開成功!");
WriteByte(0x234,0x0);
WriteWord(0x23c,0x0020);
WriteByte(0x329,0x0);
WriteByte(0x235,0x0);
WriteByte(0x325,0x0);
CString str;
str.Format("%x",ReadByte(0x23e));
SetDlgItemText(IDC_STATIC_STATUS,str);
}
void CMy429testDlg::OnExit()
{
DeviceClose();
CDialog::OnOK();
}
void CMy429testDlg::OnSend()
{
UpdateData(TRUE);
if(m_send.GetLength()<8)
AfxMessageBox("要發送的數據個數小于8,請填滿后再進行發送!");
else{
unsigned short data1,data2;
//if(m_radioSpdH.GetCheck()==1) AfxMessageBox("您選擇了100Kbps的發送速率!");
//if(m_radioSpdL.GetCheck()==1) AfxMessageBox("您選擇了12.5Kbps的發送速率!");
sscanf(m_send.Left(4),"%x",&data1);
sscanf(m_send.Right(4),"%x",&data2);
WriteWord(0x238,data1);
WriteWord(0x23a,data2);
CString str;
str.Format("%x",ReadByte(0x23e));
SetDlgItemText(IDC_STATIC_STATUS,str);
}
//nPos=0;
//SetTimer(1,100,NULL);
//發送data1和data2
}
void CMy429testDlg::OnReceive1()
{
CString str1,str2;
str1.Format("%x",ReadWord(0x230));
str2.Format("%x",ReadWord(0x232));
//m_channel1.Format("%x%x",readword(0x232),readword(0x230));
m_list1.AddString(str1+str2);//選中列表框的sort屬性,就會讓框中的字符串按字母順序排列
// str1.Format("%x",ReadWord(0x238));
// str2.Format("%x",ReadWord(0x23a));
//m_channel1.Format("%x%x",readword(0x232),readword(0x230));
// m_list2.AddString(str1+str2);//選中列表框的sort屬性,就會讓框中的字符串按字母順序排列
//m_list1.AddString("12345678");//添加字符串
//m_list1.InsertString(1,"hahaha");//在第一行插入字符串(0最小)
//m_list1.AddString("lhp");
//m_list1.AddString("111111");
//m_list1.AddString("222222");
//m_list1.AddString("dfdfd");
//m_list1.AddString("dfdfdf");
CString str;
str.Format("%x",ReadByte(0x23e));
SetDlgItemText(IDC_STATIC_STATUS,str);
SetDlgItemInt(IDC_STATIC_COUNT,m_list1.GetCount());//計算列表框中有多少個字符串
}
void CMy429testDlg::OnTimer(UINT nIDEvent)
{
prg.SetPos(nPos);
if(nPos<=100)
nPos++;
else
nPos=0;
CDialog::OnTimer(nIDEvent);
}
void CMy429testDlg::OnSave()
{
CStdioFile myfile;
if(!myfile.Open("hello.txt",CFile::modeReadWrite|CFile::modeNoTruncate|CFile::modeCreate))
AfxMessageBox("error");
myfile.WriteString(" 數據讀取記錄 \n");
myfile.SeekToEnd();
CString ss;
for(int i=0;i<m_list1.GetCount();i++)
{
m_list1.GetText(i,ss);
myfile.WriteString("\n"+ss);
}
myfile.Close();
}
void CMy429testDlg::OnDestroy()
{
CDialog::OnDestroy();
KillTimer(1);
}
void CMy429testDlg::OnClosewindow()
{
SendMessage(WM_CLOSE);
}
void CMy429testDlg::OnContextMenu(CWnd*, CPoint point)
{ // CG: This block was added by the Pop-up Menu component { if (point.x == -1 && point.y == -1){ //keystroke invocation CRect rect; GetClientRect(rect); ClientToScreen(rect); point = rect.TopLeft(); point.Offset(5, 5); } CMenu menu; VERIFY(menu.LoadMenu(CG_IDR_POPUP_MY429TEST_DLG)); CMenu* pPopup = menu.GetSubMenu(0); ASSERT(pPopup != NULL); CWnd* pWndPopupOwner = this; while (pWndPopupOwner->GetStyle() & WS_CHILD) pWndPopupOwner = pWndPopupOwner->GetParent(); pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, pWndPopupOwner); }
}
void CMy429testDlg::OnClose()
{
SendMessage(WM_CLOSE);
}
void CMy429testDlg::OnOpenFile()
{
ShellExecute(NULL,NULL,_T("hello.txt"),NULL,NULL,SW_SHOWNORMAL);
}
void CMy429testDlg::OnMaxtextEditSend()
{
//CEdit* pData=(CEdit*)GetDlgItem(IDC_EDIT_SEND);
//pData->SetSel(0,-1,FALSE);
//pData->CloseWindow();
}
void CMy429testDlg::OnClear()
{
// TODO: Add your control notification handler code here
m_list1.ResetContent();
SetDlgItemInt(IDC_STATIC_COUNT,0);//計算列表框中有多少個字符串
}
void CMy429testDlg::OnButton4()
{
int i=0;
if(i%2==0)
WriteByte(0x329,0x0);
else
WriteByte(0x328,0x0);
i++;
}
void CMy429testDlg::OnChangeRate()
{
// TODO: Add your control notification handler code here
WriteWord(0x23c,0x4020);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -