⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mtextdlg.cpp

📁 mtext,编辑器,支持潜入对象
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    case  1:
		pToolCtrl.Indeterminate(ID_CHAR_UNDERLINE,false);
		pToolCtrl.CheckButton(ID_CHAR_UNDERLINE,true);
		break;
    default:
		pToolCtrl.CheckButton(ID_CHAR_UNDERLINE,false);
		pToolCtrl.Indeterminate(ID_CHAR_UNDERLINE,false);
		break;
	}
}
LRESULT CMTextDlg::OnKickIdle(WPARAM wParam, LPARAM lParam)
{ 
	TBBUTTON infoBtn;
	int i,iCount;
	CCmdUI cmdUI;
	CToolBarCtrl &pToolCtrl = m_wndStyleBar.GetToolBarCtrl();
	iCount = pToolCtrl.GetButtonCount();
	for( i = 0; i < iCount; i++ )
	{ 
		pToolCtrl.GetButton(i,&infoBtn);
		cmdUI.m_nID = infoBtn.idCommand;
		cmdUI.DoUpdate(this, FALSE);
	}
	m_wndStyleBar.OnUpdateCmdUI(NULL,true);
	return 0L;
}

void CMTextDlg::OnEditUndo() 
{
	// TODO: Add your command handler code here
	::SendMessage( 
	m_ctlRichText.m_hWnd,              
		EM_UNDO,                 
		0,          
		0         
		);
	
}

void CMTextDlg::OnEditRedo() 
{
	// TODO: Add your command handler code here
	::SendMessage( 
		m_ctlRichText.m_hWnd,              
		EM_REDO,                 
		0,          
		0         
		);
}

void CMTextDlg::OnUpdateEditUndo(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	CToolBarCtrl &pToolCtrl = m_wndStyleBar.GetToolBarCtrl();
	int iValue =m_ctlRichText.IsUnderlined();
	if(m_ctlRichText.CanUndo())
		pToolCtrl.EnableButton(ID_EditUndo);
	else
		pToolCtrl.EnableButton(ID_EditUndo,FALSE);

  
	
}

void CMTextDlg::OnUpdateEditRedo(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	int lCanRedo;
	lCanRedo=m_ctlRichText.SendMessage(       
		EM_CANREDO ,                 
		0,          
		0         
		);
	CToolBarCtrl &pToolCtrl = m_wndStyleBar.GetToolBarCtrl();
	if(lCanRedo)
		pToolCtrl.EnableButton(ID_EditRedo);
	else
		pToolCtrl.EnableButton(ID_EditRedo,FALSE);
		
}



void CMTextDlg::OnContextMenu(CWnd* pWnd, CPoint point) 
{
	// TODO: Add your message handler code here
		CMenu menuTextEdit;
		menuTextEdit.LoadMenu(IDR_Rich_POP);
      
		switch(m_iTextAlign) {
		case 0:
			menuTextEdit.CheckMenuItem(ID_EditAlignL,MF_CHECKED);
			break;
		case 1:
			menuTextEdit.CheckMenuItem(ID_EditAlignC,MF_CHECKED);
			break;
		case 2:
			menuTextEdit.CheckMenuItem(ID_EditAlignR,MF_CHECKED);
			break;
		case 3:
			menuTextEdit.CheckMenuItem(ID_EditAlignL_C,MF_CHECKED);
			break;
		case 4:
			menuTextEdit.CheckMenuItem(ID_EditAlignC_C,MF_CHECKED);
			break;
		case 5:
			menuTextEdit.CheckMenuItem(ID_EditAlignR_C,MF_CHECKED);
			break;
		case 6:
			menuTextEdit.CheckMenuItem(ID_EditAlignL_D,MF_CHECKED);
			break;
		case 7:
			menuTextEdit.CheckMenuItem(ID_EditAlignC_D,MF_CHECKED);
			break;
		case 8:
			menuTextEdit.CheckMenuItem(ID_EditAlignR_D,MF_CHECKED);
			break;
		}
		TRACE("(Align in OnMenu: %d )",m_iTextAlign);
		BYTE keyState[256];
		GetKeyboardState((LPBYTE)&keyState);
		if((keyState[VK_CAPITAL] & 1))
			menuTextEdit.CheckMenuItem(ID_EditAutoUPCASE,MF_CHECKED);

		int iStackStatus;
		m_ctlRichText.GetStackStatus(iStackStatus);
		if(IsSelectStack())
			iStackStatus=1;

		switch(iStackStatus) 
		{
		case 0://选中了可Stack的字符串
			menuTextEdit.DeleteMenu(ID_StackStyle,MF_BYCOMMAND);
			menuTextEdit.DeleteMenu(ID_UndoStack,MF_BYCOMMAND);
			break;
		case 1: //选中了Stack
			menuTextEdit.DeleteMenu(ID_Stack,MF_BYCOMMAND);
			break;
		case 2:
			menuTextEdit.DeleteMenu(ID_StackStyle,MF_BYCOMMAND);
			menuTextEdit.DeleteMenu(ID_UndoStack,MF_BYCOMMAND);
			menuTextEdit.DeleteMenu(ID_Stack,MF_BYCOMMAND);
			break;
		case -1:
			menuTextEdit.DeleteMenu(ID_StackStyle,MF_BYCOMMAND);
			menuTextEdit.DeleteMenu(ID_UndoStack,MF_BYCOMMAND);
			menuTextEdit.DeleteMenu(ID_Stack,MF_BYCOMMAND);
			break;
		}
		if(m_bIsTransparent)
		{
			menuTextEdit.CheckMenuItem(ID_Transparent,MF_CHECKED);	
		}
		menuTextEdit.DeleteMenu(ID_EditTable,MF_BYCOMMAND); //由于功能不够完善,放弃使用
		menuTextEdit.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN,point.x,point.y,this);
}

void CMTextDlg::OnEditAutoUPCASE() 
{
	
	m_ctlRichText.Send_keybd_event(VK_CAPITAL);
	
}

void CMTextDlg::OnEditCut() 
{
	// TODO: Add your command handler code here
	m_ctlRichText.Cut();	
}

void CMTextDlg::OnEditCOPY() 
{
	// TODO: Add your command handler code here

	m_ctlRichText.Copy();

		
}
void CMTextDlg::OnEditPast() 
{

	if(m_ctlRichText.CanPaste(CF_TEXT))
	{
		CHARFORMAT cf;
		CHARRANGE  crS;
		CHARRANGE  crE;
		m_ctlRichText.GetSel(crS);
		m_ctlRichText.Paste();
	
		m_ctlRichText.GetSel(crE);
		m_ctlRichText.SetSel(crS.cpMin,crE.cpMax);
		cf.cbSize = sizeof(CHARFORMAT);
		cf.dwMask = CFM_COLOR;
		DWORD dwSelMask = m_ctlRichText.GetSelectionCharFormat(cf);
		if( !((dwSelMask & CFM_COLOR)&&cf.crTextColor==RGB(255,255,255))||
			(!(dwSelMask & CFM_COLOR)))
		{ 
			cf.dwMask=CFM_COLOR;
			cf.dwEffects=0;
			cf.crTextColor=RGB(255,255,255);
			m_ctlRichText.SetSelectionCharFormat(cf);
			
		}
		m_ctlRichText.SetSel(crE);
	}
	else
	{
	
		if(CreateFromClipboard())
			InsertObject();
	}  
}

void CMTextDlg::OnEditDegree() 
{
	// TODO: Add your command handler code here
	m_ctlRichText.ReplaceSel(_T("%%d"));
}

void CMTextDlg::OnEditDelFormat() 
{
	// TODO: Add your command handler code here
	m_ctlRichText.DelectSelectFormat();
}

void CMTextDlg::OnEditDiameter() 
{
	// TODO: Add your command handler code here
	m_ctlRichText.ReplaceSel(_T("%%c"));
}

void CMTextDlg::OnEditFindR() 
{
	// TODO: Add your command handler code here
//	CFindReplaceDialog dlg;
//	dlg.DoModal();
//	InitFindReplaceDlg();
	m_ctlRichText.InitFindReplaceDlg();

}

void CMTextDlg::OnEditOther() 
{
	// TODO: Add your command handler code here
	if(int(ShellExecute(NULL,"open","charmap.exe",NULL,NULL,SW_SHOW))<=32)
		AfxMessageBox(_T("Not Find charmap.exe"));
}

void CMTextDlg::OnEditPlus() 
{
	// TODO: Add your command handler code here
		m_ctlRichText.ReplaceSel(_T("%%p"));
}

void CMTextDlg::OnEditPutWord() 
{
	// TODO: Add your command handler code here
	m_ctlRichText.ReadFromFile();
}

void CMTextDlg::OnEditSelectALL() 
{
	// TODO: Add your command handler code here
	m_ctlRichText.SetSel(0,-1);
}

void CMTextDlg::OnEditTable() 
{
	// TODO: Add your command handler code here
	PARAFORMAT pf;
	m_ctlRichText.GetParaFormat(pf);
	CMTextFormatTabDlg dlg(pf);
	dlg.m_FontSizeScale=m_wndStyleBar.m_FontSizeScale;
	//dlg.m_nWordWrap = m_nWordWrap;
	if (dlg.DoModal() == IDOK)
		m_ctlRichText.SetParaFormat(dlg.m_pf);
}


void CMTextDlg::OnEditBlackSpace() 
{
	// TODO: Add your command handler code here
	CHARRANGE cr;
	m_ctlRichText.GetSel(cr);
	m_ctlRichText.SetSel(cr.cpMin,cr.cpMin);  
	m_ctlRichText.ReplaceSel("\t", TRUE);
}

void CMTextDlg::OnEditCombineP() 
{
	// TODO: Add your command handler code here
	m_ctlRichText.CombineSelectParagraph();
}



void CMTextDlg::SetTransparent(BOOL type,int degree)
{
	if(type)
	{
		HINSTANCE hInst = LoadLibrary("User32.DLL"); 
		if(hInst) 
		{ 
			typedef BOOL (WINAPI *MYFUNC)(HWND, COLORREF, BYTE, DWORD); 
			MYFUNC fun = NULL;
			//取得SetLayeredWindowAttributes函数指针 
			fun = (MYFUNC)GetProcAddress(hInst, "SetLayeredWindowAttributes");
			if (fun) 
			{
				SetWindowLong(this->GetSafeHwnd(), GWL_EXSTYLE, GetWindowLong(this->GetSafeHwnd(), GWL_EXSTYLE) ^0x80000);
				fun(GetSafeHwnd(), RGB(255,0,0), (255 * degree) / 100, 0x2);
			}
			FreeLibrary(hInst); 
		}
	}
	else
	{
		SetWindowLong(GetSafeHwnd(), GWL_EXSTYLE,
			GetWindowLong(GetSafeHwnd(), GWL_EXSTYLE) & ~0x80000);
		// Ask the window and its children to repaint
		::RedrawWindow(GetSafeHwnd(), NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_FRAME |
			RDW_ALLCHILDREN);
	}
}

void CMTextDlg::OnEditAlignL() 
{
	// TODO: Add your command handler code here
	m_ctlRichText.SetLeft();
	m_iTextAlign=0;
	TRACE("(Align: %d )",m_iTextAlign);
}

void CMTextDlg::OnEditAlignC() 
{
	// TODO: Add your command handler code here
	m_ctlRichText.SetCenter();
	m_iTextAlign=1;
	TRACE("(Align: %d )",m_iTextAlign);
}

void CMTextDlg::OnEditAlignR() 
{
	// TODO: Add your command handler code here
	m_ctlRichText.SetRight();
	m_iTextAlign=2;
	TRACE("(Align: %d )",m_iTextAlign);
}
void CMTextDlg::OnEditAlignL_C() 
{
	// TODO: Add your command handler code here
	m_ctlRichText.SetLeft();
	m_iTextAlign=3;
	TRACE("(Align: %d )",m_iTextAlign);
}

void CMTextDlg::OnEditAlignC_C() 
{
	// TODO: Add your command handler code here
	m_ctlRichText.SetCenter();
	m_iTextAlign=4;
	TRACE("(Align: %d )",m_iTextAlign);
}

void CMTextDlg::OnEditAlignR_C() 
{
	// TODO: Add your command handler code here
	m_ctlRichText.SetRight();
	m_iTextAlign=5;
	TRACE("(Align: %d )",m_iTextAlign);
}
void CMTextDlg::OnEditAlignL_D() 
{
	// TODO: Add your command handler code here
	m_ctlRichText.SetLeft();
	m_iTextAlign=6;
	TRACE("(Align: %d )",m_iTextAlign);
}

void CMTextDlg::OnEditAlignC_D() 
{
	// TODO: Add your command handler code here
	m_ctlRichText.SetCenter();
	m_iTextAlign=7;
	TRACE("(Align: %d )",m_iTextAlign);
}

void CMTextDlg::OnEditAlignR_D() 
{
	// TODO: Add your command handler code here
	m_ctlRichText.SetRight();
	m_iTextAlign=8;
}

void CMTextDlg::GetAlignment(int &nAlignment)
{
	m_ctlRichText.GetAlignment(nAlignment);
}



void CMTextDlg::OnEditChangeLOWCASE() 
{
	// TODO: Add your command handler code here
	m_ctlRichText.MakeSelectUpperCase(FALSE);
}

void CMTextDlg::OnEditChangeUPCASE() 
{
	// TODO: Add your command handler code here
	m_ctlRichText.MakeSelectUpperCase();
}


BOOL CMTextDlg::CreateFromFile(LPCTSTR lpszFileName)
{
	USES_CONVERSION;
	
	ASSERT_VALID(this);
	ASSERT(m_lpObject == NULL);     // one time only
	
	ASSERT(m_lpStorage == NULL);
	ASSERT(m_lpClientSite == NULL);
	LPLOCKBYTES lpLockBytes = NULL;
	CLSID clsid = CLSID_NULL;
	OLERENDER render = OLERENDER_DRAW;
	CLIPFORMAT cfFormat = 0;
	LPFORMATETC lpFormatEtc = NULL;
	
	SCODE sc;
	
	sc = ::CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes);
	if (sc != S_OK)
		return FALSE;
	ASSERT(lpLockBytes != NULL);
	
	sc = ::StgCreateDocfileOnILockBytes(lpLockBytes,
		STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, &m_lpStorage);
	if (sc != S_OK)
	{
		VERIFY(lpLockBytes->Release() == 0);
		lpLockBytes = NULL;
		return FALSE;
	}
	ASSERT(m_lpStorage != NULL);
	
	// fill in FORMATETC struct
	FORMATETC formatEtc;
	lpFormatEtc = &formatEtc;
	lpFormatEtc->cfFormat = cfFormat;
	lpFormatEtc->ptd = NULL;
	lpFormatEtc->dwAspect = DVASPECT_CONTENT;
	lpFormatEtc->lindex = -1;
	lpFormatEtc->tymed = TYMED_NULL;
	
	// attempt to create the object
	m_pRichEditOle->GetClientSite(&m_lpClientSite);
//	
	sc = ::OleCreateFromFile(clsid, T2COLE(lpszFileName),
		IID_IUnknown, OLERENDER_DRAW, lpFormatEtc, m_lpClientSite, m_lpStorage,
		(void**)&m_lpObject);

	if (sc != S_OK)
		return FALSE;
	
	// m_lpObject is currently an IUnknown, convert to IOleObject
	if (m_lpObject != NULL)
	{
		LPUNKNOWN lpUnk = m_lpObject;
		lpUnk->QueryInterface(IID_IOleObject, (void**)&m_lpObject);
		lpUnk->Release();
		if (m_lpObject == NULL)
			return FALSE;
	}
	
	// all items are "contained" -- this makes our reference to this object
	//  weak -- which is needed for links to embedding silent update.
	OleSetContainedObject(m_lpObject, TRUE);
	
	ASSERT_VALID(this);
	return TRUE;
	
}
BOOL CMTextDlg::InsertObject()
{
	REOBJECT reobject;
	ZeroMemory(&reobject, sizeof(REOBJECT));
	reobject.cbStruct = sizeof(REOBJECT);
	
	CLSID clsid;
	SCODE sc = m_lpObject->GetUserClassID(&clsid);
	if (sc != S_OK)
		return FALSE;
	
	reobject.clsid = clsid;
	reobject.cp = REO_CP_SELECTION;
	reobject.dvaspect = DVASPECT_CONTENT;
	reobject.dwFlags =REO_DYNAMICSIZE|REO_BELOWBASELINE;
	reobject.dwUser = 0;
	reobject.poleobj = m_lpObject;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -