Taskbar position
For some applications, it’s important to know, where the taskbar is located. Of course, most users use standard “bottom of the screen” position, but of course, you can place it to the left, rigtht or top of the screen. Here is the method to determine actual position.
Whole procedure is pretty simple. We find coordinates of the taskbar using FindWindow and GetWindowRect functions. And then we compare them with Screen coordinates (area).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<span style="font-weight: bold;">procedure</span> TForm1.Button1Click(Sender: <span style="font-weight: bold;">TObject</span>); <span style="font-weight: bold;">var</span> hTaskbar: HWND; T: TRect; ScrW, ScrH: <span style="font-weight: bold;">integer</span>; <span style="font-weight: bold;">begin</span> ScrW := Screen.Width; ScrH := Screen.Height; hTaskBar := FindWindow('Shell_TrayWnd', <span style="font-weight: bold;">nil</span>); GetWindowRect(hTaskBar, T); <span style="font-weight: bold;">if</span> (T.Top &gt; ScrH <span style="font-weight: bold;">DIV</span> 2) <span style="font-weight: bold;">and</span> (T.Right &gt;= ScrW) <span style="font-weight: bold;">then</span> ShowMessage('Bottom of the screen') <span style="font-weight: bold;">else</span> <span style="font-weight: bold;">if</span> (T.Top &lt; ScrH <span style="font-weight: bold;">DIV</span> 2) <span style="font-weight: bold;">and</span> (T.Bottom &lt;= ScrW <span style="font-weight: bold;">DIV</span> 2) <span style="font-weight: bold;">then</span> ShowMessage('Top of the screen') <span style="font-weight: bold;">else</span> <span style="font-weight: bold;">if</span> (T.left &lt; ScrW <span style="font-weight: bold;">DIV</span> 2) <span style="font-weight: bold;">and</span> (T.Top &lt;= 0) <span style="font-weight: bold;">then</span> ShowMessage('Left side of the screen') <span style="font-weight: bold;">else</span> ShowMessage('Right side of the screen'); <span style="font-weight: bold;">end</span>; |