2010-01-14 39 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

相關問題