?
Solved

Tree control check box problem

Posted on 2005-04-04
12
Medium Priority
?
263 Views
Last Modified: 2013-11-20
Dear Experts

I have a tree control with check boxes. If i click an item at the root node i do not see the check mark at the root level. But i see the check mark in all the
leafs. Also the i see the same problem when i click on an item at the leaf level i dont see the check mark, but the i do the see the item having focus.
Its seems a little bizzare. Can any one help me on this ?

Thanks in advance
0
Comment
Question by:sjcu
[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
  • 6
  • 5
12 Comments
 
LVL 16

Expert Comment

by:nonubik
ID: 13704489
Is it a custom tree control? What styles does it have?
On a 'regular' tree control this shouldn't happen.
0
 

Author Comment

by:sjcu
ID: 13707793
Sorry for not being clear ... This is not a regular tree control. This tree control has check boxes. I have a bitmap with 3 states, checked ,unchecked and empty. Due to which i did not enable the option with check boxes. The problem thats going on is my hItem is NULL when i click on a leaf node. If
i click on the root of the parent i.e the top most node then all the leaf nodes show the  check mark bit map. I cannot figure out why the hittest is failing
and returning a null HTREEITEM. ?

m_imageList.Create(IDB_CHECKBOX_BITMAP, 16, 1, RGB(255,255,255));
m_treeCtrl.SetImageList( &m_imageList, TVSIL_STATE );      


ON_NOTIFY(NM_CLICK, ....)
UINT uFlags=0;
POINT pt;
::GetCursorPos(&pt);
ScreenToClient(&pt);
HTREEITEM hItem = m_treeCtrl.HitTest(pt,&uFlags);
HTREEITEM hParentItem = m_treeCtrl.GetParentItem(hItem);

//load the appropriate bitmap with check and uncheck
if(m_hAgents == NULL)
         {
            m_hAgents = m_treeCtrl.InsertItem(sAgents,TVI_ROOT);
            m_treeCtrl.SetItemState(m_hAgents, INDEXTOSTATEIMAGEMASK(ICON_NO_CHECK), TVIS_STATEIMAGEMASK);
         }

         // just to be on the safe side, make sure the root node insert succeeded
         if(m_hAgents != NULL)
         {
            hItem = m_treeCtrl.InsertItem(pAgent->m_userID,ICON_NO_CHECK,ICON_NO_CHECK,m_hAgents);
            if(hItem)
            {
               m_treeCtrl.SetItemState(hItem, INDEXTOSTATEIMAGEMASK(ICON_NO_CHECK), TVIS_STATEIMAGEMASK);
               m_treeCtrl.SetItemData(hItem,(DWORD)pAgent);
            }
         }
0
 
LVL 16

Expert Comment

by:nonubik
ID: 13707875
>ON_NOTIFY(NM_CLICK, ....)

Why don't you use ON_WM_LBUTTONDOWN()?
You also have the click-point. For this you'll need to have a class for the tree.

void CMyTree::OnLButtonDown(UINT nFlags, CPoint point)
{
      UINT uFlags=0;
      HTREEITEM hti = HitTest(point,&uFlags);
...
}
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:sjcu
ID: 13708320
Well i didn't want to create a new class and stuff. I have a class for my dialog anyways. Well i found out one more thing....
It only works if i click the check box at a particular spot. ...
0
 

Author Comment

by:sjcu
ID: 13716921
Well this fixed the HitTest problem

                UINT uFlags=0;
      DWORD                        dwpos;
      POINT                        point;
      TV_HITTESTINFO            tvhti;      

      // find out where the cursor was
      dwpos = GetMessagePos();
      point.x = LOWORD(dwpos);
      point.y = HIWORD(dwpos);
      ::MapWindowPoints(HWND_DESKTOP, m_treeCtrl.m_hWnd, &point, 1);

      // Test the location where the mouse hit
      tvhti.pt = point;
      HTREEITEM hItem = m_treeCtrl.HitTest(tvhti.pt,&uFlags);

Now i dont really know why this works and the previous code does not work. Although the pevious code was taken from a similar tree that works.!!!
Any thoughts on this ?.......

Thanks
0
 
LVL 16

Accepted Solution

by:
nonubik earned 375 total points
ID: 13716966
>::GetCursorPos(&pt);
>ScreenToClient(&pt);

Doing this in the tree's parent class will map the screen cursor point to the tree's parent client area, not to the tree's client area.

> ::MapWindowPoints(HWND_DESKTOP, m_treeCtrl.m_hWnd, &point, 1);
will do it. Or:

>::GetCursorPos(&pt);
>m_treeCtrl.ScreenToClient(&pt);
0
 
LVL 16

Expert Comment

by:nonubik
ID: 13717077
I see the answer does not satisfy you (http://www.experts-exchange.com/help.jsp#hi73)
0
 

Author Comment

by:sjcu
ID: 13717145
Well I am satisfied...
0
 
LVL 16

Expert Comment

by:nonubik
ID: 13717157
I was just wondering why a 'B' then...
0
 

Author Comment

by:sjcu
ID: 13727201
Dear Experts

If you notice i figured the solution for the initial question. So that should explain the B grade. I also considered the time line from the time the question
was posted to the time it was resolved.

Does this justify my grade ?

Please let me know if there are any concerns i will be happy to change it.

Thanks much...
0
 
LVL 16

Expert Comment

by:nonubik
ID: 13733584
No problem, just needed an explanation. And also please notice that the asker and the 'expert' may be on different time zones, thus sometimes such a delay between the question and the answer :o)
0

Featured Post

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

765 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