Get available screen area in autohotkey

I'm trying to write some simple AutoHotkey scripts to move windows around, and I'm having trouble getting the right screen size values.

I'm trying to get the size of the usable area on the screen (usually the full screen resolution minus the taskbar, and possibly any other attached windows, such as the sidebar in Vista). None of the methods I found to get the width of the screen work.

None of the three methods I found to get the screen size gives me the correct values. Here is the test script I am using (works on XP with the default lower taskbar):

#7::
WinMove A,,0,0,A_ScreenWidth,A_ScreenHeight
return

#8::
;SM_CXMAXIMIZED and SM_CYMAXIMIZED
SysGet, ScreenWidth, 61
SysGet, ScreenHeight, 62
WinMove A,,0,0,ScreenWidth,ScreenHeight
return

#9::
;SM_CXFULLSCREEN and SM_CYFULLSCREEN
SysGet, ScreenWidth, 16
SysGet, ScreenHeight, 17
WinMove A,,0,0,ScreenWidth,ScreenHeight
return

# 7 forces the window to accept all resolutions, so it overrides the taskbar.

# 8 ( , ), , . , , , .

# 9 , . , , 30 .

, # 9, 30 , , , . , , AutoHotkey.

, , , Java:

Toolkit.getDefaultToolkit().getScreenSize();
+5
2

- XP. , , , Vista , . , .

, , ResizeAndCenter, :

; Gets the edge that the taskbar is docked to.  Returns:
;   "top"
;   "right"
;   "bottom"
;   "left"
GetTaskbarEdge() {
  WinGetPos,TX,TY,TW,TH,ahk_class Shell_TrayWnd,,,

  if (TW = A_ScreenWidth) { ; Vertical Taskbar
    if (TY = 0) {
      return "top"
    } else {
      return "bottom"
    }
  } else { ; Horizontal Taskbar
    if (TX = 0) {
      return "left"
    } else {
      return "right"
    }
  }
}

GetScreenTop() {
  WinGetPos,TX,TY,TW,TH,ahk_class Shell_TrayWnd,,,
  TaskbarEdge := GetTaskbarEdge()

  if (TaskbarEdge = "top") {
    return TH
  } else {
    return 0
  }
}

GetScreenLeft() {
  WinGetPos,TX,TY,TW,TH,ahk_class Shell_TrayWnd,,,
  TaskbarEdge := GetTaskbarEdge()

  if (TaskbarEdge = "left") {
    return TW
  } else {
    return 0
  }
}

GetScreenWidth() {
  WinGetPos,TX,TY,TW,TH,ahk_class Shell_TrayWnd,,,
  TaskbarEdge := GetTaskbarEdge()

  if (TaskbarEdge = "top" or TaskbarEdge = "bottom") {
    return A_ScreenWidth
  } else {
    return A_ScreenWidth - TW
  }
}

GetScreenHeight() {
  WinGetPos,TX,TY,TW,TH,ahk_class Shell_TrayWnd,,,
  TaskbarEdge := GetTaskbarEdge()

  if (TaskbarEdge = "top" or TaskbarEdge = "bottom") {
    return A_ScreenHeight - TH
  } else {
    return A_ScreenHeight
  }
}

ResizeAndCenter(w, h)
{
  ScreenX := GetScreenLeft()
  ScreenY := GetScreenTop()
  ScreenWidth := GetScreenWidth()
  ScreenHeight := GetScreenHeight()

  WinMove A,,ScreenX + (ScreenWidth/2)-(w/2),ScreenY + (ScreenHeight/2)-(h/2),w,h
}
+4

All Articles