Is a rectangle on a monitor?
-
Is there a way to find out whether a rectangle or a point (given in screen coordinates) is contained in any monitor currently attached to the system? The background of my question is this: During shutdown, my dialog based MFC application stores its current screen coordinates in the registry. When I open the application the next time, it fetches the coordinates and moves the window to where it had been during the most recent session. If I move the dialog to my secondary monitor and close it, then unplug the monitor and restart the application, the dialog displays itself on an invisible part of the desktop :^) . In this case, I'd prefer to use the default location - the center of the primary monitor.
-
Is there a way to find out whether a rectangle or a point (given in screen coordinates) is contained in any monitor currently attached to the system? The background of my question is this: During shutdown, my dialog based MFC application stores its current screen coordinates in the registry. When I open the application the next time, it fetches the coordinates and moves the window to where it had been during the most recent session. If I move the dialog to my secondary monitor and close it, then unplug the monitor and restart the application, the dialog displays itself on an invisible part of the desktop :^) . In this case, I'd prefer to use the default location - the center of the primary monitor.
There are several functions that would work.
MonitorFromPoint
/MonitorFromRect
will give you a handle to the monitor. You can then use this handle in the functionGetMonitorInfo
to get more information. Here is an example from MSDN on how it could be done - Positioning Objects on a Multiple Display Setup[^]«_Superman_»
I love work. It gives me something to do between weekends. -
Is there a way to find out whether a rectangle or a point (given in screen coordinates) is contained in any monitor currently attached to the system? The background of my question is this: During shutdown, my dialog based MFC application stores its current screen coordinates in the registry. When I open the application the next time, it fetches the coordinates and moves the window to where it had been during the most recent session. If I move the dialog to my secondary monitor and close it, then unplug the monitor and restart the application, the dialog displays itself on an invisible part of the desktop :^) . In this case, I'd prefer to use the default location - the center of the primary monitor.
-
There are several functions that would work.
MonitorFromPoint
/MonitorFromRect
will give you a handle to the monitor. You can then use this handle in the functionGetMonitorInfo
to get more information. Here is an example from MSDN on how it could be done - Positioning Objects on a Multiple Display Setup[^]«_Superman_»
I love work. It gives me something to do between weekends.