CEdit控件 [英] CEdit Control

查看:75
本文介绍了CEdit控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VC 5.0中基于对话框的应用程序中有一个大型的Multiline CEdit.我如何使其接受Tab键作为编辑"选项卡,而不是作为跳转到下一个控件的命令. Rc编辑器有一个"WantReturn"选项,而不是"Want Tab"选项.

I have a large Multiline CEdit in a Dialog based App in VC 5.0. How do I make it accept a Tab Key as an ''Edit''tab, rather than as a command to jump to the next control. The Rc Editor has an option for ''WantReturn'' but not for ''Want Tab''

推荐答案

下面给出的是我所说的"hack" ",但它可以正常工作(您必须检查是否有任何不希望的副作用:=).如果您找到更好/理想的解决方案,请在此处发布.

1.子类化编辑控件

.h
==
Given below is what I would call a ''hack'' but it works ( you have to check for any undesirable side-affects :=). If you find a better/ ideal solution please post it here.

1. subclass the edit control

.h
==
class CPDEdit: public CEdit
{
public:
	DECLARE_MESSAGE_MAP()
	afx_msg LRESULT OnKeyDown(WPARAM, LPARAM);
	afx_msg LRESULT OnKeyUp(WPARAM, LPARAM);
};



.cpp
====



.cpp
====

BEGIN_MESSAGE_MAP(CPDEdit, CEdit)
    ON_MESSAGE(WM_KEYDOWN, OnKeyDown)
    ON_MESSAGE(WM_KEYUP, OnKeyUp)
END_MESSAGE_MAP()







LRESULT CPDEdit::OnKeyDown(WPARAM w, LPARAM l) {
	if (''\t'' == w) {
		return 0;
	}
	return DefWindowProc(WM_KEYDOWN, w, l);
}
LRESULT CPDEdit::OnKeyUp(WPARAM w, LPARAM l) {
	if (''\t'' == w ) {
		DWORD s = GetSel();
		if (0 != s && LOWORD(s) == HIWORD(s)) {
			ReplaceSel(_T("\t"));
                        return 0;
		}
	}
        return DefWindowProc(WM_KEYUP, w, l);
}



2.从对话框资源编辑器中为控件类型的编辑"创建一个成员变量(右键单击该控件,然后选择添加变量...".
3.在对话框标题中将此变量的类型从CEdit手动更改为CPDEdit.



2. Create a member variable for the Edit of control type from the dialog resource editor (right-click the control and select "Add variable ...".
3. Change the type of this variable from CEdit to CPDEdit manually in the dialog header.


Given below is what I would call a 'hack



我不会认为这是hack!您从CEdit类派生了一个New类,该类具有记录的和指定的行为.这就是CPP和MFC以及WndProc系统的目的.但这并不意味着所有方面的最佳意图都不会出错!很高兴地说,在我的情况下有效.

谢谢,


布拉姆.



I would not consider this a hack! You derrived a New class from the CEdit Class, with documented and specified behaviour. This is what both CPP and MFC, and also the WndProc system intended. Does not mean that the best of intentions on all fronts won''t go wrong though! Happy to say, works in my case.

Thanks,


Bram.


这篇关于CEdit控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆