📄 myrichctrl.cpp
字号:
// MyRichCtrl.cpp : implementation file
//
#include "stdafx.h"
#include "cmmg.h"
#include "MyRichCtrl.h"
#define ID_EDIT_SELECTALL 6000
// CMyRichCtrl
IMPLEMENT_DYNAMIC(CMyRichCtrl, CRichEditCtrl)
CMyRichCtrl::CMyRichCtrl()
{
//pThread = AfxBeginThread(ThreadFunc,this,THREAD_PRIORITY_LOWEST);
}
CMyRichCtrl::~CMyRichCtrl()
{
}
BEGIN_MESSAGE_MAP(CMyRichCtrl, CRichEditCtrl)
ON_WM_RBUTTONDOWN()
ON_COMMAND(ID_EDIT_COPY, OnCopy)
ON_COMMAND(ID_EDIT_CUT, OnCut)
ON_COMMAND(ID_EDIT_PASTE, OnPaste)
ON_COMMAND(ID_EDIT_SELECTALL, OnSelectall)
ON_COMMAND(ID_EDIT_UNDO, OnUndo)
//ON_WM_CHAR()
END_MESSAGE_MAP()
// CMyRichCtrl message handlers
void CMyRichCtrl::OnRButtonDown(UINT nFlags, CPoint point){
//设置为焦点
SetFocus();
//创建一个弹出式菜单
CMenu popmenu;
popmenu.CreatePopupMenu();
//添加菜单项目
popmenu.AppendMenu(0, ID_EDIT_UNDO, TEXT("&Undo"));
popmenu.AppendMenu(0, MF_SEPARATOR);
popmenu.AppendMenu(0, ID_EDIT_CUT, TEXT("&Cut"));
popmenu.AppendMenu(0, ID_EDIT_COPY, TEXT("C&opy"));
popmenu.AppendMenu(0, ID_EDIT_PASTE, TEXT("&Paste"));
popmenu.AppendMenu(0, MF_SEPARATOR);
popmenu.AppendMenu(0, ID_EDIT_SELECTALL, TEXT("Select &All"));
//初始化菜单项
UINT nUndo=(CanUndo() ? 0 : MF_GRAYED );
popmenu.EnableMenuItem(ID_EDIT_UNDO, MF_BYCOMMAND|nUndo);
UINT nSel=((GetSelectionType()!=SEL_EMPTY) ? 0 : MF_GRAYED) ;
popmenu.EnableMenuItem(ID_EDIT_CUT, MF_BYCOMMAND|nSel);
popmenu.EnableMenuItem(ID_EDIT_COPY, MF_BYCOMMAND|nSel);
UINT nPaste=(CanPaste() ? 0 : MF_GRAYED) ;
popmenu.EnableMenuItem(ID_EDIT_PASTE, MF_BYCOMMAND|nPaste);
//显示菜单
CPoint pt;
GetCursorPos(&pt);
popmenu.TrackPopupMenu(TPM_RIGHTBUTTON, pt.x, pt.y, this);
popmenu.DestroyMenu();
CRichEditCtrl::OnRButtonDown(nFlags, point);
}
/*void CMyRichCtrl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags){
CRichEditCtrl::OnChar(nChar,nRepCnt,nFlags);
long x,y;
this->GetSel(x,y);
cursorPos = x;
this->modify = true;
::ResumeThread(this->pThread->m_hThread);
}*/
/*UINT CMyRichCtrl::ThreadFunc(LPVOID p){
CMyRichCtrl* pRich = (CMyRichCtrl*)p;
while (true)
{
::Sleep(1000);
Check(p);
pRich->SetSel(pRich->cursorPos,pRich->cursorPos);
pRich->pThread->SuspendThread();
}
return 0;
}*/
/*void CMyRichCtrl::Check(LPVOID p){
CString cstr;
CMyRichCtrl* pRich = (CMyRichCtrl*)p;
pRich->SetSel(0,-1);
CHARFORMAT cf;
pRich->GetDefaultCharFormat(cf);
pRich->SetSelectionCharFormat(cf);
pRich->GetWindowTextW(cstr);
int start = 0, end = 0;
int state = 0;
int lineno = 0;
int length = cstr.GetLength();
while(true){
if (end>=length&&state!=8)
{
return;
}
char c = cstr.GetAt(end);
if (c=='\n')
{
lineno++;
}
switch(state)
{
case 0:
if (isalpha(c))
{
state = 1;
start = end;
break;
}
else if (c=='/')
{
start = end;
state = 2;
end++;
break;
}
else if (isdigit(c))
{
state = 20;
end++;
}
else
end++;
break;
case 1:
if (c=='i')
{
state = 6;
}
else if (c=='e')
{
state = 9;
}
else if (c=='w')
{
state = 12;
}
else if (c=='r')
{
state = 17;
}
else
state = 20;
end++;
break;
case 2:
if (c=='*')
{
state = 3;
end++;
break;
}
else{
state=0;
end++;
break;
}
case 3:
if (c=='*')
{
state = 4;
end++;
}
else{
end++;
}
break;
case 4:
if (c=='*')
{
end++;
state=4;
}
else if (c=='/')
{
state = 5;
}
else{
end++;
state = 3;
}
break;
case 5:
pRich->SetSel(start-lineno,end+1-lineno);
CHARFORMAT cf;
pRich->GetDefaultCharFormat(cf);
cf.dwMask = CFM_COLOR;
cf.dwEffects = ~CFE_AUTOCOLOR;
cf.crTextColor = RGB(0,255,0);
pRich->SetSelectionCharFormat(cf);
end++;
state = 0;
case 6:
if (c=='n')
{
state = 7;
}
else if (c=='f')
{
state = 8;
}
else if (isalpha(c)||isdigit(c))
state = 20;
else
state = 0;
end++;
break;
case 7:
if (c=='t')
{
state=8;
}
else if (isalpha(c)||isdigit(c))
{
state = 20;
}
else
state = 0;
end++;
break;
case 8:
if (isalpha(c)||isdigit(c))
{
state = 20;
}
else{
pRich->SetSel(start-lineno,end-lineno);
CHARFORMAT cf;
pRich->GetDefaultCharFormat(cf);
cf.dwMask = CFM_COLOR;
cf.dwEffects = ~CFE_AUTOCOLOR;
cf.crTextColor = RGB(255,0,0);
pRich->SetSelectionCharFormat(cf);
state = 0;
}
break;
case 9:
if (c=='l')
{
state=10;
}
else if (isalpha(c)||isdigit(c))
{
state = 20;
}
else
state = 0;
end++;
break;
case 10:
if (c=='s')
{
state=11;
}
else if (isalpha(c)||isdigit(c))
{
state = 20;
}
else
state = 0;
end++;
break;
case 11:
if (c=='e')
{
state=8;
}
else if (isalpha(c)||isdigit(c))
{
state = 20;
}
else
state = 0;
end++;
break;
case 12:
if (c=='h')
{
state=13;
}
else if (c=='r')
{
state = 15;
}
else if (isalpha(c)||isdigit(c))
{
state = 20;
}
else
state = 0;
end++;
break;
case 13:
if (c=='i')
{
state=14;
}
else if (isalpha(c)||isdigit(c))
{
state = 20;
}
else
state = 0;
end++;
break;
case 14:
if (c=='l')
{
state=11;
}
else if (isalpha(c)||isdigit(c))
{
state = 20;
}
else
state = 0;
end++;
break;
case 15:
if (c=='i')
{
state=16;
}
else if (isalpha(c)||isdigit(c))
{
state = 20;
}
else
state = 0;
end++;
break;
case 16:
if (c=='t')
{
state=11;
}
else if (isalpha(c)||isdigit(c))
{
state = 20;
}
else
state = 0;
end++;
break;
case 17:
if (c=='r')
{
state=18;
}
else if (isalpha(c)||isdigit(c))
{
state = 20;
}
else
state = 0;
end++;
break;
case 18:
if (c=='a')
{
state=19;
}
else if (isalpha(c)||isdigit(c))
{
state = 20;
}
else
state = 0;
end++;
break;
case 19:
if (c=='d'||c=='l')
{
state=8;
}
else if (isalpha(c)||isdigit(c))
{
state = 20;
}
else
state = 0;
end++;
break;
case 20:
if (isalpha(c)||isdigit(c))
{
state = 20;
}
else{
state = 0;
}
end++;
break;
}
}
}*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -