找回密码
 加入
搜索
查看: 3859|回复: 11

[AU3基础] 【已解决】 请教高手GUICtrlCreateInput提示问题

  [复制链接]
发表于 2010-11-1 00:14:12 | 显示全部楼层 |阅读模式
本帖最后由 ssjoe 于 2010-11-5 00:20 编辑

请教高人帮忙解决输入框输入后为何会闪过不停,同时清除第一框的时候按钮灰色,为何清除第二框的时候按钮不变灰色,希望高人帮忙解决一下!
还有可否限制第一框只可以输入数字!
#include <GuiConstants.au3>
Opt("GUIOnEventMode", 1)

Global Const $WM_NOTIFY = 0x004E
Global Const $WM_CTLCOLOREDIT = 0x0133

$Form1 = GUICreate("Form1", 494, 345, 192, 114)
GUISetOnEvent($GUI_EVENT_CLOSE, "main")
$Button1 = GUICtrlCreateButton("Button1", 320, 64, 121, 25, 0)

$Label1 = GUICtrlCreateLabel("第一框:", 48, 64, 60, 28)
$Label2 = GUICtrlCreateLabel("第二框:", 48, 94, 60, 28)
$Label3 = GUICtrlCreateLabel("", 158, 34, 60, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Input1 = GUICtrlCreateInput("", 128, 64, 169, 25)
$Input2 = GUICtrlCreateInput("", 128, 94, 169, 25)
GUISetState()

GUICtrlSetOnEvent($Button1, "main")

GUIRegisterMsg($WM_NOTIFY, "test")
GUIRegisterMsg($WM_CTLCOLOREDIT, "test")

$getfocus=ControlFocus ( "Form1", "", $Input1)


While 1
        Sleep(1000)
WEnd

Func main()

        Switch @GUI_CtrlId
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        MsgBox(0,"",GUICtrlRead($Input1))
                        
        EndSwitch
                
EndFunc
        
Func test()
        $Select1 = GUICtrlRead($Input1)
        If  $Select1= "" Then
                If BitAND(GUICtrlGetState($Button1), $GUI_ENABLE) Then
                        GUICtrlSetState($Button1, $GUI_DISABLE)                        
                        GUICtrlSetData($Label3,"")
                        GUICtrlSetData($Input2,"")
                Endif

        Else
                If BitAND(GUICtrlGetState($Button1), $GUI_DISABLE) Then GUICtrlSetState($Button1, $GUI_ENABLE)
                If BitAND(GUICtrlGetState($Select1),$GUI_FOCUS) then
                        GUICtrlSetData($Label3,GUICtrlRead($Input1))
                        GUICtrlSetData($Input2,GUICtrlRead($Input1))
                Endif
        EndIf              
EndFunc

评分

参与人数 1金钱 +10 收起 理由
afan + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

发表于 2010-11-1 02:11:14 | 显示全部楼层
#include <GuiConstants.au3>
#include <EditConstants.au3>

Opt("GUIOnEventMode", 1)

Global Const $WM_NOTIFY = 0x004E
Global Const $WM_CTLCOLOREDIT = 0x0133
$Form1 = GUICreate("Form1", 494, 345, 192, 114)
GUISetOnEvent($GUI_EVENT_CLOSE, "main")
$Button1 = GUICtrlCreateButton("Button1", 320, 64, 121, 25, 0)
$Label1 = GUICtrlCreateLabel("第一框:", 48, 64, -1, 28)
$Label2 = GUICtrlCreateLabel("第二框:", 48, 94, -1, 28)
$Label3 = GUICtrlCreateLabel("", 158, 34, 400, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Input1 = GUICtrlCreateInput("", 128, 64, 169, 25, $ES_NUMBER)
$Input2 = GUICtrlCreateInput("", 128, 94, 169, 25)
GUISetState()
GUICtrlSetOnEvent($Button1, "main")
GUIRegisterMsg($WM_NOTIFY, "test")
GUIRegisterMsg($WM_CTLCOLOREDIT, "test")
$getfocus = ControlFocus("Form1", "", $Input1)

While 1
        Sleep(1000)
WEnd

Func main()
        Switch @GUI_CtrlId
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        MsgBox(0, "", GUICtrlRead($Input1))
        EndSwitch
EndFunc   ;==>main

Func test($hWnd, $Msg, $wParam, $lParam)
        Local $nNotifyCode = BitShift($wParam, 16)
        Switch $lParam
                Case GUICtrlGetHandle($Input1)
                        $Select1 = GUICtrlRead($Input1)
                        If $Select1 = "" Then
                                If BitAND(GUICtrlGetState($Button1), $GUI_ENABLE) Then
                                        GUICtrlSetState($Button1, $GUI_DISABLE)
                                        GUICtrlSetData($Label3, "")
                                        GUICtrlSetData($Input2, "")
                                EndIf

                        Else
                                If BitAND(GUICtrlGetState($Button1), $GUI_DISABLE) Then GUICtrlSetState($Button1, $GUI_ENABLE)
                                If BitAND(GUICtrlGetState($Select1), $GUI_FOCUS) Then
                                        GUICtrlSetData($Label3, GUICtrlRead($Input1))
                                        GUICtrlSetData($Input2, GUICtrlRead($Input1))
                                EndIf
                        EndIf
        EndSwitch
EndFunc   ;==>test

评分

参与人数 1金钱 +25 收起 理由
afan + 25

查看全部评分

 楼主| 发表于 2010-11-1 19:49:43 | 显示全部楼层
谢谢您。。。但是问题还没有得到解决。第一个框现在只可以输入数字了,但能否不要提示呢?
还有能否帮忙解决第二个框为空时不要自动恢复第一个框的值,还有第二个框为空时按钮变灰色!
 楼主| 发表于 2010-11-1 22:59:53 | 显示全部楼层
怎么没有热心人回复我一下啊?是否我表达不够清楚呢?
发表于 2010-11-1 23:19:12 | 显示全部楼层
这需要钩子在修改数据前拦截(过滤),论坛有相关帖子,参考P版的经典代码
http://www.autoitx.com/forum.php ... amp;fromuid=7644923
 楼主| 发表于 2010-11-2 01:00:41 | 显示全部楼层
能否用别的方法来处理这个问题呢?我的目的就是想第一个$Input1输入的值传到$Input2和$Label3,同时按钮可以启用,当清除$Input2值改变后$Input1、$Label3、按钮都不变,但$Input1值改变,其它都同时变,但当清除$Input2值后按钮同是变灰色,大虾们能否帮我实现这个功能呢?
 楼主| 发表于 2010-11-2 14:58:36 | 显示全部楼层
怎么还没有人能帮上我这个忙啊?痛苦啊。。。
发表于 2010-11-2 15:57:59 | 显示全部楼层
奇怪的设计需求。
发表于 2010-11-2 16:12:29 | 显示全部楼层
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
Opt("GUIOnEventMode", 0)
$flag = ""
$Form1 = GUICreate("Form1", 494, 345, 192, 114)
$Button1 = GUICtrlCreateButton("Button1", 320, 64, 121, 25, 0)
$Label1 = GUICtrlCreateLabel("第一框:", 48, 64, 60, 28)
$Label2 = GUICtrlCreateLabel("第二框:", 48, 94, 60, 28)
$Label3 = GUICtrlCreateLabel("", 158, 34, 60, 28)
$Input1 = GUICtrlCreateInput("", 128, 64, 169, 25)
$Input2 = GUICtrlCreateInput("", 128, 94, 169, 25)
GUISetState()

While 1

        $msg = GUIGetMsg()
        Switch $msg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        MsgBox(0, "", GUICtrlRead($Input1))

        EndSwitch
        $Select1 = GUICtrlRead($Input1)
        If $Select1 = "" Then
                If BitAND(GUICtrlGetState($Button1), $GUI_ENABLE) = $GUI_ENABLE Then
                        GUICtrlSetState($Button1, $GUI_DISABLE)
                        GUICtrlSetData($Label3, "")
                        GUICtrlSetData($Input2, "")
                EndIf

        Else
                If BitAND(GUICtrlGetState($Button1), $GUI_DISABLE) = $GUI_DISABLE Then
                        GUICtrlSetState($Button1, $GUI_ENABLE)
                EndIf
                If GUICtrlRead($Input1) <> $flag Then
                        GUICtrlSetData($Label3, GUICtrlRead($Input1))
                        GUICtrlSetData($Input2, GUICtrlRead($Input1))
                        $flag = GUICtrlRead($Input1)
                EndIf

        EndIf

WEnd

评分

参与人数 1金钱 +20 收起 理由
ssjoe + 20 谢谢您的帮忙,问题已经解决了!

查看全部评分

 楼主| 发表于 2010-11-2 22:55:40 | 显示全部楼层
楼上的,真是太谢谢你了,但是还有一个小问题还没有得到解决,就是清空第二个框的时候按钮没变灰色!
能否帮忙再解决一下这个问题,真是万分感谢了!
 楼主| 发表于 2010-11-5 00:20:06 | 显示全部楼层
谢谢9楼您帮忙,我已经测试成功了!
发表于 2012-9-10 12:53:09 | 显示全部楼层
谢谢9楼
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-21 01:58 , Processed in 0.099275 second(s), 30 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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