本帖最后由 happytc 于 2011-6-28 08:05 编辑
回复 1# 夜猫猫
事件模式和消息模式别混用,当启用了OnEvent 函数后,GUIGetMsg函数无效了(总是返回0),用下面三种方法都可以达到你的目的:、
方法一:你定义的函数:
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
Opt("GUIOnEventMode", 1) ;加入后窗体不能拖动
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 300, 50, 193, 125, $WS_POPUP)
$Input1 = GUICtrlCreateInput("这里输入数字", 24, 16, 201, 21)
$Button1 = GUICtrlCreateButton("搜索", 255, 16, 30, 21)
GUICtrlSetOnEvent(-1, "start")
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "mouseCHK")
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUISetState(@SW_SHOW)
#EndRegion ### START Koda GUI section ### Form=
While Sleep(10000)
WEnd
#cs
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
start()
Case $GUI_EVENT_PRIMARYDOWN
mouseCHK()
EndSwitch
WEnd
#ce
Func start()
MsgBox(16,"提示","搜索")
EndFunc
Func _Exit()
Exit
EndFunc
Func mouseCHK()
$MS = GUIGetCursorInfo($Form1)
If $MS[4] = $Input1 Then move()
EndFunc ;==>mouseCHK
Func move()
Local $PosDiff[2], $MousePos, $WinPos
$MousePos = MouseGetPos()
$WinPos = WinGetPos($Form1, "")
$PosDiff[0] = $WinPos[0] - $MousePos[0]
$PosDiff[1] = $WinPos[1] - $MousePos[1]
While _IsPressed("01", DllOpen("user32.dll"))
$MousePos = MouseGetPos()
WinMove($Form1, "", $MousePos[0] + $PosDiff[0], $MousePos[1] + $PosDiff[1])
Sleep(10)
WEnd
EndFunc ;==>move
方法2:
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#Include <SendMessage.au3>
#include <GuiMenu.au3>
;Opt("GUIOnEventMode", 1) ;加入后窗体不能拖动
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 300, 50, 193, 125, BitOR($WS_SYSMENU, $WS_POPUP))
$Input1 = GUICtrlCreateInput("这里输入数字", 24, 16, 201, 21)
$Button1 = GUICtrlCreateButton("搜索", 255, 16, 30, 21)
;GUICtrlSetOnEvent(-1, "start")
GUISetState(@SW_SHOW)
#EndRegion ### START Koda GUI section ### Form=
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
start()
Case $GUI_EVENT_PRIMARYDOWN
_SendMessage($Form1, $WM_SYSCOMMAND, $SC_MOVE + $HTCAPTION, 0)
;Case $GUI_EVENT_PRIMARYDOWN
; mouseCHK()
EndSwitch
WEnd
Func start()
MsgBox(16,"提示","搜索")
EndFunc
#cs
Func mouseCHK()
$MS = GUIGetCursorInfo($Form1)
If $MS[4] = $Input1 Then move()
EndFunc ;==>mouseCHK
Func move()
Local $PosDiff[2], $MousePos, $WinPos
$MousePos = MouseGetPos()
$WinPos = WinGetPos($Form1, "")
$PosDiff[0] = $WinPos[0] - $MousePos[0]
$PosDiff[1] = $WinPos[1] - $MousePos[1]
While _IsPressed("01", DllOpen("user32.dll"))
$MousePos = MouseGetPos()
WinMove($Form1, "", $MousePos[0] + $PosDiff[0], $MousePos[1] + $PosDiff[1])
Sleep(10)
WEnd
EndFunc ;==>move
#ce
方法3:
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#Include <SendMessage.au3>
#include <GuiMenu.au3>
Opt("GUIOnEventMode", 1) ;加入后窗体不能拖动
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 300, 50, 193, 125, BitOR($WS_SYSMENU, $WS_POPUP))
$Input1 = GUICtrlCreateInput("这里输入数字", 24, 16, 201, 21)
$Button1 = GUICtrlCreateButton("搜索", 255, 16, 30, 21)
GUICtrlSetOnEvent(-1, "start")
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "_SendMsg")
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUISetState(@SW_SHOW)
#EndRegion ### START Koda GUI section ### Form=
While Sleep(10000)
WEnd
#cs
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
start()
Case $GUI_EVENT_PRIMARYDOWN
mouseCHK()
EndSwitch
WEnd
#ce
Func start()
MsgBox(16,"提示","搜索")
EndFunc
Func _SendMsg()
_SendMessage($Form1, $WM_SYSCOMMAND, $SC_MOVE + $HTCAPTION, 0)
EndFunc
Func _Exit()
Exit
EndFunc
#cs
Func mouseCHK()
$MS = GUIGetCursorInfo($Form1)
If $MS[4] = $Input1 Then move()
EndFunc ;==>mouseCHK
Func move()
Local $PosDiff[2], $MousePos, $WinPos
$MousePos = MouseGetPos()
$WinPos = WinGetPos($Form1, "")
$PosDiff[0] = $WinPos[0] - $MousePos[0]
$PosDiff[1] = $WinPos[1] - $MousePos[1]
While _IsPressed("01", DllOpen("user32.dll"))
$MousePos = MouseGetPos()
WinMove($Form1, "", $MousePos[0] + $PosDiff[0], $MousePos[1] + $PosDiff[1])
Sleep(10)
WEnd
EndFunc ;==>move
#ce
|