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. Is MSDN wrong?

Is MSDN wrong?

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasequestion
11 Posts 5 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.
  • Z Offline
    Z Offline
    zengkun100
    wrote on last edited by
    #1

    Here is a code snippet about CListCtrl from MSDN. And I don't think MSDN give correct code. // Get indexes of the first and last visible items in // the listview control. int index = m_myListCtrl.GetTopIndex(); int last_visible_index = index + m_myListCtrl.GetCountPerPage(); if (last_visible_index > m_myListCtrl.GetItemCount()) last_visible_index = m_myListCtrl.GetItemCount(); // Loop until number visible items has been reached. while (index <= last_visible_index) { //…… // Get the next item in listview control. index++; } IMO, variable last_visible_index is more than one. So the While statement should be written like this: while (index < last_visible_index) Am I wrong? Or MSND? Thank you all! :)

    A Chinese VC++ programmer

    M C 2 Replies Last reply
    0
    • Z zengkun100

      Here is a code snippet about CListCtrl from MSDN. And I don't think MSDN give correct code. // Get indexes of the first and last visible items in // the listview control. int index = m_myListCtrl.GetTopIndex(); int last_visible_index = index + m_myListCtrl.GetCountPerPage(); if (last_visible_index > m_myListCtrl.GetItemCount()) last_visible_index = m_myListCtrl.GetItemCount(); // Loop until number visible items has been reached. while (index <= last_visible_index) { //…… // Get the next item in listview control. index++; } IMO, variable last_visible_index is more than one. So the While statement should be written like this: while (index < last_visible_index) Am I wrong? Or MSND? Thank you all! :)

      A Chinese VC++ programmer

      M Offline
      M Offline
      Mukesh Kumar
      wrote on last edited by
      #2

      Your Question:

      Is MSDN wrong?

      You asked:

      Am I wrong? Or MSND?

      :-D What is wrong? you...? :laugh: Anyway, Did you implement this code?

      Mukesh Kumar Software Engineer

      Z T 2 Replies Last reply
      0
      • M Mukesh Kumar

        Your Question:

        Is MSDN wrong?

        You asked:

        Am I wrong? Or MSND?

        :-D What is wrong? you...? :laugh: Anyway, Did you implement this code?

        Mukesh Kumar Software Engineer

        Z Offline
        Z Offline
        zengkun100
        wrote on last edited by
        #3

        Yes, I didn't run this code. But look at this : last_visible_index = m_myListCtrl.GetItemCount(); The max index of a CListCtrl is m_myListCtrl.GetItemCount() - 1 not m_myListCtrl.GetItemCount(). Any way ,thank you!

        A Chinese VC++ programmer

        1 Reply Last reply
        0
        • Z zengkun100

          Here is a code snippet about CListCtrl from MSDN. And I don't think MSDN give correct code. // Get indexes of the first and last visible items in // the listview control. int index = m_myListCtrl.GetTopIndex(); int last_visible_index = index + m_myListCtrl.GetCountPerPage(); if (last_visible_index > m_myListCtrl.GetItemCount()) last_visible_index = m_myListCtrl.GetItemCount(); // Loop until number visible items has been reached. while (index <= last_visible_index) { //…… // Get the next item in listview control. index++; } IMO, variable last_visible_index is more than one. So the While statement should be written like this: while (index < last_visible_index) Am I wrong? Or MSND? Thank you all! :)

          A Chinese VC++ programmer

          C Offline
          C Offline
          CPallini
          wrote on last edited by
          #4

          Could you please, post the link to the MSDN page?

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

          Z 1 Reply Last reply
          0
          • C CPallini

            Could you please, post the link to the MSDN page?

            If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
            This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

            Z Offline
            Z Offline
            zengkun100
            wrote on last edited by
            #5

            Thank you :) http://msdn2.microsoft.com/zh-cn/library/kt4by313(VS.80).aspx Look at the sample code.

            A Chinese VC++ programmer

            C P 2 Replies Last reply
            0
            • Z zengkun100

              Thank you :) http://msdn2.microsoft.com/zh-cn/library/kt4by313(VS.80).aspx Look at the sample code.

              A Chinese VC++ programmer

              C Offline
              C Offline
              CPallini
              wrote on last edited by
              #6

              Well I think you're right and MSDN example is wrong. Unfortunately at the moment I have no time to test it, but I'll do in a day or two. :)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

              Z 1 Reply Last reply
              0
              • C CPallini

                Well I think you're right and MSDN example is wrong. Unfortunately at the moment I have no time to test it, but I'll do in a day or two. :)

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

                Z Offline
                Z Offline
                zengkun100
                wrote on last edited by
                #7

                O,yeah! :-D Thank you! I'll test it tomorrow.

                A Chinese VC++ programmer

                1 Reply Last reply
                0
                • Z zengkun100

                  Thank you :) http://msdn2.microsoft.com/zh-cn/library/kt4by313(VS.80).aspx Look at the sample code.

                  A Chinese VC++ programmer

                  P Offline
                  P Offline
                  peterchen
                  wrote on last edited by
                  #8

                  It might actually be right. I assume that GetCountPerPage includes only complete items to be shown, however the click might occur at a partially visible additional item.

                  We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
                  blog: TDD - the Aha! | Linkify!| FoldWithUs! | sighist

                  Z 1 Reply Last reply
                  0
                  • P peterchen

                    It might actually be right. I assume that GetCountPerPage includes only complete items to be shown, however the click might occur at a partially visible additional item.

                    We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
                    blog: TDD - the Aha! | Linkify!| FoldWithUs! | sighist

                    Z Offline
                    Z Offline
                    zengkun100
                    wrote on last edited by
                    #9

                    Thank you peterchen :) You're right, GetCountPerPage only returns the items that completely visible. But this has nothing to do with this bug! I've test this code, and I'm sure that this code is bugsome.GetItemRect will return FALSE when index is GetItemCount(); I've reported this to MS.

                    A Chinese VC++ programmer

                    P 1 Reply Last reply
                    0
                    • Z zengkun100

                      Thank you peterchen :) You're right, GetCountPerPage only returns the items that completely visible. But this has nothing to do with this bug! I've test this code, and I'm sure that this code is bugsome.GetItemRect will return FALSE when index is GetItemCount(); I've reported this to MS.

                      A Chinese VC++ programmer

                      P Offline
                      P Offline
                      peterchen
                      wrote on last edited by
                      #10

                      you are right, either the limiting condition should be changed to

                      if (last_visible_index > =GetItemCount())
                      last_visible_index = GetItemCount()-1;

                      or the return value of GetItemRect should be checked.

                      We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
                      blog: TDD - the Aha! | Linkify!| FoldWithUs! | sighist

                      1 Reply Last reply
                      0
                      • M Mukesh Kumar

                        Your Question:

                        Is MSDN wrong?

                        You asked:

                        Am I wrong? Or MSND?

                        :-D What is wrong? you...? :laugh: Anyway, Did you implement this code?

                        Mukesh Kumar Software Engineer

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

                        Mukesh Kumar wrote:

                        What is wrong? you...?

                        Nope thats why asking the question!

                        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
                        Never mind - my own stupidity is the source of every "problem" - Mixture

                        cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

                        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