eidt控制是vc中经常使用的文本输入输出交互控制,有的时候,我们为了实现对输入,输出有特殊的操作过程,那么,原来的edit控制的功能也许就不一定能实现我们的要求,或者实现的不是那么灵活,因此,我们也经常在edit控件的基础上继承基类来做一些配生的子类情况下实现我们自己在工程中需要的特殊的要求。本文介绍一个可以带有菜单操作的edit类的实现过程,基础类eidt基类,在继承的子类上添加各个菜单操作功能,其中的菜单操作也是为了实现多edit中的文本进行各种文本的常规操作。
这个类的实现过程如下:
。h文件
#if !defined(AFX_MENUEDIT_H__8EA53611_FD2B_11D4_B625_D04FA07D2222__INCLUDED_) #define AFX_MENUEDIT_H__8EA53611_FD2B_11D4_B625_D04FA07D2222__INCLUDED_
#if _MSC_VER > 1000 #pragma once #endif
class CMenuEdit : public CEdit { public: CMenuEdit() {};
protected: virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam); afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
DECLARE_MESSAGE_MAP() };
#endif
。cpp文件
#include "stdafx.h" #include "MenuEdit.h"
#ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif
#define MES_UNDO _T("&Undo") #define MES_CUT _T("Cu&t") #define MES_COPY _T("&Copy") #define MES_PASTE _T("&Paste") #define MES_DELETE _T("&Delete") #define MES_SELECTALL _T("Select &All") #define ME_SELECTALL WM_USER + 0x7000
BEGIN_MESSAGE_MAP(CMenuEdit, CEdit) ON_WM_CONTEXTMENU() END_MESSAGE_MAP()
void CMenuEdit::OnContextMenu(CWnd* pWnd, CPoint point) { SetFocus(); CMenu menu; menu.CreatePopupMenu(); BOOL bReadOnly = GetStyle() & ES_READONLY; DWORD flags = CanUndo() && !bReadOnly ? 0 : MF_GRAYED; menu.InsertMenu(0, MF_BYPOSITION | flags, EM_UNDO, MES_UNDO);
menu.InsertMenu(1, MF_BYPOSITION | MF_SEPARATOR);
DWORD sel = GetSel(); flags = LOWORD(sel) == HIWORD(sel) ? MF_GRAYED : 0; menu.InsertMenu(2, MF_BYPOSITION | flags, WM_COPY, MES_COPY); <  
说明:本教程来源互联网或网友上传或出版商,仅为学习研究或媒体推广,wanshiok.com不保证资料的完整性。
1/2 1 2 下一页 尾页 |