vs怎么改使输入20位字符输出的是16进制 vs 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 // COMDDlg.cpp : implementation file//#include "stdafx.h"#include "COMD.h"#include "COMDDlg.h"#include "SerialPort.h"#include "ConverDlg.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif#define MSG(msg) SetDlgItemText(IDC_INFO,_T(msg))/////////////////////////////////////////////////////////////////////////////// CAboutDlg dialog used for App Aboutclass 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// Implementationprotected: //{{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_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CCOMDDlg dialogCCOMDDlg::CCOMDDlg(CWnd* pParent /*=NULL*/) : CDialog(CCOMDDlg::IDD, pParent){ //{{AFX_DATA_INIT(CCOMDDlg) m_disp = _T(""); m_bRxHex = FALSE; m_bTxHex = FALSE; m_sTx = _T(""); m_bAutoSend = FALSE; m_nSendTime = 0; m_autoclear = FALSE; //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);}void CCOMDDlg::DoDataExchange(CDataExchange* pDX){ CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CCOMDDlg) DDX_Control(pDX, IDC_START, m_start); DDX_Control(pDX, IDC_CALC, m_calc); DDX_Control(pDX, IDC_CLEARCOUNT, m_clear); DDX_Text(pDX, IDC_DISPLAY, m_disp); DDV_MaxChars(pDX, m_disp, 65535); DDX_Check(pDX, IDC_RXHEX, m_bRxHex); DDX_Check(pDX, IDC_TXHEX, m_bTxHex); DDX_Text(pDX, IDC_TXTXT, m_sTx); DDX_Check(pDX, IDC_AUTOSEND, m_bAutoSend); DDX_Text(pDX, IDC_AUTOSENDTIME, m_nSendTime); DDX_Check(pDX, IDC_AUTOCLEAR, m_autoclear); //}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CCOMDDlg, CDialog) //{{AFX_MSG_MAP(CCOMDDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_START, OnStart) ON_MESSAGE(ON_COM_RECEIVE, OnReceive) ON_BN_CLICKED(IDC_SEND, OnSend) ON_BN_CLICKED(IDC_ENDISPLAY, OnEndisplay) ON_BN_CLICKED(IDC_RXCLEAR, OnRxclear) ON_BN_CLICKED(IDC_CLEARCOUNT, OnClearcount) ON_WM_TIMER() ON_BN_CLICKED(IDC_AUTOSEND, OnAutosend) ON_BN_CLICKED(IDC_CALC, OnCalc) ON_EN_CHANGE(IDC_DISPLAY, OnChangeDisplay) ON_WM_CTLCOLOR() ON_BN_CLICKED(IDC_CLEARTX, OnCleartx) //}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CCOMDDlg message handlersBOOL CCOMDDlg::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_bush.CreateSolidBrush(RGB(200, 200, 255)); //笔刷颜色 m_bDisplay = TRUE; m_com.SetWnd(this->m_hWnd); SetTimer(1,100,NULL); m_nSendTime = 0 ; m_rRX.SubclassDlgItem(IDC_DISPLAY,this); m_rTX.SubclassDlgItem(IDC_TXTXT,this); m_rRX.SetBackgroundColor(0,RGB(200, 200, 255)); //扫描串口列表 ScanPort(); //波特率 ((CComboBox *)GetDlgItem(IDC_BAUDRATE))->InsertString(0,"110"); ((CComboBox *)GetDlgItem(IDC_BAUDRATE))->InsertString(1,"300"); ((CComboBox *)GetDlgItem(IDC_BAUDRATE))->InsertString(2,"600"); ((CComboBox *)GetDlgItem(IDC_BAUDRATE))->InsertString(3,"1200"); ((CComboBox *)GetDlgItem(IDC_BAUDRATE))->InsertString(4,"2400"); ((CComboBox *)GetDlgItem(IDC_BAUDRATE))->InsertString(5,"4800"); ((CComboBox *)GetDlgItem(IDC_BAUDRATE))->InsertString(6,"9600"); ((CComboBox *)GetDlgItem(IDC_BAUDRATE))->InsertString(7,"19200"); ((CComboBox *)GetDlgItem(IDC_BAUDRATE))->InsertString(8,"38400"); ((CComboBox *)GetDlgItem(IDC_BAUDRATE))->InsertString(9,"56000"); ((CComboBox *)GetDlgItem(IDC_BAUDRATE))->InsertString(10,"57600"); ((CComboBox *)GetDlgItem(IDC_BAUDRATE))->InsertString(11,"115200"); ((CComboBox *)GetDlgItem(IDC_BAUDRATE))->SetCurSel(7); //校验位 ((CComboBox *)GetDlgItem(IDC_CHECKBIT))->InsertString(0,"NONE 无"); ((CComboBox *)GetDlgItem(IDC_CHECKBIT))->InsertString(1,"ODD 奇校验"); ((CComboBox *)GetDlgItem(IDC_CHECKBIT))->InsertString(2,"EVEN 偶校验"); ((CComboBox *)GetDlgItem(IDC_CHECKBIT))->InsertString(3,"MARK 标记"); ((CComboBox *)GetDlgItem(IDC_CHECKBIT))->InsertString(4,"SPACE 空格"); ((CComboBox *)GetDlgItem(IDC_CHECKBIT))->SetCurSel(0); //数据位 ((CComboBox *)GetDlgItem(IDC_DATABIT))->InsertString(0,"5"); ((CComboBox *)GetDlgItem(IDC_DATABIT))->InsertString(1,"6"); ((CComboBox *)GetDlgItem(IDC_DATABIT))->InsertString(2,"7"); ((CComboBox *)GetDlgItem(IDC_DATABIT))->InsertString(3,"8"); ((CComboBox *)GetDlgItem(IDC_DATABIT))->SetCurSel(3); //停止位 ((CComboBox *)GetDlgItem(IDC_STOPBIT))->InsertString(0,"1"); ((CComboBox *)GetDlgItem(IDC_STOPBIT))->InsertString(1,"1.5"); ((CComboBox *)GetDlgItem(IDC_STOPBIT))->InsertString(2,"2"); ((CComboBox *)GetDlgItem(IDC_STOPBIT))->SetCurSel(0); //开始按钮 //m_start.SetIcon(IDI_GREEN); //设置默认cfg cfg.baud = 19200; cfg.databits = 8; cfg.stopbits = 1; cfg.parity = 'N'; cfg.port_num = 1; MSG("初始化完成!"); UpdateData(FALSE); return TRUE; // return TRUE unless you set the focus to a control}void CCOMDDlg::OnSysCommand(UINT nID, LPARAM lParam){ if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); }} void CCOMDDlg::OnTimer(UINT nIDEvent) {// TODO: Add your message handler code here and/or call defaultUpdateData();if(nIDEvent == 1){nRx = m_com.GetCounter(TRUE); //接收nTX = m_com.GetCounter(FALSE); //发送CString str;str.Format("接收:%d 发送:%d",nRx,nTX);SetDlgItemText(IDC_COUNTER,str);}if(nIDEvent == 2){if(m_com.IsOpen())OnSend();}CDialog::OnTimer(nIDEvent);} void CCOMDDlg::OnTimer(UINT nIDEvent) {// TODO: Add your message handler code here and/or call defaultUpdateData();if(nIDEvent == 1){nRx = m_com.GetCounter(TRUE); //接收nTX = m_com.GetCounter(FALSE); //发送CString str;str.Format("接收:%d 发送:%d",nRx,nTX);SetDlgItemText(IDC_COUNTER,str);}if(nIDEvent == 2){if(m_com.IsOpen())OnSend();}CDialog::OnTimer(nIDEvent);} Format的时候不要用%d(这是十进制),用%x 这个是十六进制吧!ASCII码的十六进制也这么表示么?还有输入20位怎么编写!谢啦! 这个是十六进制吧!ASCII码的十六进制也这么表示么?还有输入20位怎么编写!谢啦!什么叫输入20位?输出20位:%020x 这个是十六进制吧!ASCII码的十六进制也这么表示么?还有输入20位怎么编写!谢啦!什么叫输入20位?输出20位:%020x就是我想从我的电脑发出20位字符另外一台电脑接收!只是接收的是ASCII码16进制! CTreeCtrl 和 GetItemText 问下菜单键盘加速这个尖角符号是什么? 添加的控件对象为什么不加入到DoDataExchange函数里面? 如何获取控件是否可用? 系统输入法默认为微软拼音时,怎么控制程序使得向IE窗口发送键盘事件时转化为英文输入? 如何 将 char * 类型的日期格式 转换为 CTime类型??? 寻找acdsee的源码 vc++6.0中的CRecordSet对数据库表中的字段数有限制怎么办? 求助 怎样设置才能是vc6.0在英文版win2000中显示中文? windows下c++除了开发游戏外,还有什么好就业? ASCII转换成16进制的程序
//#include "stdafx.h"
#include "COMD.h"
#include "COMDDlg.h"
#include "SerialPort.h"
#include "ConverDlg.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif#define MSG(msg) SetDlgItemText(IDC_INFO,_T(msg))
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App Aboutclass 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()/////////////////////////////////////////////////////////////////////////////
// CCOMDDlg dialogCCOMDDlg::CCOMDDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCOMDDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCOMDDlg)
m_disp = _T("");
m_bRxHex = FALSE;
m_bTxHex = FALSE;
m_sTx = _T("");
m_bAutoSend = FALSE;
m_nSendTime = 0;
m_autoclear = FALSE;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}void CCOMDDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCOMDDlg)
DDX_Control(pDX, IDC_START, m_start);
DDX_Control(pDX, IDC_CALC, m_calc);
DDX_Control(pDX, IDC_CLEARCOUNT, m_clear);
DDX_Text(pDX, IDC_DISPLAY, m_disp);
DDV_MaxChars(pDX, m_disp, 65535);
DDX_Check(pDX, IDC_RXHEX, m_bRxHex);
DDX_Check(pDX, IDC_TXHEX, m_bTxHex);
DDX_Text(pDX, IDC_TXTXT, m_sTx);
DDX_Check(pDX, IDC_AUTOSEND, m_bAutoSend);
DDX_Text(pDX, IDC_AUTOSENDTIME, m_nSendTime);
DDX_Check(pDX, IDC_AUTOCLEAR, m_autoclear);
//}}AFX_DATA_MAP
}BEGIN_MESSAGE_MAP(CCOMDDlg, CDialog)
//{{AFX_MSG_MAP(CCOMDDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_START, OnStart)
ON_MESSAGE(ON_COM_RECEIVE, OnReceive)
ON_BN_CLICKED(IDC_SEND, OnSend)
ON_BN_CLICKED(IDC_ENDISPLAY, OnEndisplay)
ON_BN_CLICKED(IDC_RXCLEAR, OnRxclear)
ON_BN_CLICKED(IDC_CLEARCOUNT, OnClearcount)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_AUTOSEND, OnAutosend)
ON_BN_CLICKED(IDC_CALC, OnCalc)
ON_EN_CHANGE(IDC_DISPLAY, OnChangeDisplay)
ON_WM_CTLCOLOR()
ON_BN_CLICKED(IDC_CLEARTX, OnCleartx)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CCOMDDlg message handlersBOOL CCOMDDlg::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_bush.CreateSolidBrush(RGB(200, 200, 255)); //笔刷颜色 m_bDisplay = TRUE;
m_com.SetWnd(this->m_hWnd);
SetTimer(1,100,NULL);
m_nSendTime = 0 ; m_rRX.SubclassDlgItem(IDC_DISPLAY,this);
m_rTX.SubclassDlgItem(IDC_TXTXT,this);
m_rRX.SetBackgroundColor(0,RGB(200, 200, 255));
//扫描串口列表
ScanPort(); //波特率
((CComboBox *)GetDlgItem(IDC_BAUDRATE))->InsertString(0,"110");
((CComboBox *)GetDlgItem(IDC_BAUDRATE))->InsertString(1,"300");
((CComboBox *)GetDlgItem(IDC_BAUDRATE))->InsertString(2,"600");
((CComboBox *)GetDlgItem(IDC_BAUDRATE))->InsertString(3,"1200");
((CComboBox *)GetDlgItem(IDC_BAUDRATE))->InsertString(4,"2400");
((CComboBox *)GetDlgItem(IDC_BAUDRATE))->InsertString(5,"4800");
((CComboBox *)GetDlgItem(IDC_BAUDRATE))->InsertString(6,"9600");
((CComboBox *)GetDlgItem(IDC_BAUDRATE))->InsertString(7,"19200");
((CComboBox *)GetDlgItem(IDC_BAUDRATE))->InsertString(8,"38400");
((CComboBox *)GetDlgItem(IDC_BAUDRATE))->InsertString(9,"56000");
((CComboBox *)GetDlgItem(IDC_BAUDRATE))->InsertString(10,"57600");
((CComboBox *)GetDlgItem(IDC_BAUDRATE))->InsertString(11,"115200");
((CComboBox *)GetDlgItem(IDC_BAUDRATE))->SetCurSel(7); //校验位
((CComboBox *)GetDlgItem(IDC_CHECKBIT))->InsertString(0,"NONE 无");
((CComboBox *)GetDlgItem(IDC_CHECKBIT))->InsertString(1,"ODD 奇校验");
((CComboBox *)GetDlgItem(IDC_CHECKBIT))->InsertString(2,"EVEN 偶校验");
((CComboBox *)GetDlgItem(IDC_CHECKBIT))->InsertString(3,"MARK 标记");
((CComboBox *)GetDlgItem(IDC_CHECKBIT))->InsertString(4,"SPACE 空格");
((CComboBox *)GetDlgItem(IDC_CHECKBIT))->SetCurSel(0); //数据位
((CComboBox *)GetDlgItem(IDC_DATABIT))->InsertString(0,"5");
((CComboBox *)GetDlgItem(IDC_DATABIT))->InsertString(1,"6");
((CComboBox *)GetDlgItem(IDC_DATABIT))->InsertString(2,"7");
((CComboBox *)GetDlgItem(IDC_DATABIT))->InsertString(3,"8");
((CComboBox *)GetDlgItem(IDC_DATABIT))->SetCurSel(3); //停止位
((CComboBox *)GetDlgItem(IDC_STOPBIT))->InsertString(0,"1");
((CComboBox *)GetDlgItem(IDC_STOPBIT))->InsertString(1,"1.5");
((CComboBox *)GetDlgItem(IDC_STOPBIT))->InsertString(2,"2");
((CComboBox *)GetDlgItem(IDC_STOPBIT))->SetCurSel(0); //开始按钮
//m_start.SetIcon(IDI_GREEN);
//设置默认cfg
cfg.baud = 19200;
cfg.databits = 8;
cfg.stopbits = 1;
cfg.parity = 'N';
cfg.port_num = 1; MSG("初始化完成!");
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}void CCOMDDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
{
// TODO: Add your message handler code here and/or call defaultUpdateData();if(nIDEvent == 1)
{
nRx = m_com.GetCounter(TRUE); //接收
nTX = m_com.GetCounter(FALSE); //发送CString str;
str.Format("接收:%d 发送:%d",nRx,nTX);
SetDlgItemText(IDC_COUNTER,str);
}if(nIDEvent == 2)
{
if(m_com.IsOpen())
OnSend();
}CDialog::OnTimer(nIDEvent);
}
{
// TODO: Add your message handler code here and/or call defaultUpdateData();if(nIDEvent == 1)
{
nRx = m_com.GetCounter(TRUE); //接收
nTX = m_com.GetCounter(FALSE); //发送CString str;
str.Format("接收:%d 发送:%d",nRx,nTX);
SetDlgItemText(IDC_COUNTER,str);
}if(nIDEvent == 2)
{
if(m_com.IsOpen())
OnSend();
}CDialog::OnTimer(nIDEvent);
}
什么叫输入20位?
输出20位:%020x
什么叫输入20位?
输出20位:%020x
就是我想从我的电脑发出20位字符另外一台电脑接收!只是接收的是ASCII码16进制!