鼠标没有点在次窗口区域里,自动退出,求大侠赐教(已解决)
本帖最后由 cqboyqx 于 2018-5-10 12:27 编辑#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPISys.au3>
Global $Button1,$Form1,$Form2,$a
Opt("GUIOnEventMode", 1)
my_gui()
Func my_gui();主窗口
$Form1 = GUICreate("Form1", 452, 282)
GUISetOnEvent($GUI_EVENT_CLOSE, "MYGUI_CLOSE")
$Button1 = GUICtrlCreateButton('弹出子窗', 184, 56, 62, 25);,$BS_MULTILINE
GUICtrlSetOnEvent($Button1, "TANCHU")
GUISetState(@SW_SHOW)
EndFunc
While 1
WEnd
Func TANCHU()
MYGUI2()
EndFunc
Func MYGUI_CLOSE()
Exit
EndFunc
Func MYGUI2();次窗口,启动后鼠标没有点击在次窗口区域内,而在主窗口区域里,就退出
GUISetState(@SW_DISABLE, $Form1)
$Form2 = GUICreate("Form1", 257, 157)
GUISetOnEvent($GUI_EVENT_CLOSE, "MYGUI2_CLOSE")
$a = _WinAPI_TrackMouseEvent ( $Form2,$WM_MOUSELEAVE)
GUISetState(@SW_SHOW)
EndFunc
Func MYGUI2_CLOSE()
Exit
EndFunc
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPISys.au3>
Global $Button1=0, $Form1, $Form2, $a
Opt("GUIOnEventMode", 1)
my_gui()
Func my_gui();主窗口
$Form1 = GUICreate("Form1", 452, 282)
GUISetOnEvent($GUI_EVENT_CLOSE, "MYGUI_CLOSE")
$Button1 = GUICtrlCreateButton('弹出子窗', 184, 56, 62, 25);,$BS_MULTILINE
GUICtrlSetOnEvent($Button1, "TANCHU")
GUISetState(@SW_SHOW)
EndFunc ;==>my_gui
While 1
Sleep(100)
WEnd
Func TANCHU()
MYGUI2()
EndFunc ;==>TANCHU
Func MYGUI_CLOSE()
Exit
EndFunc ;==>MYGUI_CLOSE
Func MYGUI2();次窗口,启动后鼠标没有点击在次窗口区域内,退出
$Form2 = GUICreate("Form1", 300, 200,-1,-1,$Form1)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_MOUSEMOVE, "WM_MOUSEMOVE")
GUIRegisterMsg($WM_MOUSELEAVE, "WM_MOUSELEAVE")
EndFunc ;==>MYGUI2
Func WM_MOUSEMOVE($hWnd, $Msg, $wParam, $lParam)
$tagTRACKMOUSEEVENT = DllStructCreate("DWORD cbSize;DWORD dwFlags;HWNDhwndTrack;DWORD dwHoverTime")
DllStructSetData($tagTRACKMOUSEEVENT, "cbSize", DllStructGetSize($tagTRACKMOUSEEVENT)) ;结构体缓冲区大小
DllStructSetData($tagTRACKMOUSEEVENT, "dwFlags", BitOR($TME_HOVER,$TME_LEAVE)) ;注册WM_MOUSEHOVER和$WM_MOUSELEAVE消息
DllStructSetData($tagTRACKMOUSEEVENT, "hwndTrack", $hWnd) ;当前窗口句柄
DllStructSetData($tagTRACKMOUSEEVENT, "dwHoverTime", 300) ;触发的时间300ms
$TRACKMOUSEEVENT = DllStructGetPtr($tagTRACKMOUSEEVENT)
DllCall("user32.dll", "bool", "TrackMouseEvent","ptr",$TRACKMOUSEEVENT)
EndFunc ;==>WM_MOUSEMOVE
Func WM_MOUSELEAVE($hWnd, $Msg, $wParam, $lParam)
GUIDelete($Form2)
EndFunc ;==>MYGUI2_CLOSE
本帖最后由 cqboyqx 于 2018-5-2 15:26 编辑
回复 2# xzf680
谢谢大侠的回复,你这个是移开就关闭了,我想的是鼠标没有点击在次窗口上就退出次窗口,不是鼠标没有在次窗口就关闭 回复 3# cqboyqx
退出次窗口,不是鼠标没有在次窗口就关闭
那麼退出次窗口的意思是??次窗口還存在 隱藏起來還是 次窗口不見了
不見了 不就是關閉 那 甚麼是關閉?? 回复 4# kk_lee69
可能我没有阐述清楚,就是如果鼠标点击主窗口,次窗口就关闭,类似与Combo下拉框模式, 回复 5# cqboyqx
变通一下,如果不激活就隐藏。
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPISys.au3>
Global $Button1=0, $Form1, $Form2, $a
Opt("GUIOnEventMode", 1)
my_gui()
Func my_gui();主窗口
$Form1 = GUICreate("Form1", 452, 282)
GUISetOnEvent($GUI_EVENT_CLOSE, "MYGUI_CLOSE")
$Button1 = GUICtrlCreateButton('弹出子窗', 184, 56, 62, 25);,$BS_MULTILINE
GUICtrlSetOnEvent($Button1, "TANCHU")
GUISetState(@SW_SHOW)
EndFunc ;==>my_gui
$Form2 = GUICreate("Form1", 300, 200,-1,-1,$Form1)
While 1
Sleep(100)
If Not WinActive ($Form2,'') ThenGUISetState(@SW_HIDE,$Form2)
WEnd
Func TANCHU()
MYGUI2()
EndFunc ;==>TANCHU
Func MYGUI_CLOSE()
Exit
EndFunc ;==>MYGUI_CLOSE
Func MYGUI2();次窗口,启动后鼠标没有点击在次窗口区域内,退出
;~ $Form2 = GUICreate("Form1", 300, 200,-1,-1,$Form1)
GUISetState(@SW_SHOW,$Form2)
;~ GUIRegisterMsg($WM_MOUSEMOVE, "WM_MOUSEMOVE")
;~ GUIRegisterMsg($WM_MOUSELEAVE, "WM_MOUSELEAVE")
EndFunc ;==>MYGUI2
回复 5# cqboyqx
可能是你誤解了......
combo 按下下拉就會建立 下拉清單放開後 或者點擊別的地方下拉清單就被刪除了
等待你下次 下拉再重新建立 都是這樣運作的....
實在不懂你想要的東西 回复 7# kk_lee69
就是你说的这个意思,用窗口来做一个仿combo效果 回复 8# qsy666888
你是 cqboyqx ??
都有 COMBO 還用窗口模仿啥??
能畫圖表示嗎?? 回复 9# kk_lee69
哎呀,我估计他说的就是这个意思,可能COMBO里没有他想要的功能,他想自己仿一个COMBO模式来达到COMBO效果,6楼的应该满足他需要 回复 5# cqboyqx
Global $is_tracking = False
Global $iteration = 1 ; Just to recognize different ConsoleWrite's in spammed console
Global $hGui = GUICreate('')
Global $sTrackMouseEvent = DllStructCreate('dword;dword;hwnd;dword'); Creating TRACKMOUSEEVENT Structure
Global $sTME_size = DllStructGetSize($sTrackMouseEvent) ; getting size of structure - need for 1st argument
; Filling in:
DllStructSetData($sTrackMouseEvent, 1, $sTME_size) ; Size of a structure
DllStructSetData($sTrackMouseEvent, 2, 0x00000002) ; TME_LEAVE
DllStructSetData($sTrackMouseEvent, 3, $hGui) ; HWND of our GUI
DllStructSetData($sTrackMouseEvent, 4, 0xFFFFFFFF); HOVER_DEFAULT - BUT IT'S NOT USED ANYWAY, SINCE WE'RE TRACKING ONLY MOUSE_LEAVE EVENT
Global $sTME_POINTER = DllStructGetPtr($sTrackMouseEvent) ; Getting the pointer to the structure, needed to TrackMouseEvent function
GUIRegisterMsg(0x0200, '__wm_mousemove')
GUIRegisterMsg(0x02A3, '__wm_mouseleave') ; WM_MOUSELEAVE code
GUISetState()
$Form2 = GUICreate("Form1", 300, 200,-1,-1,$hGui)
Func __wm_mouseleave($hwnd, $msg, $wParam, $lParam)
$is_tracking = False
ConsoleWrite('YOUR MOUSE HAS JUST LEAVED YOUR GUI WINDOW FOR THE ' & $iteration & ' TIME!' & @CRLF)
GUISetState(@SW_SHOW,$Form2)
$iteration += 1
EndFunc
Func __wm_mousemove($hwnd, $msg, $wParam, $lParam)
If Not $is_tracking Then
$is_tracking = True
DllCall('user32.dll', 'bool', 'TrackMouseEvent', 'ptr', $sTME_POINTER) ; We're calling the tracking function
ConsoleWrite('Starting tracking...' & @CRLF)
GUISetState(@SW_HIDE,$Form2)
EndIF
EndFunc
Do
Until GuiGetMsg() = -3 回复 1# cqboyqx
打开主窗口后,点击弹出子窗按钮,
显示子窗口,鼠标离开子窗口区域,子窗口就退出。
是这个意思?
回复 6# 骗子
谢谢大侠,正是此意思 回复 10# qsy666888
昨天不在,正是你说的意思 回复 12# chzj589
你這個跟 二樓是一樣的樓主 又說不是
页:
[1]
2