串口调试助手程序框架(一)【截图】【源码】main.cpp#includewindows.h#includecommctrl.h#includeiostream#includestdio.h#includeresource.husingnamespacestd;HINSTANCEhInst;//窗口实例HWNDhRDCLEAR,hSDCLEAR;HMENUhRDCHAR;voidInit(HWNDhwndDlg){SetWindowText(GetDlgItem(hwndDlg,SETXONC),0x13);SetWindowText(GetDlgItem(hwndDlg,SETXOFFC),0x19);SetWindowText(GetDlgItem(hwndDlg,SETTO),0);SendDlgItemMessage(hwndDlg,RDCHAR,BM_SETCHECK,1,0);//把RadioBoxRDCHAR设置为选中SendDlgItemMessage(hwndDlg,SDCHAR,BM_SETCHECK,1,0);//默认发送字符SendDlgItemMessage(hwndDlg,CTASY,BM_SETCHECK,1,0);//默认异步通信//在一个groupbox中必须有一个radiobox的属性:组为真//串口号SetWindowText(GetDlgItem(hwndDlg,SETCOMNO),COM4);//默认值SendDlgItemMessage(hwndDlg,SETCOMNO,CB_ADDSTRING,0,(LPARAM)(COM1));SendDlgItemMessage(hwndDlg,SETCOMNO,CB_ADDSTRING,0,(LPARAM)(COM2));SendDlgItemMessage(hwndDlg,SETCOMNO,CB_ADDSTRING,0,(LPARAM)(COM3));SendDlgItemMessage(hwndDlg,SETCOMNO,CB_ADDSTRING,0,(LPARAM)(COM4));SendDlgItemMessage(hwndDlg,SETCOMNO,CB_ADDSTRING,0,(LPARAM)(COM5));SendDlgItemMessage(hwndDlg,SETCOMNO,CB_ADDSTRING,0,(LPARAM)(COM6));SendDlgItemMessage(hwndDlg,SETCOMNO,CB_ADDSTRING,0,(LPARAM)(COM7));SendDlgItemMessage(hwndDlg,SETCOMNO,CB_ADDSTRING,0,(LPARAM)(COM8));SendDlgItemMessage(hwndDlg,SETCOMNO,CB_ADDSTRING,0,(LPARAM)(COM9));//波特率SetWindowText(GetDlgItem(hwndDlg,SETBR),9600);//默认值SendDlgItemMessage(hwndDlg,SETBR,CB_ADDSTRING,0,(LPARAM)(1200));SendDlgItemMessage(hwndDlg,SETBR,CB_ADDSTRING,0,(LPARAM)(2400));SendDlgItemMessage(hwndDlg,SETBR,CB_ADDSTRING,0,(LPARAM)(4800));SendDlgItemMessage(hwndDlg,SETBR,CB_ADDSTRING,0,(LPARAM)(9600));SendDlgItemMessage(hwndDlg,SETBR,CB_ADDSTRING,0,(LPARAM)(14400));SendDlgItemMessage(hwndDlg,SETBR,CB_ADDSTRING,0,(LPARAM)(28800));SendDlgItemMessage(hwndDlg,SETBR,CB_ADDSTRING,0,(LPARAM)(38400));SendDlgItemMessage(hwndDlg,SETBR,CB_ADDSTRING,0,(LPARAM)(57600));SendDlgItemMessage(hwndDlg,SETBR,CB_ADDSTRING,0,(LPARAM)(115200));//数据位SetWindowText(GetDlgItem(hwndDlg,SETBS),8);//默认值SendDlgItemMessage(hwndDlg,SETBS,CB_ADDSTRING,0,(LPARAM)(4));SendDlgItemMessage(hwndDlg,SETBS,CB_ADDSTRING,0,(LPARAM)(5));SendDlgItemMessage(hwndDlg,SETBS,CB_ADDSTRING,0,(LPARAM)(6));SendDlgItemMessage(hwndDlg,SETBS,CB_ADDSTRING,0,(LPARAM)(7));SendDlgItemMessage(hwndDlg,SETBS,CB_ADDSTRING,0,(LPARAM)(8));//校验位SetWindowText(GetDlgItem(hwndDlg,SETPAR),N);//默认值SendDlgItemMessage(hwndDlg,SETPAR,CB_ADDSTRING,0,(LPARAM)(N));SendDlgItemMessage(hwndDlg,SETPAR,CB_ADDSTRING,0,(LPARAM)(odd));SendDlgItemMessage(hwndDlg,SETPAR,CB_ADDSTRING,0,(LPARAM)(even));//停止位SetWindowText(GetDlgItem(hwndDlg,SETSB),1);//默认值SendDlgItemMessage(hwndDlg,SETSB,CB_ADDSTRING,0,(LPARAM)(1));SendDlgItemMessage(hwndDlg,SETSB,CB_ADDSTRING,0,(LPARAM)(2));}BOOLCALLBACKDlgMain(HWNDhwndDlg,UINTuMsg,WPARAMwParam,LPARAMlParam){//窗口回调函数switch(uMsg)//消息处理{caseWM_INITDIALOG://初始化{Init(hwndDlg);}returnTRUE;caseWM_CLOSE://关闭窗口{EndDialog(hwndDlg,0);}returnTRUE;caseWM_COMMAND://菜单消息{switch(LOWORD(wParam)){caseRDCLEAR://清空接收框数据{SetWindowText(hRDCLEAR,);}returnTRUE;caseSDCLEAR://清空发送框数据{SetWindowText(GetDlgItem(hwndDlg,SDTEXT),);}returnTRUE;caseSDSEND://发送数据{TCHARszBuf[80];//缓存区stringtemp;GetWindowText(GetDlgItem(hwndDlg,SDTEXT),szBuf,80);//获得接收框的文本temp=szBuf;//拼接字符串//couttemp;SetWindowText(GetDlgItem(hwndDlg,RDTEXT),temp.c_str());}returnTRUE;caseSETOP:{//打开串口}returnTRUE;caseSETCP:{//关闭串口}returnTRUE;caseSETSO:{}returnTRUE;}}returnTRUE;}returnFALSE;}intAPIENTRYWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance,LPSTRlpCmdLine,intnShowCmd){hInst=hInstance;InitCommonControls();returnDialogBox(hInst,MAKEINTRESOURCE(DLG_MAIN),NULL,(DLGPROC)DlgMain);}【源码】resource.h#ifndefIDC_STATIC#defineIDC_STATIC(-1)#endif#defineDLG_MAIN100#defineRDBOX40000#defineRDTEXT40001#defineRDCHAR40002#defineRDHEX40003#defineRDCLEAR40004#defineSDCHAR40005#defineSDHEX40006#defineSDCLEAR40007#defineSDSEND40008#defineSDAS40009#defineSDASTIME40010#defineSETCOMNO40011#defineCTSYN40012#defineCTASY40013#defineSETBR40014#defineSDTEXT40015#defineSETXONC40016#defineSETXOFFC40017#defineSETTO40018#defineSETPAR40019#defineSETSB40020#defineSETBS40021#defineSETOP40022#defineSETCP40023#defineSETSO40024【源码】resource.rc#includewindows.h#includecommctrl.h#includerichedit.h#includeresource.h////Dialogresources//LANGUAGELANG_NEUTRAL,SUBLANG_NEUTRALDLG_MAINDIALOG0,0,635,304STYLEDS_3DLOOK|DS_CENTER|DS_MODALFRAME|DS_SHELLFONT|WS_CAPTION|WS_VISIBLE|WS_POPUP|WS_SYSMENUCAPTIONSerialPortDebugFONT8,MsShellDlg{GROUPBOXSetting,0,257,7,365,290,0,WS_EX_LEFTLTEXTSelectPort,0,284,30,36,8,SS_LEFT,WS_EX_LEFTGROUPBOXCommunicationType,0,278,62,295,35,0,WS_EX_LEFTLTEXTByteSize,0,469,120,28,8,SS_LEFT,WS_EX_LEFTLTEXTBaudRate,0,297,122,33,8,SS_LEFT,WS_EX_LEFTGROUPBOXSendData,0,12,135,240,162,0,WS_EX_LEFTLTEXTStopBits,0,471,161,27,8,SS_LEFT,WS_EX_LEFTLTEXTParity,0,299,162,18,8,SS_LEFT,WS_EX_LEFTAUTOCHECKBOXfParity,0,401,162,35,8,0,WS_EX_LEFTAUTOCHECKBOXCTS,0,296,202,30,8,0,WS_EX_LEFTAUTOCHECKBOXDSR,0,365,202,31,8,0,WS_EX_LEFTAUTOCHECKBOXDTR,0,436,202,31,8,0,WS_EX_LEFTAUTOCHECKBOXXON/XOFF,0,507,202,53,8,0,WS_EX_LEFTLTEXTms,0,131,228,