Ok slight brain fart…
I need to position an SDI window at runtime (center horizontally and above the taskbar)
I use the GetPosition(myWindow, x, y, w ,h) but missing how to get the total width/height of the desktop and the height of the taskbar?
TIA
Ok slight brain fart…
I need to position an SDI window at runtime (center horizontally and above the taskbar)
I use the GetPosition(myWindow, x, y, w ,h) but missing how to get the total width/height of the desktop and the height of the taskbar?
TIA
You can try using the GetSystemMetrics function for get the screen size
MODULE('Windows')
GetSystemMetrics( LONG nIndex ), LONG, PASCAL, DLL(1)
END
SM_CXSCREEN EQUATE(0) ! Total screen width in pixels
SM_CYSCREEN EQUATE(1) ! Total screen height in pixels
SM_CXFULLSCREEN EQUATE(16) ! Width of maximized window client area (excludes taskbar)
SM_CYFULLSCREEN EQUATE(17) ! Height of maximized window client area (excludes taskbar)
ScreenWidth LONG
ScreenHeight LONG
ScreenWidth = GetSystemMetrics(SM_CXSCREEN)
ScreenHeight = GetSystemMetrics(SM_CYSCREEN)
Hope this helps
Tuz
That will only be the Primary Monitor which probably works for your desire to be above the Taskbar.
System Metrics does not handle Multiple Monitors that are very common. You need to use the Monitor API to find the monitor your on window is on MonitorFromWindow and GetMonitorInfo for its size.
In Clarion you will need to Set Position in Pixels not DLUs.
I think Devuna may have the Monitor code on its GitHub.
If you have a 2+ monitor setup…
The order of the monitors ie 1,2 & 3) does not affect the XY pos.
Only the main display affects the XY pos.
In this example the main display is the centre monitor ie #2.
Bottom left of the main display is 0,0.
Every monitor to the left (or below) the main display with have negative XY positions.
Every monitor to the right (or above) the main display will have a positive XY pos.
The overview for Windows desktop positions is perhaps summarised like this.
Physical Machine
|------ Window's Station 1
| |-------------- Desktop 1
| |-------------- Desktop 2 (optional)
| |-------------- Desktop 3 (optional)
|
|------ Windows Station 2 (optional) - typically Remote Desktop Services (RDS) aka Terminal Services (TS)
|--------------- Desktop 1
|--------------- Desktop 2 (optional)
In most cases your app will be dealing with a single Windows Station with a single Desktop, but in Win11 (19H2 iirc) a new taskbar button was included which makes it quick and easy for a user to create new desktops, and then run apps in isolation on the newly created desktop, although if you use a favourite of @lodestar, you can still communicate easily using a file (or a pipe).
Throw in the fact some of the more powerful graphics cards lets you create any number of virtual monitor settings, and windows will only see what your graphics card wants it to see, then things get more interesting.
For example you could have a single physical ultrawide monitor, and your graphics card can turn that into 3 virtual monitors laid out like the example above.
You could have 3 physical monitors laid out like the example above and turn it into a single virtual ultrawide monitor.
The graphics card can make one of those monitors have a different screen resolution, be above or below the other monitors when physically they are all side by side.
The graphics card can simulate virtually any physical display hardware to Windows.
Your app will only see what Window’s see’s on the Desktop its told to run on.
That also makes Browser fingerprinting interesting and you can control multiple web browsers using an automation plugin… ![]()
MSDN page on GetSystemMetrics for “Full Screen” says:
To get the coordinates of the portion of the screen that is not obscured by the system taskbar or by application desktop toolbars, call the SystemParametersInfo function with the SPI_GETWORKAREA value.
The Work Area is a RECT which gives you the Upper-Left (X,Y) so you don’t have to assume (0,0). The Taskbar does not have to be at the bottom. IIRC in Windows 11 it cannot be moved in Settings (changing soon?), it can be done with a registry change.
SPI_GETWORKAREA EQUATE(30h)
Retrieves the size of the work area on the primary display monitor. The work area is the portion of the screen not obscured by the system taskbar or by application desktop toolbars. The pvParam parameter must point to a RECT structure that receives the coordinates of the work area, expressed in physical pixel size. Any DPI virtualization mode of the caller has no effect on this output.
To get the work area of a monitor other than the primary display monitor, call the GetMonitorInfo function.
SHAppBarMessage can get the Taskbar position Rect and Auto Hide.