// 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
DWORD style=WS_VISIBLE|WS_CHILD;// if (!m_Com.Create(NULL,style,CRect(0,0,0,0),this,IDC_MSCOMM1))
// { TRACE0("Failed to create OLE Communications Control\n");
// return -1; //fail to create
// }
m_Com.SetCommPort(1); //选择COM1
m_Com.SetInBufferSize(1024); //设置输入缓冲区的大小,Bytes
m_Com.SetOutBufferSize(512); //设置输入缓冲区的大小,Bytes
if(!m_Com.GetPortOpen()) //打开串口
m_Com.SetPortOpen(TRUE);
m_Com.SetInputMode(1); //设置输入方式为二进制方式
m_Com.SetSettings("9600,n,8,1"); //设置波特率等参数
m_Com.SetRThreshold(1); //为1表示有一个字符引发一个事件
m_Com.SetInputLen(0);
return TRUE; // return TRUE unless you set the focus to a control我必须把
if (!m_Com.Create(NULL,style,CRect(0,0,0,0),this,IDC_MSCOMM1))
{ TRACE0("Failed to create OLE Communications Control\n");
return -1; //fail to create
}注释掉才能运行,不知何故??
// 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
DWORD style=WS_VISIBLE|WS_CHILD;// if (!m_Com.Create(NULL,style,CRect(0,0,0,0),this,IDC_MSCOMM1))
// { TRACE0("Failed to create OLE Communications Control\n");
// return -1; //fail to create
// }
m_Com.SetCommPort(1); //选择COM1
m_Com.SetInBufferSize(1024); //设置输入缓冲区的大小,Bytes
m_Com.SetOutBufferSize(512); //设置输入缓冲区的大小,Bytes
if(!m_Com.GetPortOpen()) //打开串口
m_Com.SetPortOpen(TRUE);
m_Com.SetInputMode(1); //设置输入方式为二进制方式
m_Com.SetSettings("9600,n,8,1"); //设置波特率等参数
m_Com.SetRThreshold(1); //为1表示有一个字符引发一个事件
m_Com.SetInputLen(0);
return TRUE; // return TRUE unless you set the focus to a control我必须把
if (!m_Com.Create(NULL,style,CRect(0,0,0,0),this,IDC_MSCOMM1))
{ TRACE0("Failed to create OLE Communications Control\n");
return -1; //fail to create
}注释掉才能运行,不知何故??
// 若是在SDI中使用该控件则要调用下两句,在对话框程序中该语句有MFC自己创建
// 所以不用人为添加DWORD style=WS_VISIBLE | WS_CHILD;
m_MSComm.Create(NULL,style,CRect(0,0,0,0),this,IDC_MSCOMM1);//你的是对话框程序吧?
1。如前我所说,串口这部分是我从别的程序中COPY过来的,而这个所谓“别的程序”也是以对话框为主窗口,却能正常运行;
2。如您所说“若是在SDI中使用该控件则要调用下两句,在对话框程序中该语句有MFC自己创建,所以不用人为添加 ”,那么在哪个文件的哪处可以看到“MFC自己创建”的这部分程序?
另,运行时弹出对话框提示如下:
Debug Assertion Failed!
Program: C:\Documents and Settings\桌面\Tc\Debug\tc.exe
File: occsite.cpp
Line:161 For information on how your program can cause an assertion
failure,see the Visual C++ documentation on asserts.
(Press Retry to debug the application)
终止 重试 忽略