Is MSDN wrong?
-
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, variablelast_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
-
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, variablelast_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
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
-
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
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
-
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, variablelast_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
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 -
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 ClarkeThank you :) http://msdn2.microsoft.com/zh-cn/library/kt4by313(VS.80).aspx Look at the sample code.
A Chinese VC++ programmer
-
Thank you :) http://msdn2.microsoft.com/zh-cn/library/kt4by313(VS.80).aspx Look at the sample code.
A Chinese VC++ programmer
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 -
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 ClarkeO,yeah! :-D Thank you! I'll test it tomorrow.
A Chinese VC++ programmer
-
Thank you :) http://msdn2.microsoft.com/zh-cn/library/kt4by313(VS.80).aspx Look at the sample code.
A Chinese VC++ programmer
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 -
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! | sighistThank 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
-
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
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 -
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
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" - Mixturecheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You