Solved

CListCtrl::GetTopIndex on KeyDown

Posted on 2004-10-19
13
756 Views
Last Modified: 2013-11-20
Hi,
   I need to know the top index which is visible in the list control. For that I use CListCtrl::GetTopIndex().

But when I hook a function LVN_KEYDOWN for this list control. It always returns me 0. Basically I need to process something when the top index of the list control changes.

When the user uses mouse and scrollbar to scroll, GetTopIndex() works as expected. But on keydown or selection via mouse on a particular row it does not always return me the right TopIndex.

Note:
Observation made when I hit down arrow key GetTopIndex() returns me always 0. But when I hit up arrow key it returns me the right index.
0
Comment
Question by:akalmani
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +3
13 Comments
 
LVL 6

Expert Comment

by:Amritpal Singh
ID: 12346073
have a look at the comment at the following link

http://www.geocities.com/codenit/tech/vc/control4/list28.htm
0
 
LVL 6

Expert Comment

by:Amritpal Singh
ID: 12346079
0
 
LVL 6

Expert Comment

by:Amritpal Singh
ID: 12346148
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:akalmani
ID: 12346184
amrit_82:
Did you read my question carefully?

I solved my question. Thanks for your suggestions. Infact I found a crook way to solve this issue.
0
 
LVL 3

Author Comment

by:akalmani
ID: 12346190
Does anyone know how to refund my points ??
0
 
LVL 13

Expert Comment

by:SteH
ID: 12346198
How do you get the CListCtrl pointer? Via the HWND contained in the message? If yes the function might return a temporary object.
0
 
LVL 16

Expert Comment

by:nonubik
ID: 12346210
>Does anyone know how to refund my points ??
You'd better read instructions carefully... http://www.experts-exchange.com/help.jsp#hi70
0
 
LVL 16

Expert Comment

by:nonubik
ID: 12346216
Anyway, if you claim refund you need to post the solution
0
 
LVL 3

Author Comment

by:akalmani
ID: 12354844
SteH:
I have derived a class from CListCtrl. And I hooked LVN_KEYDOWN method to track keydown events. But when I call GetTopIndex() in this method I always get 0 for down arrow key. But I get the right value for up arrow key.

Anyways I resolved the question myself. I would not post the whole solution though here.

Override OnCustomDraw() and call GetTopIndex() in CDDS_ITEMPOSTPAINT.

VOID CMyListCtrl::OnCustomDraw(NMHDR *pHdr, LRESULT *pResult)
{
   LPNMLVCUSTOMDRAW lpvcd = (LPNMLVCUSTOMDRAW) pHdr;

   switch(lpvcd->nmcd.dwDrawStage)
   {
    case CDDS_PREPAINT:
             *pResult = CDRF_NOTIFYSUBITEMDRAW;
              break;
    case CDDS_ITEMPREPAINT:
             *pResult = CDRF_NOTIFYPOSTPAINT;
              break;
    case CDDS_ITEMPOSTPAINT:
           {
             int iIndex = GetTopIndex();            //This returns me the right value. Insert whatever logic here.
             *pResult = CDRF_DODEFAULT;
           }
              break;
   }
}
}
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 12356519
From link nonubik posted

Post a question in the Community Support topic area asking for a refund, and asking the Moderators to close the question. You'll be required to post your solution in your original question. A Moderator will post a notice of your request which will give the participants 96 hours to object to the refund. Note that if it resembles one of the suggested comments, the likelihood is that your request will not be granted, but rather, the points will be awarded to the Expert who makes the suggestion. In your Community Support request, remember to post a link to the original question.


Also you can delete
http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_21174988.html
yourself as long as no other expert posts a comment there.
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12867816
PAQed with points refunded (500)

modulo
Community Support Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Looking for a specific application/software 2 124
wait notify demo infinite loop 3 148
Making an alias 7 121
moto 4g phone enable finger print 4 68
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Suggested Courses

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question