Solved

CListCtrl::GetTopIndex on KeyDown

Posted on 2004-10-19
13
748 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
  • 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ORA-01403: no data found 43 101
twoTwo  challenge 35 103
wordappend challenge 8 177
unix example issues 18 90
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…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

772 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