📄 mweditctl.cpp
字号:
// MWEditCtl.cpp : Implementation of the CMWEditCtrl ActiveX Control class.
#include "stdafx.h"
#include "MWEdit.h"
#include "MWEditCtl.h"
#include "MWEditPpg.h"
//#define _UNICODE
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CMWEditCtrl, COleControl)
/////////////////////////////////////////////////////////////////////////////
// Message map
BEGIN_MESSAGE_MAP(CMWEditCtrl, COleControl)
//{{AFX_MSG_MAP(CMWEditCtrl)
ON_WM_CHAR()
ON_WM_KEYDOWN()
ON_WM_PAINT()
ON_WM_RBUTTONDOWN()
ON_WM_WINDOWPOSCHANGED()
ON_WM_LBUTTONDOWN()
ON_WM_CONTEXTMENU()
ON_COMMAND(IDM_COPY, OnCopy)
ON_COMMAND(IDM_CUT, OnCut)
ON_COMMAND(IDM_DELETE, OnDelete)
ON_COMMAND(IDM_PASTE, OnPaste)
ON_COMMAND(IDM_UNDO, OnUndo)
ON_COMMAND(IDM_SELECTALL, OnSelectall)
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONUP()
ON_WM_ACTIVATE()
ON_WM_HSCROLL()
ON_UPDATE_COMMAND_UI(IDM_COPY, OnUpdateCopy)
ON_UPDATE_COMMAND_UI(IDM_CUT, OnUpdateCut)
ON_UPDATE_COMMAND_UI(IDM_DELETE, OnUpdateDelete)
ON_UPDATE_COMMAND_UI(IDM_PASTE, OnUpdatePaste)
ON_UPDATE_COMMAND_UI(IDM_SELECTALL, OnUpdateSelectall)
ON_UPDATE_COMMAND_UI(IDM_UNDO, OnUpdateUndo)
//}}AFX_MSG_MAP
ON_OLEVERB(AFX_IDS_VERB_EDIT, OnEdit)
ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Dispatch map
BEGIN_DISPATCH_MAP(CMWEditCtrl, COleControl)
//{{AFX_DISPATCH_MAP(CMWEditCtrl)
DISP_PROPERTY_NOTIFY(CMWEditCtrl, "BufferStr", m_bufferStr, OnBufferStrChanged, VT_BSTR)
DISP_PROPERTY_NOTIFY(CMWEditCtrl, "initialsizecx", m_initialsizecx, OnInitialsizecxChanged, VT_I4)
DISP_PROPERTY_NOTIFY(CMWEditCtrl, "initialsizecy", m_initialsizecy, OnInitialsizecyChanged, VT_I4)
DISP_PROPERTY_NOTIFY(CMWEditCtrl, "FontWeight", m_fontWeight, OnFontWeightChanged, VT_I4)
DISP_PROPERTY_NOTIFY(CMWEditCtrl, "FontHeight", m_fontHeight, OnFontHeightChanged, VT_I4)
DISP_PROPERTY_NOTIFY(CMWEditCtrl, "top", m_top, OnTopChanged, VT_I4)
DISP_PROPERTY_NOTIFY(CMWEditCtrl, "bottom", m_bottom, OnBottomChanged, VT_I4)
DISP_PROPERTY_NOTIFY(CMWEditCtrl, "left", m_left, OnLeftChanged, VT_I4)
DISP_PROPERTY_NOTIFY(CMWEditCtrl, "right", m_right, OnRightChanged, VT_I4)
DISP_STOCKPROP_READYSTATE()
//}}AFX_DISPATCH_MAP
DISP_FUNCTION_ID(CMWEditCtrl, "AboutBox", DISPID_ABOUTBOX, AboutBox, VT_EMPTY, VTS_NONE)
END_DISPATCH_MAP()
/////////////////////////////////////////////////////////////////////////////
// Event map
BEGIN_EVENT_MAP(CMWEditCtrl, COleControl)
//{{AFX_EVENT_MAP(CMWEditCtrl)
// NOTE - ClassWizard will add and remove event map entries
// DO NOT EDIT what you see in these blocks of generated code !
EVENT_STOCK_READYSTATECHANGE()
//}}AFX_EVENT_MAP
END_EVENT_MAP()
/////////////////////////////////////////////////////////////////////////////
// Property pages
// TODO: Add more property pages as needed. Remember to increase the count!
BEGIN_PROPPAGEIDS(CMWEditCtrl, 1)
PROPPAGEID(CMWEditPropPage::guid)
END_PROPPAGEIDS(CMWEditCtrl)
/////////////////////////////////////////////////////////////////////////////
// Initialize class factory and guid
IMPLEMENT_OLECREATE_EX(CMWEditCtrl, "MWEDIT.MWEditCtrl.1",
0x54717205, 0x4c3b, 0x11d5, 0x8d, 0xc4, 0, 0x80, 0xc8, 0xe1, 0xf3, 0x52)
/////////////////////////////////////////////////////////////////////////////
// Type library ID and version
IMPLEMENT_OLETYPELIB(CMWEditCtrl, _tlid, _wVerMajor, _wVerMinor)
/////////////////////////////////////////////////////////////////////////////
// Interface IDs
const IID BASED_CODE IID_DMWEdit =
{ 0x54717203, 0x4c3b, 0x11d5, { 0x8d, 0xc4, 0, 0x80, 0xc8, 0xe1, 0xf3, 0x52 } };
const IID BASED_CODE IID_DMWEditEvents =
{ 0x54717204, 0x4c3b, 0x11d5, { 0x8d, 0xc4, 0, 0x80, 0xc8, 0xe1, 0xf3, 0x52 } };
/////////////////////////////////////////////////////////////////////////////
// Control type information
static const DWORD BASED_CODE _dwMWEditOleMisc =
OLEMISC_ACTIVATEWHENVISIBLE |
OLEMISC_IGNOREACTIVATEWHENVISIBLE |
OLEMISC_SETCLIENTSITEFIRST |
OLEMISC_INSIDEOUT |
OLEMISC_CANTLINKINSIDE |
OLEMISC_RECOMPOSEONRESIZE;
IMPLEMENT_OLECTLTYPE(CMWEditCtrl, IDS_MWEDIT, _dwMWEditOleMisc)
/////////////////////////////////////////////////////////////////////////////
// CMWEditCtrl::CMWEditCtrlFactory::UpdateRegistry -
// Adds or removes system registry entries for CMWEditCtrl
BOOL CMWEditCtrl::CMWEditCtrlFactory::UpdateRegistry(BOOL bRegister)
{
// TODO: Verify that your control follows apartment-model threading rules.
// Refer to MFC TechNote 64 for more information.
// If your control does not conform to the apartment-model rules, then
// you must modify the code below, changing the 6th parameter from
// afxRegInsertable | afxRegApartmentThreading to afxRegInsertable.
if (bRegister)
return AfxOleRegisterControlClass(
AfxGetInstanceHandle(),
m_clsid,
m_lpszProgID,
IDS_MWEDIT,
IDB_MWEDIT,
afxRegInsertable | afxRegApartmentThreading,
_dwMWEditOleMisc,
_tlid,
_wVerMajor,
_wVerMinor);
else
return AfxOleUnregisterClass(m_clsid, m_lpszProgID);
}
/////////////////////////////////////////////////////////////////////////////
// CMWEditCtrl::CMWEditCtrl - Constructor
CMWEditCtrl::CMWEditCtrl()
{
InitializeIIDs(&IID_DMWEdit, &IID_DMWEditEvents);
m_uiCustomFormat=::RegisterClipboardFormat(_T("MFCControlWinCustomFormat"));
m_lReadyState = READYSTATE_LOADING;
// lpRect=&Rect;
// GetRectInContainer(lpRect);
SubStr.Empty();
m_cstrCaption.Empty();
sControl=0;
Insert=1;
font=1;//蒙文
m_bufferStrCopy.Empty();
m_bufferStr.Empty();
m_initialsizecx=300;
m_initialsizecy=200;
SetInitialSize(m_initialsizecx,m_initialsizecy);
flag=0;
thisone=0;
WindowChangFlag=0;
m_fontWeight=500;
m_fontHeight=30;
/*MyFont.CreateFont(m_fontHeight-2,
0,
2700,
0,
m_fontWeight,
FALSE,
FALSE,
0,
ANSI_CHARSET,//|DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
//DEFAULT_PITCH|FF_SWISS,
FF_ROMAN,
_T("Times New Roman"));//"Times New Roman");//"Arial");
*/
MyFont.CreateFont(m_fontHeight-2,
0,
2700,
0,
FW_DONTCARE,
FALSE,
FALSE,
FALSE,
DEFAULT_CHARSET,//|DEFAULT_CHARSET,
OUT_CHARACTER_PRECIS,
CLIP_CHARACTER_PRECIS,
DEFAULT_QUALITY,
DEFAULT_PITCH|FF_DONTCARE,
_T("Times New Roman"));//_T("MWyst"));//
//GetFontUnicodeRanges(NULL);
/* char enter[2];
enter[0]=13;
enter[1]=10;
Enter+=enter;*/
Enter.SetAt(0,0x000d);
//chushihua
curCaret.CaretPos.x=0;
curCaret.CaretPos.y=0;
curCaret.CharCount=0;
curCaret.GeneralBufPos=0;
curCaret.GeneralLine=1;
curCaret.SCreenLine=1;
curCaretCopy=curCaret;
redrawcaret=curCaret;
block.FirstCaret=curCaret;
zero=curCaret;
block.Str.Empty();
for(int i=0;i<100;i++)
{
curGeneral.ColumnCount[i]=0;
curGeneral.ColumnPosit[i]=0;
}
Select=0;
MaxLine=0;
SFLisGL=1;
DealGenPos=0;
finishflag=0;
allflag=0;
MyPopMenu.LoadMenu(ID_POPMENU);
//AfxGetApp()->LoadCursor(IDC_ARROW);
firstflag=0;
blockflag=0;
clipflag=0;
transmis.Str.Empty();
transmis.FirstCaret=zero;
transmis.LastCaret=zero;
// myBar.LoadScrollBar(IDC_SCROLLBAR1);
// TODO: Call InternalSetReadyState when the readystate changes.
//GetTextFace(
// TODO: Initialize your control's instance data here.
}
/////////////////////////////////////////////////////////////////////////////
// CMWEditCtrl::~CMWEditCtrl - Destructor
CMWEditCtrl::~CMWEditCtrl()
{
// TODO: Cleanup your control's instance data here.
}
/////////////////////////////////////////////////////////////////////////////
// CMWEditCtrl::OnDraw - Drawing function
void CMWEditCtrl::OnDraw(
CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid)
{
}
/////////////////////////////////////////////////////////////////////////////
// CMWEditCtrl::DoPropExchange - Persistence support
void CMWEditCtrl::DoPropExchange(CPropExchange* pPX)
{
ExchangeVersion(pPX, MAKELONG(_wVerMinor, _wVerMajor));
COleControl::DoPropExchange(pPX);
// TODO: Call PX_ functions for each persistent custom property.
}
/////////////////////////////////////////////////////////////////////////////
// CMWEditCtrl::GetControlFlags -
// Flags to customize MFC's implementation of ActiveX controls.
//
// For information on using these flags, please see MFC technical note
// #nnn, "Optimizing an ActiveX Control".
DWORD CMWEditCtrl::GetControlFlags()
{
DWORD dwFlags = COleControl::GetControlFlags();
// The control will not be redrawn when making the transition
// between the active and inactivate state.
dwFlags |= noFlickerActivate;
// The control can receive mouse notifications when inactive.
// TODO: if you write handlers for WM_SETCURSOR and WM_MOUSEMOVE,
// avoid using the m_hWnd member variable without first
// checking that its value is non-NULL.
dwFlags |= pointerInactive;
// The control can optimize its OnDraw method, by not restoring
// the original GDI objects in the device context.
dwFlags |= canOptimizeDraw;
return dwFlags;
}
/////////////////////////////////////////////////////////////////////////////
// CMWEditCtrl::OnResetState - Reset control to default state
void CMWEditCtrl::OnResetState()
{
COleControl::OnResetState(); // Resets defaults found in DoPropExchange
// TODO: Reset any other control state here.
}
/////////////////////////////////////////////////////////////////////////////
// CMWEditCtrl::AboutBox - Display an "About" box to the user
void CMWEditCtrl::AboutBox()
{
CDialog dlgAbout(IDD_ABOUTBOX_MWEDIT);
dlgAbout.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CMWEditCtrl message handlers
void CMWEditCtrl::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
curCaretCopy=curCaret;
m_bufferStrCopy=m_bufferStr.Left(m_bufferStr.GetLength());
HideCaret();
TCHAR ch;
//CString s1,s2;
//MessageBox(
if(nChar==32)
ch=nChar;
else
{
if(font)
{
if((nChar<128)&&(nChar>20))
ch=0x1800+nChar-0x33;
else
ch=nChar;
}
else
ch=nChar;
}
SubStr+=ch;
//ch=SubStr[0+0];
// TestInt(nChar,SubStr);
if(blockflag)
{
curCaret=transmis.FirstCaret;
m_bufferStr.Delete(transmis.FirstCaret.GeneralBufPos,transmis.Str.GetLength());
transmis.Str.Empty();
blockflag=0;
}
Invalidate();
}
void CMWEditCtrl::OnBufferStrChanged()
{
// TODO: Add notification handler code
SetModifiedFlag();
}
void CMWEditCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
/* switch(nChar)
{
case VK_LEFT:
Left();
break;
case VK_UP:
Up();
break;
case VK_RIGHT:
Right();
break;
case VK_DOWN:
Down();
break;
case VK_HOME:
Home();
break;
case VK_END:
End();
break;
case VK_PRIOR:
Delete();
//Pageup();
break;
case VK_NEXT:
Pagedown();
break;
case VK_DELETE:
Delete();
break;
case VK_INSERT:
if(Insert)
Insert=0;
else
Insert=1;
//Invalidate();
break;
case VK_BACK:
Backup();
break;
}*/
// COleControl::OnKeyDown(nChar, nRepCnt, nFlags);
}
void CMWEditCtrl::Up()
{
m_bufferStrCopy=m_bufferStr.Left(m_bufferStr.GetLength());
curCaretCopy=curCaret;
if(curCaret.CharCount!=0)
{
//TestInt(curCaret.GeneralLine,curCaret.CharCount);
curCaret.GeneralBufPos--;
curCaret.CharCount--;
CString Sub=m_bufferStr.Mid(curCaret.GeneralBufPos-curCaret.CharCount,curCaret.CharCount);
if(curCaret.CharCount)
curCaret.CaretPos.y=GetStrWid(Sub);
else
curCaret.CaretPos.y=0;
}
CClientDC dc(this);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -