如何给GUI input控件设置一个立即显示的Tip提示信息
本帖最后由 gapkiller 于 2011-2-26 11:43 编辑给自己创建的GUI 控件设置一个立即显示的tip提示
类似于下图所示:
我尝试过使用GUICtrlSetTip()
发现这个函数只有在鼠标移动到该控件上, 信息才能显示.
那么如何让这个tip立即显示呢?
===============================================================
补充:
加了$ES_NUMBER扩展风格的input控件, 在输入非number型数据时, 提示的错误信息直接指向输入光标所在的位置.
如果我们能够获得输入光标所在的位置, 这个应该好很多. #Include <GuiEdit.au3>
_GUICtrlEdit_ShowBalloonTip($hWnd, $sTitle, $sText, $iIcon) #include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#Region ### START Koda GUI section ### Form=c:\documents and settings\administrator\my documents\form1.kxf
$Form1 = GUICreate("test", 409, 260, 434, 170)
$Label1 = GUICtrlCreateLabel("X:", 40, 32, 86, 17)
$Input1 = GUICtrlCreateInput("", 120, 32, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER))
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
Local Const $EN_CHANGE = 0x300
Local $nNotifyCode = BitShift($wParam, 16)
Local $nID = BitAND($wParam, 0xFFFF)
Local $hCtrl = $lParam
If $nNotifyCode = $EN_CHANGE Then
If GUICtrlRead($input1)>169 Then ToolTip("输入数据太大",434+120+121,170+32+21,"出错",3,1)
EndIf
EndFunc ;==>MY_WM_COMMAND
路过,顶一个 本帖最后由 guang19831217 于 2011-2-25 20:00 编辑
支持一下,偶也在学习中#include <EditConstants.au3>
$Form1 = GUICreate("Form1", 633, 447, 192, 124)
$Input1 = GUICtrlCreateInput("", 95, 205, 129, 21,$ES_NUMBER)
GUICtrlSetLimit(-1, 9)
GUISetState(@SW_SHOW)
While 1
Sleep(10)
WEnd 楼主的意思是不是一开软件就显示tip信息?
借用一下楼上几位的代码
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#Region ### START Koda GUI section ### Form=c:\documents and settings\administrator\my documents\form1.kxf
$Form1 = GUICreate("test", 409, 260, 434, 170)
$Label1 = GUICtrlCreateLabel("X:", 40, 32, 86, 17)
$Input1 = GUICtrlCreateInput("", 120, 32, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER))
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
GUISetState(@SW_SHOW)
ToolTip("只能输入长度小于十位数字",434+120+121,170+32+21,"",3,1)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
Local Const $EN_CHANGE = 0x300
Local $nNotifyCode = BitShift($wParam, 16)
Local $nID = BitAND($wParam, 0xFFFF)
Local $hCtrl = $lParam
If $nNotifyCode = $EN_CHANGE Then
If StringLen(GUICtrlRead($input1))>10 Then
ToolTip("输入数据太大",434+120+121,170+32+21,"出错",3,1)
Else
ToolTip("",434+120+121,170+32+21,"出错",3,1)
EndIf
EndIf
EndFunc ;==>MY_WM_COMMAND 收藏。多谢各位分享。肯定有用处 代码收下了,谢谢.... 楼主的意思是不是一开软件就显示tip信息?
借用一下楼上几位的代码
gto250 发表于 2011-2-25 20:13 http://www.autoitx.com/images/common/back.gif
这个到不一定,
其实我是想在点击 OK button 之后提示这么一个信息,表示输入有误.
#Include
_GUICtrlEdit_ShowBalloonTip($hWnd, $sTitle, $sText, $iIcon)
afan 发表于 2011-2-26 13:30 http://www.autoitx.com/images/common/back.gif
啊, 我亲爱的afan....你太帅了. 我该怎么报答你呢? 本帖最后由 gapkiller 于 2011-2-26 16:13 编辑
为什么WinGetCaretPos ( ) 不能获得正确坐标呢??? 回复 11# gapkiller
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#Region ### START Koda GUI section ### Form=c:\documents and settings\administrator\my documents\form1.kxf
$Form1 = GUICreate("test", 409, 260, 434, 170)
$Label1 = GUICtrlCreateLabel("X:", 40, 32, 86, 17)
$Input1 = GUICtrlCreateInput("", 120, 32, 121, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER))
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
Local Const $EN_CHANGE = 0x300
Local $nNotifyCode = BitShift($wParam, 16)
Local $nID = BitAND($wParam, 0xFFFF)
Local $hCtrl = $lParam
If $nNotifyCode = $EN_CHANGE Then
If GUICtrlRead($Input1) > 169 Then
$caretpos = _Caret_GetPos()
ToolTip("输入数据太大", 434 + 120 + $caretpos, 170 + 32 + $caretpos + 21 * 2, "出错", 3, 3)
EndIf
EndIf
EndFunc ;==>MY_WM_COMMAND
Func _Caret_GetPos()
Local $POINT = DllStructCreate("long;long")
Local $Return
DllCall("User32.dll", "int", "GetCaretPos", "ptr", DllStructGetPtr($POINT))
$Return = DllStructGetData($POINT, 1)
$Return = DllStructGetData($POINT, 2)
Return $Return
EndFunc ;==>_Caret_GetPos
又学到了一招 都是高手,学习了 呵呵好像是只能输入数字的那个就可以
页:
[1]
2