2010-01-14 70 views
25

我想知道任何类型的API或解决方法(例如,脚本或注册表)将Windows任务栏移动(或调整大小)到另一个位置,包括另一个显示器(如果双显示器)。当然,我们可以使用鼠标移动任务栏,但我想通过程序或某种自动化方式移动它。如何以编程方式移动Windows任务栏?

我试图找到Win32 API,但似乎没有人做这份工作。

编辑:我很惊讶很多人的意见。让我解释为什么我想要它。在我的工作场所,我使用双显示器(分辨率不同),任务栏放在左侧显示器上,而主显示器是正确的显示器。但是,我经常通过远程桌面连接到我的工作场所计算机。在远程连接之后,任务栏位置被切换。这就是为什么我想制作一个简单的程序,可以保存/恢复任务栏的位置。每天我都必须重新安排我的任务栏。而已。我只是想要它

+2

为什么downvote?这是一个非常完美的问题。至于这个可疑的意图,我在这里看到了更糟糕的答案...... – Thomas 2010-01-14 21:24:39

+0

好吧,托马斯,可以说这个问题没有用,因为它不是程序应该做的任务。但是,我们并不真正了解Minjang计划的意图,所以我们都会给出疑问的好处,我们呢? – 2010-01-14 21:34:24

+8

“不是程序应该做的任务” - 真的吗?你如何得出Rob的结论?如果你曾经在多显示器环境中工作过,那么你会知道这些类型的应用程序(如UltraMon - http://www.realtimesoft.com/ultramon/)几乎是必不可少的。谁指定了你什么程序应该做的上帝?这是一个非常好的问题;从我+1。 – Gerard 2010-01-14 21:47:16

回答

3

据我所知,Vista和起忽略任何程序试图移动任务栏。旧方法是ABM_SETPOS + MoveWindow,这不再适用于任务栏。我意识到这一点仍然有效的唯一方法是模拟鼠标移动(点击移动释放)。我已经阅读过有关该方法的内容,但我从来没有做过。

6

任务栏是一个窗口。使用SetWindowPos()来移动它。另请参阅SHAppBarMessage()和ABM_WINDOWPOSCHANGED。

尽管任务栏可能是特殊的,Windows可能不喜欢你移动它。在任务栏的Shell appbar API实现中有很多特殊情况。

要移动到另一台显示器,请使用EnumDisplayMonitors()GetMonitorInfo()。一些监视器可能具有负坐标。

+1

这是一个糟糕的主意。请不要这样做给你的客户。 – 2010-01-15 02:59:13

+7

直到OP告诉我们他为什么要这样做,我们不知道。有两件事需要考虑:是否有可能,是否是一个好主意。我们只是在这里考虑前者而不是后者。虽然我一般同意移动用户任务栏并不好,但我也可以看到至少有两个有效的情况用于根据用户请求移动它。既然我们不知道,让我们尽量不要判断太多。 – 2010-01-15 03:10:15

+0

@jeffamaphone:我们在这里,因为我们选择在这里。你是谁说我们只是为了一个而不是另一个? – 2010-01-15 03:14:21

0

SHAppBarMessage(ABM_SETPOS,...)

+1

'ABM_GETTASKBARPOS'检索任务栏的位置。但是,ABM_SETPOS运行不正常。我通过查找“Shell_TrayWnd”获得了任务栏的hWnd。 (我正在使用Windows 7)但是,没有运气。 MoveWindow/SetWindowPos和其他任何ABM_ *都不起作用。但是,谢谢。 – minjang 2010-01-15 05:26:47

4

我已经在AutoHotkey脚本中使用了这个任务的一些运气,以防万一你不关心使用的语言。它使用模拟击键和鼠标移动来移动任务栏。我没有自动解锁/锁定任务栏。

难的部分是让它可靠地工作。许多代码致力于确保任务栏移动。它仍然不能100%地工作......它从我所看到的10%的时间里失败了。但是,它应该足以让你开始!

如果我回到这个脚本,使其完美工作,我会在这里重新发布。

下面是示例脚本(高亮有点奇怪,在这里,因为语言是AHK):

F3:: 
    reload 
return 

F5:: 
    MoveTaskbar(2,"bottom") 
return 

F6:: 
    MoveTaskbar(2,"left") 
return 

F7:: 
    MoveTaskbar(1,"top") 
return 

; Move the taskbar 
; dspNumber: number. device number (primary display is 1, secondary display is 2...) 
; edge:   string. Top, Right, Bottom, or Left 
MoveTaskbar(dspNumber, edge) 
{ 
    Critical 
    OutputDebug MoveTaskbar - called to move taskbar to display #%dspNumber% ("%edge%" edge) 

    ; absolute coordinate system 
    CoordMode, Mouse, Screen 

    ; error checking for dspNumber 
    SysGet, numMonitors, MonitorCount 
    if (numMonitors<dspNumber) 
    { 
     OutputDebug MoveTaskbar - [ERROR] target monitor does not exist (dspNumber = "%dspNumber%") 
     return 
    } 

    ; get screen position for target monitor 
    SysGet, target, Monitor, %dspNumber% 

    oX := 7 
    oY := 7 

    ; get coordinates for where to move the taskbar 
    if (edge = "Top") 
    { 
     oX := (targetRight-targetLeft)/2 
     trgX := oX+targetLeft 
     trgY := targetTop+15 
    } 
    else if (edge = "Right") 
    { 
     oY := -(targetBottom-targetTop)/2 
     trgX := targetRight-15 
     trgY := -oY + targetTop 
    } 
    else if (edge = "Bottom") 
    { 
     oX := -(targetRight-targetLeft)/2 
     trgX := -oX+targetLeft 
     trgY := targetBottom-15 
    } 
    else if (edge = "Left") 
    { 
     oY := (targetBottom-targetTop)/2 
     trgX := targetLeft+15 
     trgY := oY+targetTop 
    } 
    else 
    { 
     OutputDebug MoveTaskbar - [ERROR] target edge was improperly specified (edge = "%edge%") 
     return 
    } 
    trgX := round(trgX) 
    trgY := round(trgY) 
    oX := round(oX) 
    oY := round(oY) 

    OutputDebug MoveTaskbar - target location is (%trgX%,%trgY%) 
    MouseGetPos, startX, startY 
    OutputDebug MoveTaskbar - mouse is currently at (%startX%,%startY%) 

    ; request the move mode (via context menu) 
    SendInput #b 
    SendInput !+{Space} 
    SendInput m 

    ; wait for the move mode to be ready 
    Loop 
    { 
     if A_Cursor = SizeAll 
      break 
    } 
    OutputDebug MoveTaskbar - move mode is ready 

    ; start the move mode 
    SendInput {Right} 

    ; wait for the move mode to become active for mouse control 
    Loop 
    { 
     if A_Cursor = Arrow 
      break 
    } 
    OutputDebug MoveTaskbar - move mode is active for mouse control 

    ; move taskbar (and making sure it actually does move) 
    offset := 7 
    count := 0 
    Loop 
    { 
     ; move the taskbar to the desired location 
     OutputDebug MoveTaskbar - attempting to move mouse to (%trgX%,%trgY%) 
     MouseMove, %trgX%, %trgY%, 0 
     MouseGetPos, mX, mY, win_id 
     WinGetClass, win_class, ahk_id %win_id% 

     count += 1 

     ; if the mouse didn't get where it was supposed to, try again 
     If ((mX != trgX) or (mY != trgY)) 
     { 
      OutputDebug MoveTaskbar - mouse didn't get to its destination (currently at (%mX%,%mY%)). Trying the move again... 
      continue 
     } 

     ; if the taskbar hasn't followed yet, wiggle the mouse! 
     if (win_class != "Shell_TrayWnd") 
     { 
      OutputDebug MoveTaskbar - window with class "%win_class%" is under the mouse... wiggling the mouse until the taskbar gets over here 

      ;offset := - offset 
      trgX -= round(oX/2) 
      trgY -= round(oY/2) 
      oX := -oX 
      oY := -oY 
      if count = 50 
      { 
       OutputDebug, MoveTaskbar - wiggling isn't working, so I'm giving up. 
       return 
      } 
     } 
     else 
      break 
    } 

    OutputDebug MoveTaskbar - taskbar successfully moved 
    SendInput {Enter} 
} 
7

我也有这方面的需要在Windows 7这是我拿去做这个使用AutoHotkey的脚本:

; This script will try to drag and move the taskbar to where the *current* mouse 
; cursor is 

; 0x111: WM_COMMAND, 424: lock/unlock taskbar, http://www.codeproject.com/KB/miscctrl/Taskbar_Manipulation.aspx 
RegRead, TaskbarLocked, HKEY_CURRENT_USER, SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced, TaskbarSizeMove 
If TaskbarLocked = 0 
    SendMessage 0x111, 424, , , ahk_class Shell_TrayWnd 

WinActivate ahk_class Shell_TrayWnd 
MouseGetPos targetX, targetY 
ControlGetPos x, y, w, h, MSTaskListWClass1, ahk_class Shell_TrayWnd 
MouseMove x+1, y+1 
MouseClickDrag Left, x+1, y+1, targetX, targetY, 10 

; often after dragging the taskbar to left or right side of a monitor, even though 
; there are enough room to show two columns of icons, it will only show one column, 
; it seems showing or hiding an icon will fix this 
Menu, Tray, NoIcon 
Menu, Tray, Icon 

; lock the taskbar if it was previously locked 
If TaskbarLocked = 0 
    SendMessage 0x111, 424, , , ahk_class Shell_TrayWnd 

我已经在Windows 7上用经典的窗口主题测试过了。要使用此功能,请指定一个热键来调用此脚本,然后将鼠标光标放到要将任务栏拖动到的位置,然后按热键。

+0

完美的作品!谢谢! (我不得不调整确切的坐标到x + 10,y-35为我的决议和主题) – staafl 2013-02-13 09:12:54

+0

正是我需要的,这让我疯狂。谢谢!注意:我必须使用w和h变量为不同的任务栏起始位置定义单独的偏移量。 – 2013-03-13 20:32:59

+0

适用于Windows 10.我稍微修改了它,使任务栏始终具有相同的大小,并将其添加到调度程序以在工作站解锁上运行。 – 2016-12-03 17:56:18

相关问题