UNeverNo
UNeverNo

Reputation: 583

Get screen on which application is running

I want to detect on which screen a window is displayed when I got its handle. I found a SetWindowPos() function in Win API, but unfortunately there is no GetWindowPos() just a GetWindowRect(), but this results some odd values.

I got two devices, left one 1280x1024 and right one (primary) 1680x1050. When I want to get the position of a minimized firefox, I get b/l/r/t -31973/-32000/-31840/-32000 for either screen.

How do I know that it is my left or my right screen?

Upvotes: 2

Views: 1147

Answers (2)

peterchen
peterchen

Reputation: 41096

WinAPI has a MonitorFromRect function, which is probably what you need. I'm not sure if there's a C# equivalent, but you can call it through interop.

Be aware that the window can be on both monitors, or on neither. The API has flags for that, e.g. MONITOR_DEFAULTTONEAREST.

Upvotes: 2

Ben Voigt
Ben Voigt

Reputation: 283634

Try GetWindowPlacement, in order to find the rectangle that the window will use if it were restored.

Upvotes: 2

Related Questions