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. DLGTemplate MapDialogRect() problem

DLGTemplate MapDialogRect() problem

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

    Hello, I have a dialog without resources which works fine.In a class derived from CDialog I have a variable of type DLGTemplate.This variable has default x,y,cx,cy values set in the constructor. But I want to increase the height and width of the dialog box in accordance with the number of windows controls added to the dialog box.I am adding windows controls in the OnCreate() function of Dialog class like this. CRect Rect(10,10,100,100); CComboBox* Combo = new CComboBox; Combo->Create(WS_VISIBLE | WS_CHILD |CBS_SORT, Rect, this, ID); How do I find the relation between the above Rect's coordinates and the coordinates of the dialog box? I tried MapDialogRect but I don't understand what exactly is done there? Please help. Thanks Prithaa

    J M 2 Replies Last reply
    0
    • P prithaa

      Hello, I have a dialog without resources which works fine.In a class derived from CDialog I have a variable of type DLGTemplate.This variable has default x,y,cx,cy values set in the constructor. But I want to increase the height and width of the dialog box in accordance with the number of windows controls added to the dialog box.I am adding windows controls in the OnCreate() function of Dialog class like this. CRect Rect(10,10,100,100); CComboBox* Combo = new CComboBox; Combo->Create(WS_VISIBLE | WS_CHILD |CBS_SORT, Rect, this, ID); How do I find the relation between the above Rect's coordinates and the coordinates of the dialog box? I tried MapDialogRect but I don't understand what exactly is done there? Please help. Thanks Prithaa

      J Offline
      J Offline
      Jason Teagle
      wrote on last edited by
      #2

      The co-ordinates specified in the control's Create() call are specified in the parent's (your dialogue's) CLIENT co-ordinates. 'Client' co-ords have their (0, 0) at the top-left of the space *within* any border and title bar the dialogue has. If it has no border and no title bar, then this is the same as the top-left of the full dialogue. If you want to know how far the control is from the top-left of yoour dialogue and you have a title bar and / or border, then you need to get the dialogues 'window' rect, and the control's 'window' rect, and then you can calculate the offset. Note, though, that if you ask a control for its client rect, it gives you co-ordinates relative to *its*own* client area, not its parent. If you ask a control or window for its 'window' rect, it gicves you co-ords relative to *the*screen's* top-left. So, to get the offset from a dialogue's client arrea to a control's top-left, do this: CRect rctControl ; MyControl.GetWindowRect(&rctControl); // It's relative to top-left of screen. MyDlg.ScreenToClient(&rctControl); // Now, relative to top-left of dlg's client area. To get it relative to the full dlg's top-left (ignoring title bar and border): CRect rctControl ; MyControl.GetWindowRect(&rctControl); // It's relative to top-left of screen. CRect rctDlg ; MyDlg.GetWindowRect(&rctDlg); rctControl.OffsetRect(rctDlg.left - rctControl.left, rctDlg.top - rctControl.top); // Now, relative to top-left of dlg's full area.

      1 Reply Last reply
      0
      • P prithaa

        Hello, I have a dialog without resources which works fine.In a class derived from CDialog I have a variable of type DLGTemplate.This variable has default x,y,cx,cy values set in the constructor. But I want to increase the height and width of the dialog box in accordance with the number of windows controls added to the dialog box.I am adding windows controls in the OnCreate() function of Dialog class like this. CRect Rect(10,10,100,100); CComboBox* Combo = new CComboBox; Combo->Create(WS_VISIBLE | WS_CHILD |CBS_SORT, Rect, this, ID); How do I find the relation between the above Rect's coordinates and the coordinates of the dialog box? I tried MapDialogRect but I don't understand what exactly is done there? Please help. Thanks Prithaa

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        If you know your client area size, and you want to calculate the window size that will give you that client area size, you can use: CWnd::CalcWindowRect()    (MFC) or AdjustWindowRect()/AdjustWindowRectEx()   (Win32) Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        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