夜猫猫 发表于 2011-6-28 02:12:30

求助.无边框窗体移动问题.(解决)

本帖最后由 夜猫猫 于 2011-6-28 22:11 编辑

代码是论坛里的.在测试时,添加 Opt("GUIOnEventMode", 1) 后.窗体不能拖动了.
move()跟Opt("GUIOnEventMode", 1)有冲突?....请大大们帮忙下.怎么解决这个问题.#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")

GUISetState(@SW_SHOW)
#EndRegion ### START Koda GUI section ### Form=

While 1
      $nMsg = GUIGetMsg()
      Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $GUI_EVENT_PRIMARYDOWN
                        mouseCHK()
      EndSwitch
WEnd


Func start()
MsgBox(16,"提示","搜索")
EndFunc

Func mouseCHK()
      $MS = GUIGetCursorInfo($Form1)
      If $MS = $Input1 Then move()
EndFunc   ;==>mouseCHK
Func move()
      Local $PosDiff, $MousePos, $WinPos
      $MousePos = MouseGetPos()
      $WinPos = WinGetPos($Form1, "")
      $PosDiff = $WinPos - $MousePos
      $PosDiff = $WinPos - $MousePos
      While _IsPressed("01", DllOpen("user32.dll"))
                $MousePos = MouseGetPos()
                WinMove($Form1, "", $MousePos + $PosDiff, $MousePos + $PosDiff)
                Sleep(10)
      WEnd
EndFunc   ;==>move

happytc 发表于 2011-6-28 08:00:59

本帖最后由 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 = $Input1 Then move()
EndFunc   ;==>mouseCHK


Func move()
        Local $PosDiff, $MousePos, $WinPos
        $MousePos = MouseGetPos()
        $WinPos = WinGetPos($Form1, "")
        $PosDiff = $WinPos - $MousePos
        $PosDiff = $WinPos - $MousePos
        While _IsPressed("01", DllOpen("user32.dll"))
                $MousePos = MouseGetPos()
                WinMove($Form1, "", $MousePos + $PosDiff, $MousePos + $PosDiff)
                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 = $Input1 Then move()
EndFunc   ;==>mouseCHK


Func move()
        Local $PosDiff, $MousePos, $WinPos
        $MousePos = MouseGetPos()
        $WinPos = WinGetPos($Form1, "")
        $PosDiff = $WinPos - $MousePos
        $PosDiff = $WinPos - $MousePos
        While _IsPressed("01", DllOpen("user32.dll"))
                $MousePos = MouseGetPos()
                WinMove($Form1, "", $MousePos + $PosDiff, $MousePos + $PosDiff)
                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 = $Input1 Then move()
EndFunc   ;==>mouseCHK


Func move()
        Local $PosDiff, $MousePos, $WinPos
        $MousePos = MouseGetPos()
        $WinPos = WinGetPos($Form1, "")
        $PosDiff = $WinPos - $MousePos
        $PosDiff = $WinPos - $MousePos
        While _IsPressed("01", DllOpen("user32.dll"))
                $MousePos = MouseGetPos()
                WinMove($Form1, "", $MousePos + $PosDiff, $MousePos + $PosDiff)
                Sleep(10)
        WEnd
EndFunc   ;==>move
#ce

wsfda 发表于 2011-6-28 09:03:12

方法果然很多,学习,学习

minghui 发表于 2011-6-28 15:45:58

留个脚印,日后查用

夜猫猫 发表于 2011-6-28 22:11:20

哇.厉害..三种之多啊..谢谢..
页: [1]
查看完整版本: 求助.无边框窗体移动问题.(解决)