[已解决]求高手修改代码解决利用回车切换下一个控件焦点
本帖最后由 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 比较常见的是tab切换控件焦点 是的,我知道tab但是毕竟用enter键要方便顺手一些,我看论坛中有人提议用$BS_DEFPUSHBUTTON解决,可是我没明白怎么用,有人能帮帮我么? #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
If $hc = GUICtrlGetHandle($User) Then GUICtrlSetState($Password, $GUI_FOCUS)
If $hc = GUICtrlGetHandle($Password) Then GUICtrlSetState($Button1, $GUI_FOCUS)
EndIf
EndIf
EndFunc ;==>_WM_COMMAND 谢谢版主afan的超强答案!问题得以完美解决。 回复 4# afan
不错,高手就是高手。学习了。 正要用到这个,谢谢 太感谢了,正要用到这个。 学习,学习,就缺这个了。刚刚好、感谢
页:
[1]