找回密码
 加入
搜索
查看: 6917|回复: 8

[GUI管理] [已解决]求高手修改代码解决利用回车切换下一个控件焦点

  [复制链接]
发表于 2013-2-21 22:23:31 | 显示全部楼层 |阅读模式
本帖最后由 silvay22 于 2013-2-22 21:17 编辑

使用回车键切换到下一控件焦点的源代码如下,但本代码有个缺陷就是必须输入数据后才能实现按回车键切换到下一控件的焦点上,我的问题是,能否在不输入数据的前提下,按回车键就能切换到下一控件
#include <GUIConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("test", 247, 158, 216, 188)
$Label1 = GUICtrlCreateLabel("用户名:", 16, 16, 43, 17)
$User = GUICtrlCreateInput("a", 72, 16, 169, 21)
GUICtrlSetState(-1,$GUI_FOCUS)
$Label2 = GUICtrlCreateLabel("密码:", 24, 56, 31, 17)
$Password = GUICtrlCreateInput("b", 72, 54, 169, 21)
$Button1 = GUICtrlCreateButton("确定", 80, 112, 89, 33)


GUISetState(@SW_SHOW)

Do
    Local $msg = GUIGetMsg()

    Select
        Case $msg = $User
            GUICtrlSetState($Password,$GUI_FOCUS)
        Case $msg = $Password
            GUICtrlSetState($Button1,$GUI_FOCUS)
        Case $msg = $Button1
            MsgBox(0, "You clicked on", "Exit")
        Case $msg = $GUI_EVENT_CLOSE
            MsgBox(0, "You clicked on", "Close")
    EndSelect
Until $msg = $GUI_EVENT_CLOSE Or $msg = $Button1
发表于 2013-2-21 22:27:58 | 显示全部楼层
比较常见的是tab切换控件焦点
 楼主| 发表于 2013-2-21 22:36:29 | 显示全部楼层
是的,我知道tab但是毕竟用enter键要方便顺手一些,我看论坛中有人提议用$BS_DEFPUSHBUTTON解决,可是我没明白怎么用,有人能帮帮我么?
发表于 2013-2-21 23:27:49 | 显示全部楼层
#include <GUIConstants.au3>

$Form1 = GUICreate('test', 247, 158)
$Label1 = GUICtrlCreateLabel('用户名:', 16, 16, 43, 17)
$User = GUICtrlCreateInput('a', 72, 16, 169, 21)
GUICtrlSetState(-1, $GUI_FOCUS)
$Label2 = GUICtrlCreateLabel('密码:', 24, 56, 31, 17)
$Password = GUICtrlCreateInput('b', 72, 54, 169, 21)
$Button1 = GUICtrlCreateButton('确定', 80, 112, 89, 33)
GUISetState(@SW_SHOW)
GUIRegisterMsg(0x111, '_WM_COMMAND')

Do
        Local $msg = GUIGetMsg()
Until $msg = -3 Or $msg = $Button1

Func _WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
        If Not $ilParam Then
                Local $hc, $aRt, $id
                If BitAND($iwParam, 0xFFFF) <> 1 Then
                        $id = BitAND($iwParam, 0xFFFF)
                        If $id = $User Then GUICtrlSetState($Password, $GUI_FOCUS)
                        If $id = $Password Then GUICtrlSetState($Button1, $GUI_FOCUS)
                Else
                        $aRt = DllCall('user32.dll', 'hwnd', 'GetFocus')
                        If Not @error Then $hc = $aRt[0]
                        If $hc = GUICtrlGetHandle($User) Then GUICtrlSetState($Password, $GUI_FOCUS)
                        If $hc = GUICtrlGetHandle($Password) Then GUICtrlSetState($Button1, $GUI_FOCUS)
                EndIf
        EndIf
EndFunc   ;==>_WM_COMMAND
 楼主| 发表于 2013-2-22 21:16:16 | 显示全部楼层
谢谢版主afan的超强答案!问题得以完美解决。
发表于 2013-6-3 12:40:14 | 显示全部楼层
回复 4# afan
不错,高手就是高手。学习了。
发表于 2014-1-7 15:19:37 | 显示全部楼层
正要用到这个,谢谢
发表于 2014-3-30 20:11:04 | 显示全部楼层
太感谢了,正要用到这个。
发表于 2014-7-14 13:58:08 | 显示全部楼层
学习,学习,就缺这个了。刚刚好、感谢
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-18 14:39 , Processed in 0.079770 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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