LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Get Usable Monitor Size

Solved!
Go to solution

This is a difficult one to search for, and is OS specific.  But what I'm trying to do is get the size of all usable space on all monitors.  By this I mean the space a window would take up, if it were made full screen, but without having to make it full screen.

 

I have a UI function that will popup a small window under the mouse if you perform some action, to show more detailed information about what you moused over.  I want this window to appear centered under the mouse coordates, but I want it to fit on the current monitor, and I want the whole window visible.

 

So if my mouse is in the upper left corner of my monitor, I want my window to appear in the upper left corner but have it all visible.  If my mouse is just above the task bar, I want the whole window to appear above the taskbar, but still under the mouse.  What I'm trying to avoid is poping up a window that is cut off by clipping off the monitor, or under the taskbar.

 

The Display >> All Monitors property helps get the bounds of all monitors, but this is the resolution of the display and won't take into account a task bar that is likely on the bottom of the window, but potentially could be any where, or could even be hidden.

 

Any thoughts on this?  My only partial solution I haven't tried, but assume would work, is to make the window hidden, maximize it, get the window bounds, then unmaximize it.  Is there some function I'm missing?  Thanks.

0 Kudos
Message 1 of 24
(8,391 Views)

The Display >> Primary Workspace property responds to the task bar being moved and resized.

0 Kudos
Message 2 of 24
(8,384 Views)

What happens if you have the taskbar on a different window? I am assuming that your method will still work.

 

[EDIT]

 You should be able to use the USER32.dll command GetMonitorInfo to return usable info, although I'm not sure if this is a better method then you already have.

[EDIT #2]

I think this method may actually be what kyle is calling in his diagram below

0 Kudos
Message 3 of 24
(8,377 Views)
Solution
Accepted by topic author Hooovahh

Using .NET nodes:

Screen working area.png

 

That first one is System.Windows.Forms.Screen

 

On my system (1920x1080) this returns 1920, 1040.  My taskbar is 40 pixels high.

 

Instead of choosing the "PrimaryScreen" there is also an "AllScreens" property, which is an array of Screens. This will allow you to check every monitor on the PC.

Message 4 of 24
(8,362 Views)

I think the display >> primary workspace property node will give all the information you need if you want to compensate for taskbars that are not guaranteed to be at the bottom.

 

screen border.png

Message 5 of 24
(8,344 Views)

Thanks guys that was quick.  The issue with the LabVIEW native one is it only works on your primary monitor, and I first want to figure out which monitor the mouse is on, then put the new window in that.  So in my case the .Net solution works by using the All Screens read, then iterating over all of them.  I also don't know what kinds of taskbars I may or may not find on the other monitors either.  

0 Kudos
Message 6 of 24
(8,319 Views)

I can confirm Gregory's suggestion -- the Display:Primary Workspace property does what you want.  I usually AutoHide the Taskbar, so I get coordinates of 0, 0, 1280, 1024.  If I turn off "AutoHide" and have the Taskbar at the bottom, the coordinates are 0, 0, 1280, 984.  If the Taskbar is on the right, they are 0, 0, 1218, 1024, on the left 62, 0, 1280, 1024, and on top 0, 40, 1280, 1024.

 

Pretty neat!  So easy (once Gregory points it out to us) ...

 

Bob Schor

0 Kudos
Message 7 of 24
(8,305 Views)

Initially I was concerned that Kyles solution might just give the workable area but after going back into it, you can use the Rectangle node to get all the points of interest no matter where the taskbar is located (hidden, left, right, top, bottom)

 

Corners.png

Message 8 of 24
(8,275 Views)

Why use the .NET methods (which require "hooks" into Windows, and possibly expertise I might not posess) when the App Property Node seems to do the same thing?

 

One answer that occurs to me is the Property Node only handles "Working Area" for the Primary Screen.  In particular, if you move the TaskBar to the Secondary Screen, there's no way (with LabVIEW Properties) to get the reduced Working Area on the Secondary Screen.  You can get the Bounds and Depth of All Monitors, but that doesn't show Working Area.

 

Turns out (unless I missed something) that .NET doesn't do any better.  As near as I can tell, if the Task Bar is on the Secondary Screen, the .NET properties don't allow you to tell this.  But I'm not a .NET expert, so maybe I'm wrong about this ...

 

Bob Schor

0 Kudos
Message 9 of 24
(8,209 Views)

If you use the nodes like this:

allscreens.png

You get this on my system 2x 1080p monitors, taskbar on main monitor:

primary monitor taskbar.png

If I move the taskbar to my second monitor and rerun it, I get:

secondary monitor taskbar.png

So it does appear to work on all monitors...

 

 

Message 10 of 24
(8,201 Views)