We help IT Professionals succeed at work.
Get Started
Troubleshooting Question

In C++ VS 2010 (MFC), how do I find the starting column of a scrolled CListBox table?

DickStone
DickStone asked
on
41 Views
Last Modified: 2020-08-24
The attached procedure finds where a user selects a column in a CListBox table.

For example, if there is a table that is 20 columns wide, and 10 fit on the screen, then the screen shows | C0 | C1 | C2 | C3 | C4 | C5 | C6 | C7| C8 | C9 |. If the user mouse clicks on the 5th screen column, the procedure returns 5, and the software knows it's column C5.

However, us the user scrolls over 10 columns, the screen shows  | C10 | C11 | C12 | C13 | C14 | C15 | C16 | C17| C18 | C19 | . If the mouse clicks on the 5th screen column (the 15th actual column, C15), the procedure still returns 5, when it's supposed to return 15. How do I add that the user has scrolled right 10 columns, so that the procedure can return 15?
--------------------------------


int CMyListCtrl::GetCurColumn()
{
   // Get the current mouse location and convert it to client
   // coordinates.
    DWORD pos = GetMessagePos();
    CPoint ptPos(LOWORD(pos), HIWORD(pos));
    ScreenToClient(&ptPos);


   long lWide=0;
   long lWideLast;


   
   // Step across to find the column the mouse is in
   for (int nSubIndex=0; nSubIndex<100; nSubIndex++) {


      lWideLast = lWide;
      lWide += GetColumnWidth(nSubIndex);


      if ( lWide>=ptPos.x ) {
         rectHit.left = lWideLast;
         rectHit.right = lWide;
         return( nSubIndex );   // could be break
      }


   } // end for


   return( -1 );


} // end GetSubItemClicked


Comment
Watch Question
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE