【已解决】请教怎么捕获Input的鼠标点击事件?
本帖最后由 leenkon 于 2011-4-7 15:24 编辑请教一下高手,怎么捕获Input的鼠标点击事件?如下面,想要鼠标点击输入框则执行一个任务(例如弹出对话框)
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <Constants.au3>
#include <GUIListBox.au3>
#include <GuiStatusBar.au3>
#include <GuiToolbar.au3>
#include <StaticConstants.au3>
$xz1 = GUICtrlCreateInput("", 368, 560, 81, 21)
while 1
$nMsg = GUIGetMsg()
Switch $nMsg
case $xz1
************
EndSwitch
WEnd
while 1 鼠标点击输入框控件,势必会赋予其输入焦点,不妨通过这个来判断。 回覆 1# leenkon
参考http://www.autoitx.com/forum.php?mod=viewthread&tid=23182&extra=page%3D1%26amp%3Borderby%3Ddateline%26amp%3Bfilter%3D2592000
写了一个例子
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <winapi.au3>
#include <Constants.au3>
$Form1 = GUICreate("输入框点击例子", 341, 208, 192, 124)
$Input1 = GUICtrlCreateInput("点击我", 72, 40, 153, 33)
$wProcNew = DllCallbackRegister("_MyWindowProc", "ptr", "hwnd;uint;long;ptr")
$wProcOld = _WinAPI_SetWindowLong(GUICtrlGetHandle($Input1), $GWL_WNDPROC, DllCallbackGetPtr($wProcNew))
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
GUIDelete($Form1)
Exit
EndSwitch
WEnd
Func _MyWindowProc($hWnd, $uiMsg, $wParam, $lParam)
Switch $uiMsg
Case $WM_LBUTTONUP
MsgBox(64,"提示","点击成功弹出消息")
EndSwitch
Return _WinAPI_CallWindowProc($wProcOld, $hWnd, $uiMsg, $wParam, $lParam)
EndFunc ;==>_MyWindowProc
回复 2# 水木子
焦点这个不行的。。。我尝试过。。怎么都会激活操作 如果输入框已经是焦点,点击不会触发一个EN_SETFOCUS事件。 学习一下,学习一下 直接用GUICtrlSetOnEvent不就是了吗 应该注册消息吧
GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")
Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)
Global $tabim
#forceref $hWndGUI, $MsgID, $wParam
Local $tagNMHDR, $event, $hwndFrom, $code
$tagNMHDR = DllStructCreate("int;int;int", $lParam) ;NMHDR (hwndFrom, idFrom, code)
If @error Then Return
$event = DllStructGetData($tagNMHDR, 3)
Select
Case $wParam = $btn
Select
Case $event = $NM_Click
Case Else
EndSelect
EndSelect
$tagNMHDR = 0
$event = 0
$lParam = 0
EndFunc ;==>WM_Notify_Events 回复 7# xrzmjz
这个不行。。。会导致guimsg失效? 回复 8# xyold1
不好意思,我刚学,不是很明白,因为我想要几个输入框点击都达到这个效果?怎么弄呢 可以用GUISetonEvent来解决因GUICtrlSetOnEvent导致的GUIMSG失效的问题
参考这段代码
GUISetonEvent($GUI_EVENT_CLOSE,"EXITS")
Func EXITS()
EXIT
EndFunc #include <GUIConstantsEx.au3>
$Form1 = GUICreate("输入框点击例子", 341, 208, 192, 124)
$Input1 = GUICtrlCreateInput("点击我", 72, 40, 153, 33)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $GUI_EVENT_PRIMARYDOWN
$Pos = GUIGetCursorInfo($Form1)
If $Pos = $Input1 Then MsgBox(0,0,"点击了 Input")
EndSwitch
WEnd 回复 12# yhxhappy
十分感谢,你的方法来得省事, 回复 12# yhxhappy
十分感谢,你的方法来得省事, case $input
行不行
页:
[1]
2