找回密码
 加入
搜索
查看: 1800|回复: 5

[AU3基础] 多个input控件,如何获取光标所在控件id【已解决】

[复制链接]
发表于 2017-4-19 14:39:08 | 显示全部楼层 |阅读模式
本帖最后由 fenhanxue 于 2017-4-19 23:16 编辑

有许多个input
鼠标任一点击其中一个后,点按钮,自动在当前的光标的位置插入字符A
应如何实现?
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 600, 400)
Global $Input[11][11];

For $i = 1 To 10
        For $j = 1 To 10
                $Input[$i][$j] = GUICtrlCreateInput('',40*$j,20*$i,38,18)
        Next
Next


$Button1 = GUICtrlCreateButton("在光标处插入字符A", 100, 300, 137, 25)
GUISetState(@SW_SHOW)


While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        GUICtrlSetData(控件id,'A',1);如何        判断        控件id 为$Input[$i][$j] 里面的具体哪一个
        EndSwitch
WEnd
发表于 2017-4-19 15:24:04 | 显示全部楼层
我是个新手,是不是按1检测鼠标在哪个控件上?不知道是不是这样的意思?

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("Form1", 363, 177, 445, 329)
$Input1 = GUICtrlCreateInput("", 16, 32, 329, 21)
$Input2 = GUICtrlCreateInput("", 16, 64, 329, 21)
$Input3 = GUICtrlCreateInput("", 16, 96, 329, 21)


HotKeySet('1', 'get_info')
GUISetState(@SW_SHOW)
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
        EndSwitch
WEnd

Func get_info()
        If ControlGetFocus($Form1) = 'Edit1' Then
                MsgBox(0, 0, '当前光标选的是第一个控件')
        ElseIf ControlGetFocus($Form1) = 'Edit2' Then
                MsgBox(0, 0, '当前光标选的是第二个控件')
        ElseIf ControlGetFocus($Form1) = 'Edit3' Then
                MsgBox(0, 0, '当前光标选的是第三个控件')
        EndIf
EndFunc   ;==>get_info

评分

参与人数 1金钱 +20 收起 理由
kk_lee69 + 20

查看全部评分

发表于 2017-4-19 15:25:42 | 显示全部楼层
看了看帮助,然后模仿例子写的。。你可以参照一下帮助。
ControlGetFocus函数
返回指定窗口键盘焦点控件的类别名
 楼主| 发表于 2017-4-19 16:21:03 | 显示全部楼层
回复 3# 229989799


    谢谢,另寻求更好的办法
        Local $temp_classnn = ControlGetFocus($GUI)
        Local $temp_h = ControlGetHandle($GUI,'','[classNN:'&$temp_classnn&']')
        
        for $i = 1 to 10
                for $j = 1to 10
                        if  GUICtrlGetHandle($input[$i][$j]) = $temp_h  then
                                msgbox(0,'$i','$j')
                        endif
                next
        next
发表于 2017-4-19 18:22:45 | 显示全部楼层
前两天有个提问,如何几个INPUT值有一个变动时,其它也相应变化..........原理上也可以这样实现的.
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Local $cur_Input
$Form1 = GUICreate("Form1", 600, 400)
Global $Input[11][11];

For $i = 1 To 10
        For $j = 1 To 10
                $Input[$i][$j] = GUICtrlCreateInput('',40*$j,20*$i,38,18)
        Next
Next


$Button1 = GUICtrlCreateButton("在光标处插入字符A", 100, 300, 137, 25)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                                        Case $Button1
                                                MsgBox(0, '', '当前的焦点所在的INPUT(ID): ' & $cur_Input, 1)
                        GUICtrlSetData($cur_Input,'A',1);如何        判断        控件id 为$Input[$i][$j] 里面的具体哪一个
        EndSwitch
WEnd
Func WM_COMMAND($hWnd, $msg, $wParam, $lParam)
        Local $nNotifyCode = BitShift($wParam, 16)
        If $nNotifyCode = $EN_SETFOCUS Then $cur_Input = BitAND($wParam, 0x0000FFFF)
EndFunc

评分

参与人数 2金钱 +20 收起 理由
fenhanxue + 10 感激
xzf680 + 10 很好,学习了

查看全部评分

 楼主| 发表于 2017-4-19 23:15:58 | 显示全部楼层
回复 5# Alam


    非常感谢帮忙,此代码正解
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-3-29 20:40 , Processed in 0.086288 second(s), 28 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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