[已解决]API 控制移动WIN系统任务栏的问题
本帖最后由 小影 于 2012-12-21 12:14 编辑;~ ;查找任务栏的句柄
Local $winhwnd=DllCall("user32.dll","hwnd","FindWindow","str","Shell_TrayWnd","str","")
;~ ;获取任务栏的左上角,和右下角坐标
Local $apihw=DllStructCreate("long x;long y;long c;long d")
DllCall("user32.dll","bool","GetWindowRect","hwnd",$winhwnd,"ptr",DllStructGetPtr($apihw))
$x=DllStructGetData($apihw,"x") ;左上X坐标 0
$y=DllStructGetData($apihw,"y");左上Y坐标860
$c=DllStructGetData($apihw,"c") ;右下x 坐标1440
$d=DllStructGetData($apihw,"d") ;右下Y坐标 900
Local $heghit=$d-$y
MouseClickDrag("left",$y,$d+$heghit,0,$heghit) ;向左
Sleep(5000)
MouseClickDrag("left",0,$d-300,$c,$d) ;还原
以上代码在任务栏无锁定,任务栏没有打开文件的时候能成功运行!
测试了api MoveWindow 函数,无效。AU3自带的函数表示也没有什么效果。
寻求不受任务栏中显示有多少文件影响,能够移动的函数! #Include <WinAPIEx.au3>
_WinAPI_ShellAppBarMessage 回复 2# netegg
谢谢NETEGG指导,但是找不到你所说的_WinAPI_ShellAppBarMessage函数,查了一个MSDN,找到了这个函数的原型,但这个函数原型太复杂了,搞不明白,搞到一半搞不下去了。再求指导一下 本帖最后由 小影 于 2012-12-20 10:04 编辑
补充一下,RC指向的结构,还没有对元素进行赋值,RC指向的是坐标值位置!
SHAppBarMessage 函数地址
http://msdn.microsoft.com/en-us/library/bb762108(v=VS.85).aspx 本帖最后由 netegg 于 2012-12-20 14:20 编辑
;consts
Global Const $ABM_NEW = 0x00000000
Global Const $ABM_REMOVE = 0x00000001
Global Const $ABM_QUERYPOS = 0x00000002
Global Const $ABM_SETPOS = 0x00000003
Global Const $ABM_GETSTATE = 0x00000004
Global Const $ABM_GETTASKBARPOS = 0x00000005
Global Const $ABM_ACTIVATE = 0x00000006
Global Const $ABM_GETAUTOHIDEBAR = 0x00000007
Global Const $ABM_SETAUTOHIDEBAR = 0x00000008
Global Const $ABM_WINDOWPOSCHANGED = 0x00000009
Global Const $ABM_SETSTATE = 0x0000000A
Global Const $ABE_LEFT = 0x0
Global Const $ABE_TOP = 0x1
Global Const $ABE_RIGHT = 0x2
Global Const $ABE_BOTTOM = 0x3
Func _WinAPI_ShellAppBarMessage($Message)
Local $tagAPPBARAPPBARDATA = "DWORD cbSize;HWND hWnd;UINT uCallbackMessage;UINT uEdge;" & $tagRECT & ";int lParam;"
Local $tAPPBARAPPBARDATA = DllStructCreate($tagAPPBARAPPBARDATA)
Local $hAPPBAR = WinGetHandle("", "") ; Get handle of taskbar
DllStructSetData($tAPPBARAPPBARDATA, "hWnd", $hAPPBAR) ; Set handle to taskbar
DllStructSetData($tAPPBARAPPBARDATA, "cbSize", DllStructGetSize($tAPPBARAPPBARDATA)) ; Set size of struct
Local $Ret = DllCall("shell32.dll", "int", "SHAppBarMessage", "int", $Message, "ptr", DllStructGetPtr($tAPPBARAPPBARDATA))
If (@error) Or (Not $Ret) Then
Return SetError(1, 0, 0)
EndIf
Local $Result
$Result = DllStructGetData($tAPPBARAPPBARDATA, 'uEdge')
$Result = DllStructGetData($tAPPBARAPPBARDATA, 'Left')
$Result = DllStructGetData($tAPPBARAPPBARDATA, 'Top')
$Result = DllStructGetData($tAPPBARAPPBARDATA, 'Right')
$Result = DllStructGetData($tAPPBARAPPBARDATA, 'Bottom')
Return $Result
EndFunc ;==>_WinAPI_ShellAppBarMessage
本帖最后由 小影 于 2012-12-20 14:35 编辑
回复 5# netegg
谢谢蛋兄的指导,测试了没效果!附上测试代码!
#include<winapiex.au3>
;~ ;查找任务栏的句柄
Local $winhwnd=DllCall("user32.dll","hwnd","FindWindow","str","Shell_TrayWnd","str","")
;~ ;获取任务栏的左上角,和右下角坐标
Local $apihw=DllStructCreate("long x;long y;long c;long d")
DllCall("user32.dll","bool","GetWindowRect","hwnd",$winhwnd,"ptr",DllStructGetPtr($apihw))
$x=DllStructGetData($apihw,"x") ;左上X坐标 0
$y=DllStructGetData($apihw,"y");左上Y坐标860
$c=DllStructGetData($apihw,"c") ;右下x 坐标1440
$d=DllStructGetData($apihw,"d") ;右下Y坐标 900
Local $heghit=$d-$y
Local $Var=3
_WinAPI_ShellAppBarMessage($var)
Func _WinAPI_ShellAppBarMessage($Message)
Local $tagAPPBARAPPBARDATA = "DWORD cbSize;HWND hWnd;UINT uCallbackMessage;UINT uEdge;" & $tagRECT & ";int lParam;"
Local $tAPPBARAPPBARDATA = DllStructCreate($tagAPPBARAPPBARDATA)
Local $hAPPBAR = WinGetHandle("", "") ; Get handle of taskbar
DllStructSetData($tAPPBARAPPBARDATA, "hWnd", $hAPPBAR) ; Set handle to taskbar
DllStructSetData($tAPPBARAPPBARDATA, "cbSize", DllStructGetSize($tAPPBARAPPBARDATA)) ; Set size of struct
Local $Ret = DllCall("shell32.dll", "int", "SHAppBarMessage", "int", $Message, "ptr", DllStructGetPtr($tAPPBARAPPBARDATA))
If (@error) Or (Not $Ret) Then
Return SetError(1, 0, 0)
EndIf
Local $Result
$Result = DllStructGetData($tAPPBARAPPBARDATA, 'uEdge')
$Result = DllStructGetData($tAPPBARAPPBARDATA, 'Left')
$Result = DllStructGetData($tAPPBARAPPBARDATA, 'Top')
$Result = DllStructGetData($tAPPBARAPPBARDATA, 'Right')
$Result = DllStructGetData($tAPPBARAPPBARDATA, 'Bottom')
Return $Result
EndFunc ;==>_WinAPI_ShellAppBarMessage
#CS
dwMessage
Type: DWORD
Appbar message value to send. This parameter can be one of the following values.
ABM_NEW (0x00000000)
Registers a new appbar and specifies the message identifier that the system should use to send notification messages to the appbar.
ABM_REMOVE (0x00000001)
Unregisters an appbar, removing the bar from the system's internal list.
ABM_QUERYPOS (0x00000002)
Requests a size and screen position for an appbar.
ABM_SETPOS (0x00000003)
Sets the size and screen position of an appbar.
ABM_GETSTATE (0x00000004)
Retrieves the autohide and always-on-top states of the Windows taskbar.
ABM_GETTASKBARPOS (0x00000005)
Retrieves the bounding rectangle of the Windows taskbar. Note that this applies only to the system taskbar. Other objects, particularly toolbars supplied with third-party software, also can be present. As a result, some of the screen area not covered by the Windows taskbar might not be visible to the user. To retrieve the area of the screen not covered by both the taskbar and other app bars—the working area available to your application—, use the GetMonitorInfo function.
ABM_ACTIVATE (0x00000006)
Notifies the system to activate or deactivate an appbar. The lParam member of the APPBARDATA pointed to by pData is set to TRUE to activate or FALSE to deactivate.
ABM_GETAUTOHIDEBAR (0x00000007)
Retrieves the handle to the autohide appbar associated with a particular edge of the screen.
ABM_SETAUTOHIDEBAR (0x00000008)
Registers or unregisters an autohide appbar for an edge of the screen.
ABM_WINDOWPOSCHANGED (0x00000009)
Notifies the system when an appbar's position has changed.
ABM_SETSTATE (0x0000000A)
Windows XP and later: Sets the state of the appbar's autohide and always-on-top attributes.
#CE
3的话要给$tagRect赋值 回复 7# netegg
蛋兄,还是没反应。能麻烦一下你,帮忙测试一下吗?晕菜ING
#include<winapiex.au3>
;~ ;查找任务栏的句柄
Local $winhwnd = DllCall("user32.dll", "hwnd", "FindWindow", "str", "Shell_TrayWnd", "str", "")
;~ ;获取任务栏的左上角,和右下角坐标
Local $apihw = DllStructCreate("long x;long y;long c;long d")
DllCall("user32.dll", "bool", "GetWindowRect", "hwnd", $winhwnd, "ptr", DllStructGetPtr($apihw))
$x = DllStructGetData($apihw, "x") ;左上X坐标 0
$y = DllStructGetData($apihw, "y") ;左上Y坐标860
$c = DllStructGetData($apihw, "c") ;右下x 坐标1440
$d = DllStructGetData($apihw, "d") ;右下Y坐标 900
Local $heghit = $d - $y
Local $Var = 3
_WinAPI_ShellAppBarMessage($Var)
Func _WinAPI_ShellAppBarMessage($Message)
Local $tagAPPBARAPPBARDATA = "DWORD cbSize;HWND hWnd;UINT uCallbackMessage;UINT uEdge;ptr tagRECT;int lParam"
Local $tAPPBARAPPBARDATA = DllStructCreate($tagAPPBARAPPBARDATA)
Local $rc = "long left;long top; long right;long bottom"
Local $apirc = DllStructCreate($rc)
DllStructSetData($apirc, "left", 0)
DllStructSetData($apirc, "top", 0)
DllStructSetData($apirc, "right", $heghit)
DllStructSetData($apirc, "bottom", $d)
DllStructSetData($tagAPPBARAPPBARDATA,"tagRECT",DllStructGetPtr($apirc))
Local $hAPPBAR = WinGetHandle("", "") ; Get handle of taskbar
DllStructSetData($tAPPBARAPPBARDATA, "hWnd", $hAPPBAR) ; Set handle to taskbar
DllStructSetData($tAPPBARAPPBARDATA, "cbSize", DllStructGetSize($tAPPBARAPPBARDATA)) ; Set size of struct
Local $Ret = DllCall("shell32.dll", "int", "SHAppBarMessage", "int", $Message, "ptr", DllStructGetPtr($tAPPBARAPPBARDATA))
If (@error) Or (Not $Ret) Then
Return SetError(1, 0, 0)
EndIf
Local $Result
$Result = DllStructGetData($tAPPBARAPPBARDATA, 'uEdge')
$Result = DllStructGetData($tAPPBARAPPBARDATA, 'Left')
$Result = DllStructGetData($tAPPBARAPPBARDATA, 'Top')
$Result = DllStructGetData($tAPPBARAPPBARDATA, 'Right')
$Result = DllStructGetData($tAPPBARAPPBARDATA, 'Bottom')
Return $Result
EndFunc ;==>_WinAPI_ShellAppBarMessage
回复 8# 小影
DllStructSetData($tagAPPBARAPPBARDATA,"tagRECT",DllStructGetPtr($apirc))
这句是什么意思 回复 9# netegg
给元素TAGRECT赋值,赋值结构是$APIRC 本帖最后由 netegg 于 2012-12-20 15:58 编辑
回复 10# 小影
给$tagAPPBARAPPBARDATA结构元素赋值能直接使用$tagAPPBARAPPBARDATA结构吗 $tagAPPBARAPPBARDATA结构中含有RECT元素,而RECT指向的又是一个结构,所以我的想法应该是得为$tagAPPBARAPPBARDATA中的RECT元素构造一个RECT原型结构引用 回复 11# netegg
蛋,设置位置真的不行
隐藏置顶什么的倒是行的,我的代码
;consts
Global Const $ABM_NEW = 0x00000000
Global Const $ABM_REMOVE = 0x00000001
Global Const $ABM_QUERYPOS = 0x00000002
Global Const $ABM_SETPOS = 0x00000003
Global Const $ABM_GETSTATE = 0x00000004
Global Const $ABM_GETTASKBARPOS = 0x00000005
Global Const $ABM_ACTIVATE = 0x00000006
Global Const $ABM_GETAUTOHIDEBAR = 0x00000007
Global Const $ABM_SETAUTOHIDEBAR = 0x00000008
Global Const $ABM_WINDOWPOSCHANGED = 0x00000009
Global Const $ABM_SETSTATE = 0x0000000A
Global Const $ABS_AUTOHIDE = 0x01
Global Const $ABS_ALWAYSONTOP = 0x02
Global Const $ABE_LEFT = 0x0
Global Const $ABE_TOP = 0x1
Global Const $ABE_RIGHT = 0x2
Global Const $ABE_BOTTOM = 0x3
Global $tagAPPBARAPPBARDATA = "DWORD cbSize;HWND hWnd;UINT uCallbackMessage;UINT uEdge;" & $tagRECT & ";int lParam;"
;脚本开始
Local $tPABD = DllStructCreate($tagAPPBARAPPBARDATA)
Local $hAPPBAR = WinGetHandle("", "") ; Get handle of taskbar
DllStructSetData($tPABD, "hWnd", $hAPPBAR) ; Set handle to taskbar
DllStructSetData($tPABD, "cbSize", DllStructGetSize($tPABD)) ; Set size of struct
DllStructSetData($tPABD,"Left",-2)
DllStructSetData($tPABD,"Top",-2)
DllStructSetData($tPABD,"Right",100)
DllStructSetData($tPABD,"Bottom",802)
DllStructSetData($tPABD,"uEdge",$ABE_LEFT)
_WinAPI_ShellAppBarMessage($ABM_SETPOS, $tPABD)
Func _WinAPI_ShellAppBarMessage($Message, ByRef $tagAPPBARAPPBARDATA)
Local $Ret = DllCall("shell32.dll", "int", "SHAppBarMessage", "int", $Message, "ptr", DllStructGetPtr($tagAPPBARAPPBARDATA))
If (@error) Or (Not $Ret) Then
Return SetError(1, 0, 0)
EndIf
Local $Result
$Result = DllStructGetData($tagAPPBARAPPBARDATA, 'uEdge')
$Result = DllStructGetData($tagAPPBARAPPBARDATA, 'Left')
$Result = DllStructGetData($tagAPPBARAPPBARDATA, 'Top')
$Result = DllStructGetData($tagAPPBARAPPBARDATA, 'Right')
$Result = DllStructGetData($tagAPPBARAPPBARDATA, 'Bottom')
Return $Result
EndFunc ;==>_WinAPI_ShellAppBarMessage 本帖最后由 netegg 于 2012-12-20 16:37 编辑
uEdge元素的定义呢,顶底左右不是有常量定义吗
left和top元素不能为负吧,msdn上解释是屏幕坐标 回复 14# netegg
uEdge元素的定义呢,顶底左右不是有常量定义吗
在17到20行
Global Const $ABE_LEFT = 0x0
Global Const $ABE_TOP = 0x1
Global Const $ABE_RIGHT = 0x2
Global Const $ABE_BOTTOM = 0x3
left和top元素不能为负吧,msdn上解释是屏幕坐标
即便是非负也不动
会不会可能自己建立的appBar才能改大小或者位置,系统的改不了
页:
[1]
2