Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Is a rectangle on a monitor?

Is a rectangle on a monitor?

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++windows-admin
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hans sch
    wrote on last edited by
    #1

    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.

    _ K 2 Replies Last reply
    0
    • H hans sch

      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.

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      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 function GetMonitorInfo 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.

      Microsoft MVP (Visual C++)

      Polymorphism in C

      H 1 Reply Last reply
      0
      • H hans sch

        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.

        K Offline
        K Offline
        KarstenK
        wrote on last edited by
        #3

        Repositioning Windows on Multiple Monitor Systems[^]

        Press F1 for help or google it. Greetings from Germany

        1 Reply Last reply
        0
        • _ _Superman_

          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 function GetMonitorInfo 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.

          Microsoft MVP (Visual C++)

          Polymorphism in C

          H Offline
          H Offline
          hans sch
          wrote on last edited by
          #4

          Superman, that was a superfast and supergood answer. It works :) Thanks!

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups