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. Keeping track of control width

Keeping track of control width

Scheduled Pinned Locked Moved C / C++ / MFC
question
6 Posts 4 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.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    Hi, I have a control from which I regular need the current width, so I created a member variable. I did override OnSize() to get the new width. Where do I get the initial width?

    A B 2 Replies Last reply
    0
    • A Anonymous

      Hi, I have a control from which I regular need the current width, so I created a member variable. I did override OnSize() to get the new width. Where do I get the initial width?

      A Offline
      A Offline
      Anonymous
      wrote on last edited by
      #2

      Well, I remember from my poor Win32 experience that you get a WM_SIZE after the control is created... so overriding OnSize() might be enough? Propably someone can confirm this? Or is there any other message handler to override and call GetClientRect()?

      R 1 Reply Last reply
      0
      • A Anonymous

        Hi, I have a control from which I regular need the current width, so I created a member variable. I did override OnSize() to get the new width. Where do I get the initial width?

        B Offline
        B Offline
        BlackSmith
        wrote on last edited by
        #3

        Try reading here: CWnd::OnGetMinMaxInfo**

        --BlackSmith--

        **/*The roof is on fire, we don't need no water, let the MF burn*/. BHG.

        A 1 Reply Last reply
        0
        • B BlackSmith

          Try reading here: CWnd::OnGetMinMaxInfo**

          --BlackSmith--

          **/*The roof is on fire, we don't need no water, let the MF burn*/. BHG.

          A Offline
          A Offline
          Anonymous
          wrote on last edited by
          #4

          sorry, I dont get the relation to my question about current control size, which is a client window (a listbox) of a dialog. Meanwhile I tried with OnSize(), but OnSize() gets called to late. I need to catch the width somewhere earlier, right after the control is created....

          L 1 Reply Last reply
          0
          • A Anonymous

            sorry, I dont get the relation to my question about current control size, which is a client window (a listbox) of a dialog. Meanwhile I tried with OnSize(), but OnSize() gets called to late. I need to catch the width somewhere earlier, right after the control is created....

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Overwriting OnCreate() brought no luck... so I found this one:

            void CListBoxLovely::PreSubclassWindow()
            {
            CListBox::PreSubclassWindow();
            CRect rect;
            GetClientRect(rect);
            m_nItemWidth = rect.Width()
            }

            it works good :)

            1 Reply Last reply
            0
            • A Anonymous

              Well, I remember from my poor Win32 experience that you get a WM_SIZE after the control is created... so overriding OnSize() might be enough? Propably someone can confirm this? Or is there any other message handler to override and call GetClientRect()?

              R Offline
              R Offline
              Roger Allen
              wrote on last edited by
              #6

              Initially you will recieve a WM_SIZE before the control is created, and one after the control is created. You could do the following:

              static bool first = true ;
              if (GetDlgItem(IDC_OF_CONTROL) != NULL && first)
              {
              // this code will only be executed once.
              CRect size ;
              GetDlgItem(IDC_OF_CONTROL)->GetWindowRect(&size) ;
              first = false ;
              // do something with the initial size of the control
              }

              Roger Allen Sonork 100.10016 I think I need a new quote, I am on the prowl, so look out for a soft cute furry looking animal, which is really a Hippo in disguise. Its probably me.

              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