找回密码
 加入
搜索
查看: 13251|回复: 15

[系统综合] [已解决]API 控制移动WIN系统任务栏的问题

  [复制链接]
发表于 2012-12-19 18:04:06 | 显示全部楼层 |阅读模式
本帖最后由 小影 于 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[0],"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自带的函数表示也没有什么效果。

寻求不受任务栏中显示有多少文件影响,能够移动的函数!
发表于 2012-12-19 20:49:52 | 显示全部楼层
#Include <WinAPIEx.au3>
_WinAPI_ShellAppBarMessage

评分

参与人数 1金钱 +30 收起 理由
小影 + 30 感谢蛋哥的指导!

查看全部评分

 楼主| 发表于 2012-12-20 09:57:47 | 显示全部楼层
回复 2# netegg






谢谢NETEGG指导,但是找不到你所说的_WinAPI_ShellAppBarMessage函数,查了一个MSDN,找到了这个函数的原型,但这个函数原型太复杂了,搞不明白,搞到一半搞不下去了。再求指导一下

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2012-12-20 10:02:06 | 显示全部楼层
本帖最后由 小影 于 2012-12-20 10:04 编辑

补充一下,RC指向的结构,还没有对元素进行赋值,RC指向的是坐标值位置!

SHAppBarMessage 函数地址
http://msdn.microsoft.com/en-us/library/bb762108(v=VS.85).aspx
发表于 2012-12-20 14:04:45 | 显示全部楼层
本帖最后由 netegg 于 2012-12-20 14:20 编辑

[au3]
;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("[CLASS:Shell_TrayWnd]", "") ; 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[0]) Then
                Return SetError(1, 0, 0)
        EndIf
        Local $Result[5]
        $Result[0] = DllStructGetData($tAPPBARAPPBARDATA, 'uEdge')
        $Result[1] = DllStructGetData($tAPPBARAPPBARDATA, 'Left')
        $Result[2] = DllStructGetData($tAPPBARAPPBARDATA, 'Top')
        $Result[3] = DllStructGetData($tAPPBARAPPBARDATA, 'Right')
        $Result[4] = DllStructGetData($tAPPBARAPPBARDATA, 'Bottom')

        Return $Result
EndFunc   ;==>_WinAPI_ShellAppBarMessage

[/au3]
 楼主| 发表于 2012-12-20 14:34:04 | 显示全部楼层
本帖最后由 小影 于 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[0],"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("[CLASS:Shell_TrayWnd]", "") ; 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[0]) Then
                Return SetError(1, 0, 0)
        EndIf
        Local $Result[5]
        $Result[0] = DllStructGetData($tAPPBARAPPBARDATA, 'uEdge')
        $Result[1] = DllStructGetData($tAPPBARAPPBARDATA, 'Left')
        $Result[2] = DllStructGetData($tAPPBARAPPBARDATA, 'Top')
        $Result[3] = DllStructGetData($tAPPBARAPPBARDATA, 'Right')
        $Result[4] = DllStructGetData($tAPPBARAPPBARDATA, 'Bottom')
 
        Return $Result
EndFunc   ;==>_WinAPI_ShellAppBarMessage
#CS 
dwMessage [in] 
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
发表于 2012-12-20 14:43:01 | 显示全部楼层
3的话要给$tagRect赋值
 楼主| 发表于 2012-12-20 14:59:34 | 显示全部楼层
回复 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[0], "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("[CLASS:Shell_TrayWnd]", "") ; 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[0]) Then
                Return SetError(1, 0, 0)
        EndIf
        Local $Result[5]
        $Result[0] = DllStructGetData($tAPPBARAPPBARDATA, 'uEdge')
        $Result[1] = DllStructGetData($tAPPBARAPPBARDATA, 'Left')
        $Result[2] = DllStructGetData($tAPPBARAPPBARDATA, 'Top')
        $Result[3] = DllStructGetData($tAPPBARAPPBARDATA, 'Right')
        $Result[4] = DllStructGetData($tAPPBARAPPBARDATA, 'Bottom')

        Return $Result
EndFunc   ;==>_WinAPI_ShellAppBarMessage

发表于 2012-12-20 15:49:30 | 显示全部楼层
回复 8# 小影

DllStructSetData($tagAPPBARAPPBARDATA,"tagRECT",DllStructGetPtr($apirc))
这句是什么意思
 楼主| 发表于 2012-12-20 15:54:39 | 显示全部楼层
回复 9# netegg
给元素TAGRECT赋值,赋值结构是$APIRC
发表于 2012-12-20 15:56:06 | 显示全部楼层
本帖最后由 netegg 于 2012-12-20 15:58 编辑

回复 10# 小影

给$tagAPPBARAPPBARDATA结构元素赋值能直接使用$tagAPPBARAPPBARDATA结构吗
 楼主| 发表于 2012-12-20 16:03:53 | 显示全部楼层
$tagAPPBARAPPBARDATA结构中含有RECT元素,而RECT指向的又是一个结构,所以我的想法应该是得为$tagAPPBARAPPBARDATA中的RECT元素构造一个RECT原型结构引用
发表于 2012-12-20 16:10:51 | 显示全部楼层
回复 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("[CLASS:Shell_TrayWnd]", "") ; 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[0]) Then
                Return SetError(1, 0, 0)
        EndIf
        Local $Result[5]
        $Result[0] = DllStructGetData($tagAPPBARAPPBARDATA, 'uEdge')
        $Result[1] = DllStructGetData($tagAPPBARAPPBARDATA, 'Left')
        $Result[2] = DllStructGetData($tagAPPBARAPPBARDATA, 'Top')
        $Result[3] = DllStructGetData($tagAPPBARAPPBARDATA, 'Right')
        $Result[4] = DllStructGetData($tagAPPBARAPPBARDATA, 'Bottom')
        Return $Result

EndFunc   ;==>_WinAPI_ShellAppBarMessage

评分

参与人数 1金钱 +20 收起 理由
小影 + 20 感谢关注!

查看全部评分

发表于 2012-12-20 16:20:18 | 显示全部楼层
本帖最后由 netegg 于 2012-12-20 16:37 编辑

uEdge元素的定义呢,顶底左右不是有常量定义吗
left和top元素不能为负吧,msdn上解释是屏幕坐标
发表于 2012-12-21 08:28:48 | 显示全部楼层
回复 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才能改大小或者位置,系统的改不了
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-11-1 07:21 , Processed in 0.111382 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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