找回密码
 加入
搜索
查看: 2919|回复: 7

[AU3基础] [已解决]如何获取焦点所在控件的句柄

  [复制链接]
发表于 2012-1-11 11:00:19 | 显示全部楼层 |阅读模式
本帖最后由 沧海笑 于 2012-1-12 11:08 编辑

焦点是在不同的控件之间变换的,如何能获取到焦点所在控件的句柄呢?
发表于 2012-1-11 16:37:18 | 显示全部楼层
本帖最后由 半芯竹 于 2012-1-11 16:39 编辑
;检索具有键盘焦点的窗口句柄 :_WinAPI_GetFocus()
#include <WinAPI.au3>
#include <GUIConstantsEx.au3>
Opt('MustDeclareVars', 1)
_Main()
Func _Main()
    Local $gui, $msg, $btnFocus, $win, $text
    $gui = GUICreate("__WinAPI_GetFocus Example", 200, 200)
    $btnFocus = GUICtrlCreateButton("Get Focus", 50, 85, 100, 30)
    GUISetState(@SW_SHOW)
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                Exit
            Case $msg = $btnFocus
                $win = _WinAPI_GetFocus()
                $text = "Full Title: " & WinGetTitle($win) & @LF
                $text &= "Full Text: " & WinGetText($win) & @LF
                $text &= "Handle: " & WinGetHandle($win) & @LF
                $text &= "Process: " & WinGetProcess($win) & @LF
                MsgBox(0, "", $text)
        EndSelect
    WEnd
EndFunc   ;==>_Main
你可以修改代码为循环检测……
发表于 2012-1-11 18:25:57 | 显示全部楼层
本帖最后由 xiehuahere 于 2012-1-11 18:27 编辑

楼主问的是控件而不是窗口。

用ControlGetFocus得到当前拥有焦点的控件的ClassNameNN(类别名),然后再用ControlGetHandle就可以获取控件句柄了。
其中,ControlGetHandle里的控件ID参数使用ClassNameNN(类别名)。
发表于 2012-1-11 19:28:13 | 显示全部楼层
ControlGetHandle 具体看帮助文件。
发表于 2012-1-11 21:48:30 | 显示全部楼层
回复 3# xiehuahere


    你看懂代码没有,就是获取BUTTON控件的句柄。。
 楼主| 发表于 2012-1-12 11:02:25 | 显示全部楼层
回复 3# xiehuahere

谢谢,经测试可用
 楼主| 发表于 2012-1-12 11:06:41 | 显示全部楼层
回复 2# 半芯竹

_WinAPI_GetFocus()在你的例子里直接定位到了button上,
但是在更多的情况是直接定位到窗口上去了,具体为什么还不清楚
发表于 2012-1-12 16:33:32 | 显示全部楼层
_WinAPI_GetFocus()本来就是用于检索具有键盘焦点的窗口句柄。
他这就是帮助里的例子。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-22 23:28 , Processed in 0.079762 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表