使用编辑控件 [英] Working with edit controls

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

问题描述

我知道如何将焦点设置到编辑控件,但是有没有办法检查编辑控件是否具有焦点?

解决方案

使用 Getfocus [ http://msdn.microsoft.com/zh-我们/library/windows/desktop/ms646312%28v=vs.85%29.aspx [ http://msdn.microsoft.com/zh-我们/library/windows/desktop/ms646294%28v=vs.85%29.aspx [

DrBones69问:

我知道如何将焦点设置到编辑控件,但是有没有办法检查编辑控件是否具有焦点? /blockquote>
这将是另一种方式.可以获取CWnd::GetFocus,但仍将结果的HWND与相关控件的HWND进行比较.请参阅:
http://msdn.microsoft.com/zh-CN/library/f9fd0z3x%28v = vs.100%29.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/bcs64shx.aspx [ ^ ].

在更一般的情况下,最好使用CWnd::GetSafeHwnd,但是如果没有聚焦,结果CWnd::GetFocus将已经返回NULL,并且应该为NULL测试该结果.无论如何,另请参见:
http://msdn.microsoft.com/en-us/library/d64ehwhz.aspx [ ^ ].

—SA


I know how to set the focus to an edit control, but is there a way to check if an edit control has focus?

解决方案

Use the Getfocus[^] function to get the windows that currently has the input focus and compare the result with the edit control your using.


I guess you found out the function SetFocus:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646312%28v=vs.85%29.aspx[^].

If you did, I don''t know how could you miss GetFocus referenced from that page:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms646294%28v=vs.85%29.aspx[^].

The focus means keyboard focus; and only one control at a time in the whole system can have the focus. So, you find out HWND of the window which currently has focus and compare with HWND of the control you are interested in. If they are the same, your control is currently focused.

[EDIT]

DrBones69 asked:

I know how to set the focus to an edit control, but is there a way to check if an edit control has focus?


This would be another way. One can get CWnd::GetFocus, but still compare HWND of the result with HWND of the control in question. Please see:
http://msdn.microsoft.com/en-US/library/f9fd0z3x%28v=vs.100%29.aspx[^],
http://msdn.microsoft.com/en-us/library/bcs64shx.aspx[^].

In more general case, it''s good to use CWnd::GetSafeHwnd, but the result CWnd::GetFocus will already return NULL in case of none is focused, and this result should be tested for NULL. Anyway, see also:
http://msdn.microsoft.com/en-us/library/d64ehwhz.aspx[^].

—SA


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

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