📄 myserialrichedit.cpp
字号:
// MySerialRichEdit.cpp : implementation file
//
#include "stdafx.h"
#include "MySerialRichEdit.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// MySerialRichEdit
MySerialRichEdit::MySerialRichEdit()
{
}
MySerialRichEdit::~MySerialRichEdit()
{
}
BEGIN_MESSAGE_MAP(MySerialRichEdit, CRichEditCtrl)
//{{AFX_MSG_MAP(MySerialRichEdit)
ON_WM_CREATE()
ON_WM_KEYDOWN()
ON_WM_RBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_LBUTTONDOWN()
ON_CONTROL_REFLECT(EN_SETFOCUS, OnSetfocus)
ON_WM_LBUTTONDBLCLK()
ON_WM_RBUTTONDBLCLK()
//}}AFX_MSG_MAP
ON_COMMAND_RANGE(IDC_EDIT_COM1,IDC_EDIT_COM9,OnWzdCommandRange)
ON_COMMAND_RANGE(IDC_DEVICE_SBUSI_SELECT,IDC_DEVICE_SBUSI_SELECT+255,OnWzdCommandRange_SBUSI)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// MySerialRichEdit message handlers
void MySerialRichEdit::OnWzdCommandRange_SBUSI(UINT uid)
{
//AfxMessageBox("void MySerialRichEdit::OnWzdCommandRange_SBUSI(UINT uid)");
SerialBus * pbus=(SerialBus *)DeviceMag.DTCB[ID_TYPE_SerialBus].DEVICEINFO[uid-IDC_DEVICE_SBUSI_SELECT].DevicePoint;
pbus->SetOutObj(this);
CString str;
Linknum++;
str.Format("%d:%s",Linknum,DeviceMag.DTCB[ID_TYPE_SerialBus].DEVICEINFO[uid-IDC_DEVICE_SBUSI_SELECT].pDeviceName);
RBDOWN.AppendMenu(0,IDC_DEVICE_NULL_COM,str.GetBuffer(str.GetLength()));
//DeviceMag.DTCB[ID_TYPE_SerialBus].DEVICEINFO[uid-IDC_DEVICE_SBUSI_SELECT].flag=ID_IS_CFG;
//pcpu->PS->SetSBUSrxd(pbus);
//pbus->SetOutObj(pcpu->PS);
//psbusi=DeviceMag.DTCB[ID_TYPE_SerialBus].DEVICEINFO[uid-IDC_DEVICE_SBUSI_SELECT].pDeviceName;
//SetCPUInfo();
//AfxMessageBox(DeviceMag.DTCB[ID_TYPE_SerialBus].DEVICEINFO[uid-IDC_DEVICE_SBUSI_SELECT].pDeviceName);
//GetDlgItem(IDC_BUTTON6)->EnableWindow(FALSE);
}
void MySerialRichEdit::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
CRichEditCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
}
int MySerialRichEdit::SetFontBystr(TCHAR *str)
{
CFont font;
font.CreateFont(0,0,0,0,FW_BOLD,0,0,0,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,str);
this->SetFont(&font,TRUE);
return 0;
}
BOOL MySerialRichEdit::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
// if(pMsg->message==EM_REPLACESEL)
// {
// AfxMessageBox("");
// }
return CRichEditCtrl::PreTranslateMessage(pMsg);
}
int MySerialRichEdit::MyTextOut(TCHAR *str, int scrollpos)
{
this->SendMessage(EM_REPLACESEL,0,(LPARAM)str);
if(scrollpos)
{
this->LineScroll(this->GetLineCount(),0);
}
return 0;
}
void MySerialRichEdit::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
//SBUS.DestroyMenu();
//SBUS.CreatePopupMenu();
for(int i1=0;i1<256;i1++)
{
if(!SBUS.RemoveMenu(0,MF_BYPOSITION))
{
break;
}
}
CString str;
//popmenu.
int s=0;
for(int i=0;i<DeviceMag.DTCB[ID_TYPE_SerialBus].Currentpos;i++)
{
if(!(DeviceMag.DTCB[ID_TYPE_SerialBus].DEVICEINFO[i].flag&ID_IS_CFG))
{
str.Format("串行总线%d:%s",i,DeviceMag.DTCB[ID_TYPE_SerialBus].DEVICEINFO[i].pDeviceName);
SBUS.AppendMenu(0,IDC_DEVICE_SBUSI_SELECT+i,str.GetBuffer(str.GetLength()));
s++;
}
}
if(i==0)
{
SBUS.AppendMenu(0,IDC_DEVICE_NULL_COM,"没有可用的串行总线");
}
//RBDOWN.InsertMenu(0,MF_POPUP,(unsigned int)SBUS.m_hMenu,"选择要监控的串口");
//RBDOWN.InsertMenu(MF_POPUP ,(unsigned int)SBUS.m_hMenu,"选择要监控的串口");
//RBDOWN.ModifyMenu(0,MF_POPUP,(unsigned int)SBUS.m_hMenu,"选择要监控的串口");
/* CMenu* pSubMenu = NULL;
for (int i1=0; i<(int)RBDOWN.GetMenuItemCount(); i1++)
{
pSubMenu = RBDOWN.GetSubMenu(i1);
if (pSubMenu && RBDOWN.GetMenuItemID(0) == IDC_WZD_TYPE)
{
break;
}
}*/
// pSubMenu->AppendMenu(MF_POPUP ,IDC_DEVICE_SBUSI_SELECT,"选择要监控的串口");
CPoint pt;
GetCursorPos(&pt);
RBDOWN.TrackPopupMenu(TPM_RIGHTBUTTON, pt.x, pt.y, this);
CRichEditCtrl::OnRButtonDown(nFlags, point);
}
void MySerialRichEdit::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
//AfxMessageBox("OnLButtonUp");
CRichEditCtrl::OnLButtonUp(nFlags, point);
}
void MySerialRichEdit::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(ismove)
{
SendMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x,point.y));
ismove=0;
//this->Invalidate();
this->ShowWindow(SW_HIDE);
this->ShowWindow(SW_SHOW);
}
// if(issize)
// {
// SetWndSize();
// }
CRichEditCtrl::OnLButtonDown(nFlags, point);
}
void MySerialRichEdit::OnSetfocus()
{
// TODO: Add your control notification handler code here
}
void MySerialRichEdit::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CRichEditCtrl::OnLButtonDblClk(nFlags, point);
}
void MySerialRichEdit::OnRButtonDblClk(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CRichEditCtrl::OnRButtonDblClk(nFlags, point);
}
int MySerialRichEdit::MyCharOut(char ch)
{
this->SendMessage(WM_CHAR,ch,0);
return 0;
}
int MySerialRichEdit::Serial_Char_Event_CallBack(char ch)
{
*ppos=ch;
ppos++;
if(ch=='\n')
{
*ppos=0x00;
if(ppos==presavstr)
{
return 0;//防止多个\n的出现
}
this->SendMessage(EM_REPLACESEL,0,(LPARAM)presavstr);
ppos=presavstr;
}
//this->SendMessage(WM_CHAR,ch,0);
if(ch=='\n')
{
this->LineScroll(this->GetLineCount(),0);
}
return 0;
}
int MySerialRichEdit::Serial_String_Event_CallBack(TCHAR *str)
{
this->SendMessage(EM_REPLACESEL,0,(LPARAM)str);
this->LineScroll(this->GetLineCount(),0);
return 0;
}
int MySerialRichEdit::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CRichEditCtrl::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
ismove=1;
issize=0;
Linknum=0;
ppos=presavstr;
RBDOWN.CreatePopupMenu();
SBUS.CreatePopupMenu();
//SBUS.AppendMenu(0,IDC_DEVICE_SBUSI_SELECT,"串口1");
//RBDOWN.AppendMenu(0,IDC_EDIT_COM1,"选择要监控的串口");
RBDOWN.AppendMenu(MF_POPUP ,(unsigned int)SBUS.m_hMenu,"选择要监控的串口");
RBDOWN.AppendMenu(0,IDC_EDIT_COM3,"设置字体");
RBDOWN.AppendMenu(0,IDC_EDIT_COM2,"移动窗口");
RBDOWN.AppendMenu(0,IDC_EDIT_COM4,"最大化窗口");
RBDOWN.AppendMenu(0,IDC_EDIT_COM5,"最小化窗口");
RBDOWN.AppendMenu(0,IDC_EDIT_COM6,"恢复窗口");
RBDOWN.AppendMenu(MF_SEPARATOR,0,"");
RBDOWN.AppendMenu(0,IDC_DEVICE_NULL_COM,"连入的串行总线列表");
// RBDOWN.AppendMenu(0,IDC_EDIT_COM7,"设置窗口尺寸");
LOGFONT font;
font.lfHeight=-13;font.lfWidth=0;
font.lfEscapement=0;font.lfOrientation=0;
font.lfWeight=400;font.lfItalic=0;font.lfUnderline=0;
font.lfStrikeOut=0;
font.lfCharSet=134;font.lfOutPrecision=3;font.lfClipPrecision=2;
font.lfQuality=1;font.lfPitchAndFamily=2;
memcpy(font.lfFaceName,_T("宋体"),9);
if(!pFount.CreateFontIndirect(&font))
{
AfxMessageBox("CreateFontIndirect失败");
}
this->SetFont(&pFount);
return 0;
}
void MySerialRichEdit::OnWzdCommandRange(UINT uid)
{
switch(uid)
{
case IDC_EDIT_COM1:
break;
case IDC_EDIT_COM2:
ismove=1;
break;
case IDC_EDIT_COM3:
SeteditFont();
break;
case IDC_EDIT_COM4:
MAXWND();
break;
case IDC_EDIT_COM5:
MINWND();
break;
case IDC_EDIT_COM6:
RESTOREWND();
break;
case IDC_EDIT_COM7:
SetWndSize();
break;
case IDC_EDIT_COM8:
break;
case IDC_EDIT_COM9:
//CreateSerialWnd();
break;
default :
break;
}
//CString str;
//str.Format("命令号码%d",uid-IDC_Child_View1+1);
//AfxMessageBox(str);
//pview->SetWindowText("dsfjdsfdshgiudvhsnfdvhsinfdsi");//str.GetBuffer(str.GetLength())
//CWnd * pwnd=pview->GetDlgItem(IDC_mySTATIC);
//pwnd->SetWindowText(str.GetBuffer(str.GetLength()));
//CDC * pdc=pview->GetDC();
//pdc->TextOut(0,0,"MyDefaultView::OnWzdCommandRange");
}
int MySerialRichEdit::SetWndSize()
{
AfxMessageBox("SetWndSize");
CPoint pt;
GetCursorPos(&pt);
RECT Rect;
this->GetRect(&Rect);
//Rect.left=10;
//Rect.top=20;
//Rect.bottom=371;
//Rect.right=344;
this->GetParent()->SetWindowPos(this,Rect.left,Rect.top,Rect.left+200,Rect.top+200,SWP_SHOWWINDOW);
//this->ShowWindow(SW_SHOW);
issize=0;
return 1;
}
int MySerialRichEdit::SeteditFont()
{
LOGFONT font;
font.lfHeight=-13;font.lfWidth=0;
font.lfEscapement=0;font.lfOrientation=0;
font.lfWeight=400;font.lfItalic=0;font.lfUnderline=0;
font.lfStrikeOut=0;
font.lfCharSet=134;font.lfOutPrecision=3;font.lfClipPrecision=2;
font.lfQuality=1;font.lfPitchAndFamily=2;
memcpy(font.lfFaceName,_T("宋体"),5);
CFontDialog fdlg(&font);
if(fdlg.DoModal()==IDOK)
{
fdlg.GetCurrentFont(&font);
}
/* CString str;
str.Format("lfHeight=%d\r\nlfWidth=%d\r\nlfEscapement=%d\r\nlfOrientation=%d\r\nlfWeight=%d\r\nlfItalic=%d\r\nlfUnderline=%d\r\nlfStrikeOut=%d\r\nlfCharSet=%d\r\nlfOutPrecision=%d\r\nlfClipPrecision=%d\r\nlfQuality=%d\r\nlfPitchAndFamily=%d\r\nlfFaceName=%s\r\n",
font.lfHeight,font.lfWidth,font.lfEscapement,font.lfOrientation,font.lfWeight,font.lfItalic,font.lfUnderline,font.lfStrikeOut,
font.lfCharSet,font.lfOutPrecision,font.lfClipPrecision,font.lfQuality,font.lfPitchAndFamily,font.lfFaceName
);
AfxMessageBox(str);
*/
if(!pFount.CreateFontIndirect(&font))
{
AfxMessageBox("CreateFontIndirect失败");
}
this->SetFont(&pFount);
return 1;
}
int MySerialRichEdit::MAXWND()
{
this->ShowWindow(SW_SHOWMAXIMIZED);
return 1;
}
int MySerialRichEdit::MINWND()
{
this->ShowWindow(SW_SHOWMINIMIZED);
return 1;
}
void MySerialRichEdit::RESTOREWND()
{
/* RECT rect;
rect.top=20;
rect.left=20;
rect.right=rect.left+width;
rect.bottom=rect.top+high;
this->SetRect(&rect);*/
this->ShowWindow(SW_RESTORE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -