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. Getting control coordinates

Getting control coordinates

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

    How do you get the coordinates of a control on a dialog relative to the upper-left corner of the dialog? I've tried using the GetClientRect & GetWindowRect functions of the control I want the coords for, but neither returns the right value. Any help is appreciated. Thanks. - Aaron

    B M J 3 Replies Last reply
    0
    • M monrobot13

      How do you get the coordinates of a control on a dialog relative to the upper-left corner of the dialog? I've tried using the GetClientRect & GetWindowRect functions of the control I want the coords for, but neither returns the right value. Any help is appreciated. Thanks. - Aaron

      B Offline
      B Offline
      Brian D
      wrote on last edited by
      #2

      CRect rect; GetDlgItem(IDC_CONTROLNAME)->GetWindowRect(&rect); ScreenToClient(&rect); You should then be able to take the values of rect.


      "You know "that look" women get when they want sex? Me neither." --Steve Martin

      1 Reply Last reply
      0
      • M monrobot13

        How do you get the coordinates of a control on a dialog relative to the upper-left corner of the dialog? I've tried using the GetClientRect & GetWindowRect functions of the control I want the coords for, but neither returns the right value. Any help is appreciated. Thanks. - Aaron

        M Offline
        M Offline
        monrobot13
        wrote on last edited by
        #3

        I got it working using GetWindowRect of the control and ScreenToClient of the dialog. Is this the best way to do it? [EDIT] Guess I should have refreshed before I posted :) Thanks for the help though [/EDIT] - Aaron

        1 Reply Last reply
        0
        • M monrobot13

          How do you get the coordinates of a control on a dialog relative to the upper-left corner of the dialog? I've tried using the GetClientRect & GetWindowRect functions of the control I want the coords for, but neither returns the right value. Any help is appreciated. Thanks. - Aaron

          J Offline
          J Offline
          John R Shaw
          wrote on last edited by
          #4

          Off the top of my head. GetClientRect(): is the rectangular area that represents the area where drawing is to occur, with (0,0) representing the upper left courner of the client area within the window. GetWindowRect(): is the rectangular area that represents the area where the window is draw in screen coordinates and must be converted to client coordinates to be useful. Therefore, you need to get the screen coordinates via GetWindowRect() and then convert them to the dialog coordinates via ScreenToClient(). Now is there a better way or a function that does the needed conversion for you? I am not sure, there is one function whose usage is a bit confusing so I keep forgetting its' name and all I remeber (at the moment) is that it converts from one coordinate system to anoghter (a.k.a. client to screen or screen to client). Basicaly, it is less confusing to do it your self (with two simple function calls), than to call some function that (based on the arguments) makes the same function calls. INTP

          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