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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. relative coordinates to absolute?

relative coordinates to absolute?

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelptutorial
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.
  • T Offline
    T Offline
    ThinkingPrometheus
    wrote on last edited by
    #1

    hiho@ll i'm using OnLButtonUp to get the coordinates of a mouseclick the problem: OnLButtonUp from MSDN: Specifies the x- and y-coordinate of the cursor. These coordinates are always relative to the upper-left corner of the window so i thought using GetWindowRect and just adding the values point.x+=rect.left AND point.y+=rect.top will convert the relative coordinates to absolute the problem is for example if my window is in the middle of the screen and i click on the top of the screen (the absolute y position should be between 0 or 10) i get an relative point.y coordinate -22!!!! which means i clicked 22 pixel above my window? but i clicked a few hundred pixels above my window! so how can i convert the relative coordinates to absolute?

    T I 2 Replies Last reply
    0
    • T ThinkingPrometheus

      hiho@ll i'm using OnLButtonUp to get the coordinates of a mouseclick the problem: OnLButtonUp from MSDN: Specifies the x- and y-coordinate of the cursor. These coordinates are always relative to the upper-left corner of the window so i thought using GetWindowRect and just adding the values point.x+=rect.left AND point.y+=rect.top will convert the relative coordinates to absolute the problem is for example if my window is in the middle of the screen and i click on the top of the screen (the absolute y position should be between 0 or 10) i get an relative point.y coordinate -22!!!! which means i clicked 22 pixel above my window? but i clicked a few hundred pixels above my window! so how can i convert the relative coordinates to absolute?

      T Offline
      T Offline
      ThatsAlok
      wrote on last edited by
      #2

      ThinkingPrometheus wrote: so how can i convert the relative coordinates to absolute? Use Api ScreenToClient() and ClientToScreen(), for more info consult MSDN.

      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

      cheers, Alok Gupta VC Forum Q&A :- I/ IV

      1 Reply Last reply
      0
      • T ThinkingPrometheus

        hiho@ll i'm using OnLButtonUp to get the coordinates of a mouseclick the problem: OnLButtonUp from MSDN: Specifies the x- and y-coordinate of the cursor. These coordinates are always relative to the upper-left corner of the window so i thought using GetWindowRect and just adding the values point.x+=rect.left AND point.y+=rect.top will convert the relative coordinates to absolute the problem is for example if my window is in the middle of the screen and i click on the top of the screen (the absolute y position should be between 0 or 10) i get an relative point.y coordinate -22!!!! which means i clicked 22 pixel above my window? but i clicked a few hundred pixels above my window! so how can i convert the relative coordinates to absolute?

        I Offline
        I Offline
        icabod
        wrote on last edited by
        #3

        I think you need to be using ClientToScreen. For example: // point is relative to your window. CPoint ptScreen = point; ClientToScreen (&ptScreen); // ptScreen now holds the value as screen co-ords Hope that helps, 'bod.

        T 1 Reply Last reply
        0
        • I icabod

          I think you need to be using ClientToScreen. For example: // point is relative to your window. CPoint ptScreen = point; ClientToScreen (&ptScreen); // ptScreen now holds the value as screen co-ords Hope that helps, 'bod.

          T Offline
          T Offline
          ThinkingPrometheus
          wrote on last edited by
          #4

          great it worked! thx

          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