TaskbarEdge() : Returns the side of the monitor the taskbar is on

Post your working scripts, libraries and tools
User avatar
SKAN
Posts: 861
Joined: 29 Sep 2013, 16:58

TaskbarEdge() : Returns the side of the monitor the taskbar is on

15 Sep 2020, 08:32

Usage example: MsgBox % TaskbarEdge().
Returns one of these values: LTRB (Left, Top, Right, Bottom)
On a multi-monitor setup, you may use WinGetPos or MouseGetPos or SysGet to find X and Y and pass it to TaskbarEdge()
 
 
The function
 

Code: Select all

TaskbarEdge( X:=0, Y:=0 ) {                         ; by SKAN on D39F/D39F @ tiny.cc/taskbaredge
Local hMonitor:=VarSetCapacity(var,84,0),  v:=NumPut(40,var,"Int")-4
  hMonitor := DllCall("MonitorFromPoint", "Int64",(X & 0xFFFFFFFF) | (Y << 32), "Int",0, "UPtr")
  DllCall("GetMonitorInfo", "Ptr",hMonitor, "Ptr",v)
  DllCall("GetWindowRect", "Ptr",WinExist("ahk_class Shell_SecondaryTrayWnd"), "Ptr",v+68)
  DllCall("SubtractRect", "Ptr",v+52, "Ptr",v+4, "Ptr",v+68)
  DllCall("GetWindowRect", "Ptr",WinExist("ahk_class Shell_TrayWnd"), "Ptr",v+36)
  DllCall("SubtractRect", "Ptr",v+20, "Ptr",v+52, "Ptr",v+36)
Return NumGet(v+12,"Int")>NumGet(v+28,"Int") ? "R" : NumGet(v+16,"Int")>NumGet(v+32,"Int") ? "B"
  : NumGet(v+20,"Int")>NumGet(v+4,"Int") ? "L" : NumGet(v+24,"Int")>NumGet(v+8,"Int") ? "T" : ""
}
 
 
The following is a customized version for ShowMenu()
Call example: ShowMenu( MenuGetHandle("Tray"), False, TrayMenuParams()* )
 
TrayMenuParams()
User avatar
Delta Pythagorean
Posts: 574
Joined: 13 Feb 2017, 13:44
GitHub: DelPyth
Location: Somewhere in the US

Re: TaskbarEdge() : Returns the side of the monitor the taskbar is on

15 Sep 2020, 12:28

Ah, perfect timing! I was working on a quick OSD program and needed to find the taskbar's edge. This'll be quite interesting to work with!

- [AHK].......: 1.1.33.02 Unicode 64-bit
- [OS].........: Windows 10.0.19041
- [GITHUB]...: github.com/DeltaPyth
- [PAYPAL]....: paypal.me/DelPyth
- [DISCORD]..: Tophat Cat // Delta#8888

Remember to use [code]CODE[/code] for your multi-line scripts.
Stay safe, stay inside, and remember to wash your hands for 20 seconds!
User avatar
SKAN
Posts: 861
Joined: 29 Sep 2013, 16:58

Re: TaskbarEdge() : Returns the side of the monitor the taskbar is on

15 Sep 2020, 12:46

@Delta Pythagorean

Thanks for the feedback :thumbup: :)

Some info:

The original RECT of the monitor is @ v+4
immediately followed by the
*Subtracted RECT of the monitor @ v+20

* RECT of the monitor minus RECT of the Taskbar.

You may replace the return line with following for better understanding.

Code: Select all

  Loop % (8, offset:=0)
    v%A_Index% := NumGet(v+0, offset+=4, "Int")
Return (v3>v7 ? "Right" : v4>v8 ? "Bottom" : v5>v1 ? "Left" : v6>v2 ? "Top" : "")

:)

Return to “Scripts and Functions”

Who is online

Users browsing this forum: Jinpachi, malcev, pgeugene, seddion and 14 guests