Note that there are some explanatory texts on larger screens.

plurals
  1. POPositioning A Form From A SysTray Icon
    primarykey
    data
    text
    <p>I'd like to display a form off of a systray icon event, which just shows some information next to the taskbar and disappears itself after some time. The main issue I'm running into is positioning the form in a way that it is both in the correct position and visible. I found a couple of ways to determine where the icon is, but in testing I found them inconsistent based on OS (I attempted this in another app and ended up giving up and using a centered modal form). For example:</p> <pre><code>procedure GetWorkAreaRect(var outrect: TRect); // returns the dimensions of the work area. begin Systemparametersinfo(SPI_GETWORKAREA, 0, @outrect, 0); end; </code></pre> <p>The problem when that works is determining from there where to put the form (above, below, left, right). Any suggestions?</p> <p><strong>Edit:</strong> The problem is in <strong>positioning the form</strong> in relationship to the system tray icon, not necessarily determining where the system tray icon is. I made another attempt and got it working <em>as long as some conditions are met</em>. Most notably, it doesn't work if the taskbar is set to auto-hide, because the assumption is made that the click is made outside of the work area. This is not true when the form is set to auto-hide.</p> <pre><code>function PositionForm(X, Y, Width, Height: Integer): TPoint; // receives mouse-click position in X and Y, form width and height in width and height // returns Left and Top in TPoint.X and TPoint.Y. var workrect: TRect; resrect: TPoint; begin GetWorkAreaRect(workrect); if Y &gt; WorkRect.Bottom then // taskbar is on bottom begin resRect.X := WorkRect.Right - Width; resrect.Y := WorkRect.Bottom - Height; end else if X &gt; WorkRect.Right then // taskbar is on right begin resrect.X := WorkRect.Right - Width; resrect.Y := WorkRect.Bottom - Height; end else if X &lt; WorkRect.Left then // taskbar is on left begin resrect.X := WorkRect.Left; resrect.Y := WorkRect.Bottom - Height; end else if Y &lt; WorkRect.Top then // taskbar is on top begin resrect.X := WorkRect.Right - Width; resrect.Y := WorkRect.Top; end; Result := ResRect; end; </code></pre> <p>So on the surface, it seems the issue is to find an independent way to determine where the taskbar resides...or could the logic be extended above to take care of this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload