Link to home
Start Free TrialLog in
Avatar of asavard
asavard

asked on

weird mouse position from the NMHDR param

Hi!

I have the following function :

void CEditorExeDlg::OnItemexpandingSectionTree(NMHDR* pNMHDR, LRESULT* pResult)
{
    NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
            
   POINT ptExpand = pNMTreeView->ptDrag;

   CTreeCtrl *pTree = (CTreeCtrl *) GetDlgItem(IDC_SECTION_TREE);

   // Make a HitTest to get the current expanding item
   TV_HITTESTINFO HitTestInfo;
   HitTestInfo.pt = ptExpand;
   HTREEITEM hTest = pTree->HitTest(&HitTestInfo);
...

when I debug the app, the coordinates in the pNMTreeView->ptDrag have no sense at all.  I need this to get the item that was clicked in an tree list.  upon expanding the upper left element of the list, the value of the point is something like (1234567, 12345678) (some huge values).  Of course, after the hittest, the flag is set to below & right.

What may be the cause of this problem?
Avatar of snoegler
snoegler

In Windows95 the NMHDR structure is according to my documentation not
defined(NT only).
So you have to fetch the mouse coordinates using either:
- GetCursorPos(), which gives the *actual* coordinates of the mouse; but i think
  the time difference between message and your function should be small enough so
  that this position should be valid,
- or GetMessagePos() which returns the mouse position when the last message was
  sent(see docs), but i am not sure if this function works with common control notification
  messages(i think so though).
In each case you have to use ScreenToClient() as the coordinates returned are both
screen coordinates.
Avatar of asavard

ASKER

n Windows95 the NMHDR structure is according to my documentation not
     defined(NT only).
I'm under NT so it should work...

     So you have to fetch the mouse coordinates using either:
     - GetCursorPos(), which gives the *actual* coordinates of the mouse; but i think
       the time difference between message and your function should be small enough so
       that this position should be valid,
     - or GetMessagePos() which returns the mouse position when the last message was
       sent(see docs), but i am not sure if this function works with common control notification
       messages(i think so though).
     In each case you have to use ScreenToClient() as the coordinates returned are both
     screen coordinates.

I tried this method, and although values returned make sense, HitTest doesn't return the handle to the right item (I don't know why)  There should be a way to get the coordinates
 from NM_TREEVIEW structure, why can it be there if it's useless!
Avatar of asavard

ASKER

BTW, NMHDR is defined under win95 too...
Avatar of asavard

ASKER

I made it work.  I called ScreenToClient for the window, instead of calling it like this :
pTree->ScreenToClient.  So the conversion was relative to the corner of the dialog, instead of being relative to the tree screen...

snoegler, make a dummy answer...
NMHDR is defined, but it all NMHDR derivates (NM_TREEVIEW) have in my documentation
the comment that the values are not valid using Windows 95(MSVC 4.0)
Thank you for your offer ... But it seems like you solved your problem yourself :)
ASKER CERTIFIED SOLUTION
Avatar of payn
payn

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of asavard

ASKER

Thanks payn.  It does work.  That's the kind of method I was looking for without success, thanks to the poor documentation of MS...  This help file really sucks!  I was aware of the itemNew element, but didn't knew how to interpret it.  Do you have any good sites about MFC, I like codeguru, but I miss some information...

Bye!
The on-line documentation is not only incomplete, it's often wrong, especially when dealing with less commonplace subjects.

After spending years looking for good websites, books, and other information on MFC, I realized that the only way I was going to figure out how things really work was by looking through Microsoft's code. For example, you can learn lots of great stuff about how owner-draw listboxes really work, and how you should use some of the more obscure features, by looking at the CCheckListBox class, which is implemented as an owner-draw listbox. Also, look through the sample code that comes with VC--many times they use a workaround to get past limitations or bugs in MFC or VC or Windows that's not documented anywhere else.

The most useful thing I've found on the Net, besides codeguru, is the MFC FAQ, which I think is maintained by Stingray Software.

I would also suggest buying the book MFC Internals, by Scot Wingo and someone else. None of the books I've seen dedicated to teaching you how to use MFC seems to answer any of the questions I've ever asked, but MFC Internals answered a lot of the "how do I do this" questions on the way to explaining the "how does it work" questions...