该程序全部由C写成  没有C++  更没用MFC
完全是自娱自乐  给需要的人一个参考
#include "stdafx.h"
#include <windowsx.h>
#include "resource.h"
#include "MainDlg.h"
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
HANDLE hComm;//用于获取串口打开函数的返回值(句柄或错误值)
OVERLAPPED m_ov;
COMSTAT comstat;
DWORD m_dwCommEvents;
TCHAR cRecs[200],cSends[100]; //接收字符串 发送字符串
char j=0,*cCom; //接收用统计数据大小变量 端口选择
BOOL WINAPI Main_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
HANDLE_MSG(hWnd, WM_INITDIALOG, Main_OnInitDialog);
HANDLE_MSG(hWnd, WM_COMMAND, Main_OnCommand);
HANDLE_MSG(hWnd,WM_CLOSE, Main_OnClose);
}
return FALSE;
}
c编程网站
/*系统初始化函数*/
BOOL Main_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
HWND hwndCombo1=GetDlgItem(hwnd,IDC_COMBO1);
ComboBox_InsertString(hwndCombo1,-1,TEXT("COM1"));
ComboBox_InsertString(hwndCombo1,-1,TEXT("COM2"));
ComboBox_InsertString(hwndCombo1,-1,TEXT("COM3"));
ComboBox_InsertString(hwndCombo1,-1,TEXT("COM4"));
ComboBox_InsertString(hwndCombo1,-1,TEXT("COM5"));
ComboBox_SetCurSel(hwndCombo1,0);
void CALLBACK TimerProc (HWND hwnd, UINT message, UINT iTimerID, DWORD dwTime);
SetTimer(hwnd,1,1000,TimerProc);
return TRUE;
}
/*监视串口错误时使用的函数*/
bool ProcessErrorMessage(char* ErrorText)
{
char *Temp = new char[200];
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
sprintf(Temp, "WARNING: %s Failed with the following error: \n%s\nPort: %d\n", (char*)ErrorText, lpMsgBuf, "com2");
MessageBox(NULL, Temp, "Application Error", MB_ICONSTOP);
LocalFree(lpMsgBuf);
delete[] Temp;
return true;

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。