找回密码
 加入
搜索
查看: 8101|回复: 9

[AU3基础] 鼠标点击输入框时怎么自动清除输入框内容[已解决】

  [复制链接]
发表于 2012-12-19 11:20:31 | 显示全部楼层 |阅读模式
本帖最后由 765058729 于 2012-12-31 14:56 编辑

$Input1 = GUICtrlCreateInput("浏览或拖曳一个文件到这里", 8, 8, 297, 21)
请问怎么让鼠标点击时自动清除
发表于 2012-12-19 11:50:33 | 显示全部楼层
if guictrlgetstate($input) = $GUI_FOCUS then guictrlsetdata($input, '')
 楼主| 发表于 2012-12-19 11:58:51 | 显示全部楼层
本帖最后由 765058729 于 2012-12-19 12:00 编辑
if guictrlgetstate($input) = $GUI_FOCUS then guictrlsetdata($input, '')
netegg 发表于 2012-12-19 11:50

大哥,不行啊,
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_Icon=333.ico
#AutoIt3Wrapper_OutFile=winren.exe
#AutoIt3Wrapper_UseUPX=n
#AutoIt3Wrapper_Res_Comment=情無独钟
#AutoIt3Wrapper_Res_Description=情無独钟
#AutoIt3Wrapper_Res_FileVersion=2.0.0.7
#AutoIt3Wrapper_Res_FileVersion_AutoIncrement=y
#AutoIt3Wrapper_Res_LegalCopyright=2.0.0.0
#AutoIt3Wrapper_Res_SaveSource=y
#AutoIt3Wrapper_Res_requestedExecutionLevel=highestAvailable
#AutoIt3Wrapper_Run_Tidy=y
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ACN_HASH.au3>
Global $Hash, $FileHandle, $Filename, $Buffersize = 0x20000
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("畸形目录管理", 313, 35, -1, 1, -1, $WS_EX_ACCEPTFILES)
$Button1 = GUICtrlCreateButton("", 0, 0, 0, 0)
$Input1 = GUICtrlCreateInput("浏览或拖曳一个文件到这里", 8, 8, 297, 21)
Dim $Form1_AccelTable[1][2] = [["{ENTER}", $Button1]]
GUISetAccelerators($Form1_AccelTable)
GUICtrlSetState(-1, 8)
$Filename = GUICtrlRead($Input1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
WinSetOnTop($Form1, "", 1)
FileInstall("renplas.exe", "c:\windows\renplas.exe", 1)
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        $strInput1 = StringLower(GUICtrlRead($Input1))
                        If $strInput1 = "" Then
                                MsgBox(0 + 16 + 262144, "警告", "您没有输入任何内容!")
                        Else
                                $a = GUICtrlRead($Input1) ;原来的名字
                                $c = StringTrimRight($a, 1);不带点名字
                                $b = StringRight($a, 1) ;最后一位
                                If StringInStr($b, ".") Then
                                        Run("renplas.exe  " & $a & " " & $c & "", "", @SW_HIDE)
                                        Sleep(1000)
                                        FileSetAttrib($c, "-h-s-r")
                                Else
                                        Run("renplas.exe  " & $a & " " & $a & ".", "", @SW_HIDE)
                                EndIf
                        EndIf
                Case $GUI_EVENT_DROPPED
                        $_Filename = ControlCommand($Form1, '', $Input1, 'GetSelected', '')
                        If StringInStr($_Filename, "|") <> 0 Then
                                GUICtrlSetData($Input1, "浏览或拖曳一个文件到这里")
                                GUICtrlSetData($Input1, $Filename)
                        Else
                                GUICtrlSetData($Input1, $_Filename)
                                $a = GUICtrlRead($Input1) ;原来的名字
                                $c = StringTrimRight($a, 1);不带点名字
                                $b = StringRight($a, 1) ;最后一位
                                If StringInStr($b, ".") Then
                                        Run("renplas.exe  " & $a & " " & $c & "", "", @SW_HIDE)
                                Else
                                        Run("renplas.exe  " & $a & " " & $a & ".", "", @SW_HIDE)
                                EndIf
                        EndIf
        EndSwitch
WEnd
我还被是贴上源码吧
发表于 2012-12-19 14:48:02 | 显示全部楼层
本帖最后由 小影 于 2012-12-19 16:03 编辑

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
Func WM_COMMAND($hwnd, $wmsg, $wparam, $wlparam)
        $wcode = BitShift($wparam, 16)
        $wid = BitAND($wparam, 0x000FFFF)
        Switch $wid
                Case $Input1
                        If $wcode = $EN_SETFOCUS Then
                                GUICtrlSetData($Input1, "")
                        EndIf
        EndSwitch
EndFunc   ;==>WM_COMMAND


控件$input1获取焦点的时候,清空控件内容!
调整下代码为高亮
发表于 2012-12-19 14:50:48 | 显示全部楼层
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
说明一下,注册函数,需要放在While的前面,GUISetState(@SW_SHOW)的后面才能生效!
发表于 2012-12-19 15:09:47 | 显示全部楼层
回复 1# 765058729

不知道是不是你所需要的...

Local $NONEAACTIVECOLOR    = 0x989898
$GUI = GUICreate("检测输入框演示例子", 280, 150)

$Input_1 = GUICtrlCreateInput('', 15, 20, 250, 20)
GUICtrlSetColor(-1, $NONEAACTIVECOLOR)

$Input_2 = GUICtrlCreateInput('', 15, 60, 250, 20)
GUICtrlSetColor(-1, $NONEAACTIVECOLOR)

$Input_3 = GUICtrlCreateInput('', 15, 100, 250, 20)
GUICtrlSetColor(-1, $NONEAACTIVECOLOR)

$aboutButton = GUICtrlCreateButton("中文论坛", 100, 125, 60, 20)
$ExitButton = GUICtrlCreateButton("退出", 200, 125, 60, 20,1)
ControlFocus($GUI,'',$ExitButton)
GUISetState()

While 1
    _CheckInput($GUI, $Input_1, "点击这里输入内容")
    _CheckInput($GUI, $Input_2, "AU3最佳中文论坛")
    _CheckInput($GUI, $Input_3, "www.autoitX.com")
    Switch GUIGetMsg()
                Case $aboutButton
              ShellExecute("www.autoitX.com")
        Case $ExitButton, -3
            Exit
    EndSwitch
WEnd

Func _CheckInput($hWnd, $ID, $DefaultInputData)
    If _IsFocused($hWnd, $ID) And $DefaultInputData = GUICtrlRead($ID) Then
        GUICtrlSetData($ID, "")
        GUICtrlSetColor($ID, 0x000000)
    ElseIf  Not _IsFocused($hWnd, $ID)  And GUICtrlRead($ID) = "" Then
        GUICtrlSetData($ID, $DefaultInputData)
        GUICtrlSetColor($ID, $NONEAACTIVECOLOR)
    EndIf
EndFunc

Func _IsFocused($hWnd, $nCID)
    Return ControlGetHandle($hWnd, '', $nCID) = ControlGetHandle($hWnd, '', ControlGetFocus($hWnd))
EndFunc
 楼主| 发表于 2012-12-19 16:10:04 | 显示全部楼层
本帖最后由 765058729 于 2012-12-19 16:30 编辑

用二楼三楼的代码可以达到目的,可就是不能拖拽文件了
发表于 2012-12-23 17:54:07 | 显示全部楼层
学无止境...
发表于 2014-11-23 16:32:42 | 显示全部楼层
控件$input1获取焦点的时候,清空控件内容!
调整下代码为高亮
小影 发表于 2012-12-19 14:48



    谢谢 这个代码 可以的
发表于 2015-1-6 15:01:15 | 显示全部楼层
学习了  学无止境
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-28 12:25 , Processed in 0.088344 second(s), 22 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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