使用win32 API的编辑(edit)控件

36 篇文章 0 订阅
截获输入,过滤控件的输入


========================================
WM_CHAR

由 TranslateMessage转换后产生

并且WM_CHAR都给了 edit控件(因为她也是一个窗口)


========================================

当用户往文本框中输入字符时,Windows 会给Edit控件的窗口函数发送 WM_CHAR 消息。
这个窗口函数本身寄生于 Windows 中,因此不能直接修改它。

但是我们可以重定向这个消息使之发送到我们自己编写的窗口处理函数。

如果自定义窗口要处理这个消息那就可以处理它,如果不处理就可以把这个消息转发到它原来窗口处理函数。

通过这种方式,自定义的窗口处理函数就把它自己插入到 Windows 系统和 Edit 控件之间。





调用函数SetWindowLong可以设置自己的窗口过程lpfnWndProc


为了调用函数 CallWindowProc,我们存储了原窗口函数地址






Re:使用win32 API的编辑(edit)控件 , 2007-09-03 17:27:13 by Johnny

Append Text to an Edit Control


Windows-based applications often use edit controls to display text.
Window应用程序通常使用edit空间来显示文本,这些应用程序有时候需要追加一些文本
到编辑空间的尾部,或者来替换一些存在的文本

有2种方式来完成
1)使用 EM_SETSEL 和 EM_REPLACESEL 消息
2)使用 带剪贴板的EM_SETSEL消息 附加文本到的编辑空间的缓冲区


Re:使用win32 API的编辑(edit)控件 , 2007-08-30 23:49:21 by Johnny

在编辑控件中追加字符的方法是,将 光标移动到最后

nTextLength=edit.GetWindowTextLength();

edit.SetSel(nTextLength,nTextLength); //移动插入光标到正文末尾


http://www.impcas.ac.cn/u......vcpptutorial/chap12_4.htm
http://www.vckbase.com/study/article/vc_chap/chap12_4.htm
http://www.vckbase.com/study/article/vc_chap/chap12.htm


Re:使用win32 API的编辑(edit)控件 , 2007-08-30 23:15:14 by Johnny

Writes a character to the single-line edit control and sends the EN_UPDATE and EN_CHANGE notification messages to the parent window.


Writes a character to the multiline edit control.


Handles the accelerator keys for standard functions, such as CTRL+C for copying and CTRL+V for pasting.


In multiline edit controls, also processes TAB, and CTRL+TAB keystrokes to move among the controls in a dialog box and to insert tabs into multiline edit controls. Uses the MessageBeep function for illegal characters.



===========================

The WM_CHAR message is posted to the window with the keyboard focus when a WM_KEYDOWN message is translated by the TranslateMessage function.

The WM_CHAR message contains the character code of the key that was pressed.

=========================


Modifying Text

The user can select, delete, or move text in an edit control. The system maintains an internal flag for each edit control indicating whether the content of the control has been modified. The system clears this flag when it creates the control and sets the flag whenever the text in the control is modified. An application can retrieve the modification flag by sending the control an EM_GETMODIFY message. The application can then set or clear the modification flag by sending the control an EM_SETMODIFY message. These messages apply to both single-line and multiline edit controls.





Replacing Text

An application can replace selected text in an edit control by sending the control an EM_REPLACESEL message with a pointer to the replacement text. If there is no current selection, EM_REPLACESEL inserts the replacement text at the insertion point. The application may receive an EN_ERRSPACE notification message if the replacement text exceeds the available memory. This message applies to both single-line and multiline edit controls.

An application can use EM_REPLACESEL to replace part of an edit control's text or the SetDlgItemText function to replace all of it.


使用win32 API的编辑(edit)控件 , 2007-08-30 21:49:28 by Johnny

描述win32编辑类,如何在一个windows应用中将其作为一个子窗口,一个自维护的简单文本编辑器。


编辑控件是一个非常好的子窗口控件,因为她提供一个自我维护的编辑区域,能响应所有的按键

有2种类型的编辑框
1)单行
2)多行,有滚动条,卷轴


CreateWindow将类设置为edit即可创建edit控件

ES_WANTRETURN标志告诉控件,我们不需要enter键执行默认的行为,而是加入一个回车字符。



建立一个类似于记事本的编辑器

CreateWindow( "edit", "",
WS_VISIBLE|WS_CHILD|WS_BORDER|WS_VSCROLL|WS_HSCROLL|
ES_MULTILINE|ES_WANTRETURN|ES_AUTOHSCROLL|ES_AUTOVSCROLL,
0, 0, nClientWidth, nClientHeight, hwnd, (HMENU)nEditID, hInstance, NULL);



使用
GetDlgItemText(hwnd, nEditID, szString, nMax);
从编辑框中取得文字


SendMessage( GetDlgItem( hwnd, nEditID), WM_GETTEXTLENGTH, 0, 0L)
可以取得 编辑框中当前 有 多少个字符




当编辑内容改变时,edit控件可以更新父窗口


在WM_COMMAND case下 处理这个参数
if (HIWORD(wParam) == EN_CHANGE && LOWORD(wParam) == nEditID)

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值