如何禁止选中CEDIT内的内容 我想禁止鼠标选中CEDIT里面的内容(包括ctrl+'A'),这个该怎么做? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 控件设置成Enable = false 如果disable不够的话,子类化这个CEdit,然后屏蔽所以你不希望的操作 蓉蓉,做不到的。readonly也不行,enable也不行。没有办法啦。 用子类化的方法,自己写一个Edit类,继承自CEdit,加入你自己的处理即可。 你可以试试在PreTranslateMessage中拦截Ctrl+A,并屏蔽。 if(pMsg->message==WM_KEYDOWN){ if(GetAsyncKeyState(VK_LCONTROL)&&(pMsg->wParam=='A')) { return TRUE; }}可以屏蔽Ctrl+A 虽然屏蔽Ctrl+A,但是鼠标还是可以选中。要禁止鼠标选中的话,Disable那个控件才可以。但是你又需要键盘输入,那你只有自己写一个Edit类了。 subclass 了。早跟你说了。 楼上的CTRL键有左右两个,另,我想搂住的意思是想不被选中,也就是要屏蔽CEdit::SetSel函数,我觉得是否在派生类中重载一下setsel函数就ok了呢? 没有试验,不知道可行不 setsel是重载的吗........只有subclass,别无他法。或者自己写一个新的CXEdit类。其实在subclass类里面,拦截所有的鼠标消息,过滤不需要的键盘消息,应该可以吧。没做过,呵呵。 为什么不用CRichEditCtrlHideSelection用此函数隐藏试试 子类化这个CEdit类./******************SubEdit.h************************************/#if !defined(AFX_SUBEDIT_H__999D8DB4_CF48_4857_B86B_D5EEABE0279F__INCLUDED_)#define AFX_SUBEDIT_H__999D8DB4_CF48_4857_B86B_D5EEABE0279F__INCLUDED_#if _MSC_VER > 1000#pragma once#endif // _MSC_VER > 1000// SubEdit.h : header file///////////////////////////////////////////////////////////////////////////////// CSubEdit windowclass CSubEdit : public CEdit{// Constructionpublic: CSubEdit();// Attributespublic:// Operationspublic:// Overrides // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CSubEdit) //}}AFX_VIRTUAL// Implementationpublic: virtual ~CSubEdit(); // Generated message map functionsprotected: //{{AFX_MSG(CSubEdit) afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags); //}}AFX_MSG DECLARE_MESSAGE_MAP()};///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_SUBEDIT_H__999D8DB4_CF48_4857_B86B_D5EEABE0279F__INCLUDED_)/******************SubEdit.cpp**********************************/// SubEdit.cpp : implementation file//#include "stdafx.h"#include "Wgj.h"#include "SubEdit.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CSubEditCSubEdit::CSubEdit(){}CSubEdit::~CSubEdit(){}BEGIN_MESSAGE_MAP(CSubEdit, CEdit) //{{AFX_MSG_MAP(CSubEdit) ON_WM_CHAR() //}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CSubEdit message handlersvoid CSubEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { // TODO: Add your message handler code here and/or call default if(nChar>=0x30 && nChar<=0x39 || nChar=='.' || nChar==0x08)//0x08=回退键 { CEdit::OnChar(nChar, nRepCnt, nFlags); //只允许特定的按键通过// nChar=nChar+0x10;// DefWindowProc(WM_CHAR,(WPARAM)nChar,(LPARAM)(nRepCnt|(nFlags<<16))); //此行却可以改变一个输入字符为其它字符 }} 用CStatic吧.标签控件, 不能选定了吧! 哈哈哈.... 求:子对话框和父对话框之间发送控件消息的处理讲解和示例 基于位图的进度条 CStringArray问题,郁闷啊,大家帮忙啊,谢谢 如何通过并口进行文本和图像的传输 为什么读取INI文件内容不能成功 listen(...)可以接受的最大用户数目为多少? 在编写dll的环境下,调用那个函数可以获得当前路径? COM/DCOM组件的注册问题,请大家指教 有谁用过或听过Business Objects软件吗? OpenCV2.4.8 VC2010 MFC 内存泄露 求UpdateResource的例子,注:要象资源中添加数据的做法,而不是更新。谢谢 到底咋的了
{ if(GetAsyncKeyState(VK_LCONTROL)&&(pMsg->wParam=='A'))
{
return TRUE;
}
}可以屏蔽Ctrl+A
HideSelection
用此函数隐藏试试
#if !defined(AFX_SUBEDIT_H__999D8DB4_CF48_4857_B86B_D5EEABE0279F__INCLUDED_)
#define AFX_SUBEDIT_H__999D8DB4_CF48_4857_B86B_D5EEABE0279F__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// SubEdit.h : header file
///////////////////////////////////////////////////////////////////////////////
// CSubEdit windowclass CSubEdit : public CEdit
{
// Construction
public:
CSubEdit();// Attributes
public:// Operations
public:// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CSubEdit)
//}}AFX_VIRTUAL// Implementation
public:
virtual ~CSubEdit(); // Generated message map functions
protected:
//{{AFX_MSG(CSubEdit)
afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
//}}AFX_MSG DECLARE_MESSAGE_MAP()
};///////////////////////////////////////////////////////////////////////////////{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_SUBEDIT_H__999D8DB4_CF48_4857_B86B_D5EEABE0279F__INCLUDED_)
/******************SubEdit.cpp**********************************/
// SubEdit.cpp : implementation file
//#include "stdafx.h"
#include "Wgj.h"
#include "SubEdit.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/////////////////////////////////////////////////////////////////////////////
// CSubEditCSubEdit::CSubEdit()
{
}CSubEdit::~CSubEdit()
{
}
BEGIN_MESSAGE_MAP(CSubEdit, CEdit)
//{{AFX_MSG_MAP(CSubEdit)
ON_WM_CHAR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
// CSubEdit message handlersvoid CSubEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
if(nChar>=0x30 && nChar<=0x39 || nChar=='.' || nChar==0x08)//0x08=回退键
{
CEdit::OnChar(nChar, nRepCnt, nFlags);
//只允许特定的按键通过
// nChar=nChar+0x10;
// DefWindowProc(WM_CHAR,(WPARAM)nChar,(LPARAM)(nRepCnt|(nFlags<<16)));
//此行却可以改变一个输入字符为其它字符
}
}
标签控件, 不能选定了吧! 哈哈哈....