本帖最后由 xyold1 于 2010-11-7 23:30 编辑
回复 6# afan
原来如此啊,还不能随心所欲地处理消息处理
下面是代码,有不对的还请大有指正
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_Icon=E:\TF卡备份\mynewwork\winvista图标\Icon_35.ico
#AutoIt3Wrapper_OutFile=movewin1.exe
#AutoIt3Wrapper_Res_Description=扩展屏幕
#AutoIt3Wrapper_Res_FileVersion=1.1.0.0
#AutoIt3Wrapper_Res_LegalCopyright=小数点儿
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
#include <WinAPIEx.au3>
#include <WinAPI.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <Misc.au3>
Opt("TrayMenuMode", 1)
#Region ### START Koda GUI section ### Form=
;~ TraySetIcon("", -1)
TraySetClick("8")
$MenuItem5 = TrayCreateItem("调节速度")
TrayCreateItem("")
$MenuItem4 = TrayCreateItem("上下移动")
TrayCreateItem("")
$MenuItem3 = TrayCreateItem("还 原")
TrayCreateItem("")
$MenuItem2 = TrayCreateItem("关 于")
TrayCreateItem("")
$MenuItem1 = TrayCreateItem("退 出")
TraySetState()
#EndRegion ### END Koda GUI section ###
Global $Data
Global Const $VK_SCROLL = 0x91
HotKeySet("{esc}", 'ExitAPP')
AdlibRegister("getdata", 1000)
setini()
$mov = RegRead("HKEY_CURRENT_USER\Software\Move_WindowUD\", "speed")
If $mov = "" Then
$mov = 10
EndIf
$loc = 5
$w = @DesktopWidth
$h = @DesktopHeight
Dim $posxx, $posyy
$dll = DllOpen("user32.dll")
TrayItemSetState($MenuItem4, RegRead("HKEY_CURRENT_USER\Software\Move_WindowUD\", "state"))
While 1
$nMsg = TrayGetMsg()
Switch $nMsg
Case $MenuItem5
$answer = InputBox("提示", "请输入一个数字", $mov)
If Not @error Then
If Number($answer) <> 0 Then
$mov = Number($answer)
RegWrite("HKEY_CURRENT_USER\Software\Move_WindowUD\", "speed", "REG_DWORD", $answer)
EndIf
EndIf
Case $MenuItem4
RegWrite("HKEY_CURRENT_USER\Software\Move_WindowUD\", "state", "REG_DWORD", TrayItemGetState($MenuItem4))
Case $MenuItem3
rest()
Case $MenuItem2
MsgBox(0, "关于", "小数点儿制作")
Case $MenuItem1
ExitAPP()
EndSwitch
If Not _GetKeyState($VK_SCROLL) Then
$size = WinGetPos("[active]")
If $size[0] < -$size[2] - 20 Or $size[0] > $w + 20 Or $size[1] < -$size[3] - 20 Or $size[1] > $h + 20 Then
WinMove("[active]", "", ($w - $size[2]) / 2, ($h - $size[3]) / 2)
EndIf
$tstate = BitAND(TrayItemGetState($MenuItem4), $TRAY_CHECKED)
$pos = MouseGetPos();返回一个包含鼠标坐标的2元素一维数组array: $array[0] = X 坐标 (横向), $array[1] = Y 坐标 (垂直)
If $pos[0] > $w - 5 Then
gethwn("right")
If $tstate Then
If $pos[1] > $posyy + $loc Then
gethwn("down")
ElseIf $pos[1] < $posyy - $loc Then
gethwn("up")
EndIf
EndIf
EndIf
If $pos[0] < 5 Then
gethwn("left")
If $tstate Then
If $pos[1] > $posyy + $loc Then
gethwn("down")
ElseIf $pos[1] < $posyy - $loc Then
gethwn("up")
EndIf
EndIf
EndIf
If $pos[1] > $h - 5 Then
If $tstate Then gethwn("down")
If $pos[0] > $posxx + $loc Then
gethwn("left")
ElseIf $pos[0] < $posxx - $loc Then
gethwn("right")
EndIf
EndIf
If $pos[1] < 5 Then
If $tstate Then gethwn("up")
If $pos[0] > $posxx + $loc Then
gethwn("left")
ElseIf $pos[0] < $posxx - $loc Then
gethwn("right")
EndIf
EndIf
$posxx = $pos[0]
$posyy = $pos[1]
EndIf
WEnd
Func _GetKeyState($VK_Code)
Local $ret = DllCall("user32.dll", "long", "GetKeyState", "long", $VK_Code)
Return $ret[0]
EndFunc ;==>_GetKeyState
Func rest()
$Data = _WinAPI_EnumWindowsTop()
For $i = 1 To $Data[0][0]
;~ $xe=IniRead("PosSet.db",$Data[$i][0],"x","none")
;~ $ye=IniRead("PosSet.db",$Data[$i][0],"y","none")
$xe = RegRead("HKEY_CURRENT_USER\Software\Move_Window\" & $Data[$i][0], "x")
$ye = RegRead("HKEY_CURRENT_USER\Software\Move_Window\" & $Data[$i][0], "y")
If $xe = "" And $ye = "" Then
Else
WinMove($Data[$i][0], "", $xe, $ye)
;~ IniWrite("PosSet.db",$Data[$i][0],"x",$winpos[0])
;~ EndIf
;~ $ye=IniRead("PosSet.db",$Data[$i][0],"y","none")
;~ If $ye="none" Then
;~ IniWrite("PosSet.db",$Data[$i][0],"x",$winpos[1])
EndIf
Next
EndFunc ;==>rest
Func ExitAPP()
$Data = _WinAPI_EnumWindowsTop()
For $i = 1 To $Data[0][0]
;~ $xe=IniRead("PosSet.db",$Data[$i][0],"x","none")
;~ $ye=IniRead("PosSet.db",$Data[$i][0],"y","none")
$xe = RegRead("HKEY_CURRENT_USER\Software\Move_Window\" & $Data[$i][0], "x")
$ye = RegRead("HKEY_CURRENT_USER\Software\Move_Window\" & $Data[$i][0], "y")
If $xe = "" And $ye = "" Then
Else
WinMove($Data[$i][0], "", $xe, $ye)
;~ IniWrite("PosSet.db",$Data[$i][0],"x",$winpos[0])
;~ EndIf
;~ $ye=IniRead("PosSet.db",$Data[$i][0],"y","none")
;~ If $ye="none" Then
;~ IniWrite("PosSet.db",$Data[$i][0],"x",$winpos[1])
EndIf
Next
;~ FileDelete("PosSet.db")
RegDelete("HKEY_CURRENT_USER\Software\Move_Window\")
DllClose($dll)
Exit
EndFunc ;==>ExitAPP
Func setini()
$Data = _WinAPI_EnumWindowsTop()
For $i = 1 To $Data[0][0]
$state = WinGetState($Data[$i][0])
If Not BitAND($state, 16) Or Not BitAND($state, 32) Then
$winpos = WinGetPos($Data[$i][0])
;~ $xe=IniRead("PosSet.db",$Data[$i][0],"x","none")
$xe = RegRead("HKEY_CURRENT_USER\Software\Move_Window\" & $Data[$i][0], "x")
If $xe = "" Then
;~ IniWrite("PosSet.db",$Data[$i][0],"x",$winpos[0])
RegWrite("HKEY_CURRENT_USER\Software\Move_Window\" & $Data[$i][0], "x", "REG_DWORD", $winpos[0])
EndIf
;~ $ye=IniRead("PosSet.db",$Data[$i][0],"y","none")
$ye = RegRead("HKEY_CURRENT_USER\Software\Move_Window\" & $Data[$i][0], "y")
If $ye = "" Then
;~ IniWrite("PosSet.db",$Data[$i][0],"y",$winpos[1])
RegWrite("HKEY_CURRENT_USER\Software\Move_Window\" & $Data[$i][0], "y", "REG_DWORD", $winpos[1])
EndIf
EndIf
Next
EndFunc ;==>setini
Func getdata()
$datanum = $Data
$Data = _WinAPI_EnumWindowsTop()
If $Data <> $datanum Then setini()
EndFunc ;==>getdata
Func gethwn($MP)
For $i = 1 To $Data[0][0]
$state = WinGetState($Data[$i][0])
$winposA = WinGetPos($Data[$i][0])
If Not BitAND($state, 16) Then
Switch $MP
Case "left"
WinMove($Data[$i][0], "", $winposA[0] + $mov, $winposA[1])
;~ IniWrite("PosSet.db",$Data[$i][0],"xn",$winposA[0]+$mov)
RegWrite("HKEY_CURRENT_USER\Software\Move_Window\" & $Data[$i][0], "xn", "REG_DWORD", $winposA[0] + $mov)
Case "right"
WinMove($Data[$i][0], "", $winposA[0] - $mov, $winposA[1])
;~ IniWrite("PosSet.db",$Data[$i][0],"xn",$winposA[0]-$mov)
RegWrite("HKEY_CURRENT_USER\Software\Move_Window\" & $Data[$i][0], "xn", "REG_DWORD", $winposA[0] - $mov)
Case "up"
WinMove($Data[$i][0], "", $winposA[0], $winposA[1] + $mov)
;~ IniWrite("PosSet.db",$Data[$i][0],"yn",$winposA[1]+$mov)
RegWrite("HKEY_CURRENT_USER\Software\Move_Window\" & $Data[$i][0], "yn", "REG_DWORD", $winposA[1] + $mov)
Case "down"
WinMove($Data[$i][0], "", $winposA[0], $winposA[1] - $mov)
;~ IniWrite("PosSet.db",$Data[$i][0],"yn",$winposA[1]-$mov)
RegWrite("HKEY_CURRENT_USER\Software\Move_Window\" & $Data[$i][0], "yn", "REG_DWORD", $winposA[1] - $mov)
EndSwitch
EndIf
Next
EndFunc ;==>gethwn
|