找回密码
 加入
搜索
查看: 2593|回复: 4

[网络通信] 求助.无边框窗体移动问题.(解决)

  [复制链接]
发表于 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[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
发表于 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[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
发表于 2011-6-28 09:03:12 | 显示全部楼层
方法果然很多,学习,学习
发表于 2011-6-28 15:45:58 | 显示全部楼层
留个脚印,日后查用
 楼主| 发表于 2011-6-28 22:11:20 | 显示全部楼层
哇.厉害..三种之多啊..谢谢..
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-6-11 00:01 , Processed in 0.083066 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表