NM_DBLCK...where is the mouse position?!
Deepak Saxena -- Deepak_Saxena@ccm.ch.intel.com
Monday, May 20, 1996
VC 4.1, nt 3.51
I have a CTreeView derived class that is handling NM_DBLCK messages
sent to me by the tree ctrl. My only question is where is the mouse
location or the item handle stored? I looked in the win32 docs and
all it has for NM_DBLCLK is that it's sent when the user double-clicks on
the control.
tnx
--
Deepak_Saxena@ccm.ch.intel.com | I'm a 21st century digital boy
http://cernan.ecn.purdue.edu/~deepak | I don't know how to live,
Home:(602)812-8933, Work:(602)554-1304 | but I got a lot of toys.
My opinions, not Intel's! | - Bad Religion -
Ken Freeman -- kfreeman@pobox.com
Thursday, May 23, 1996
[Mini-digest: 10 responses]
Use ::GetMessagePos to get the mouse position in screen
coordinates, convert to client coordinates, and use HitTest
to see where the double click occurred.
Ken
-----From: "Len Wilcox"
I too am working on a program with a CTreeView class and ran into the
same issue. The solution is to use the GetMessagePos() function
which returns the position of the mouse for the last message. Below
is a segment from my code.
// Get the Point of the Click
CPoint ptRClick(LOWORD(GetMessagePos()), HIWORD(GetMessagePos()));
----
Len Wilcox - wilcoxs@access.digex.net, lwilcox@naitech.com
Home Page: http://www.access.digex.net/~wilcoxs/
Featuring downloadable shareware developed by Len Wilcox.
-----From: Deepak Saxena
Text item:
Replying to my self. The way to do this is to either:
a) Use GetMessagePos() to get the mouse position and then map that into
a treeview item
b) Use CTreeCtrl::GetSelectedItem()
Deepak
-----From: Overmyer
This function may suggest some approaches:
BOOL CTVView::DoHitTest(TV_HITTESTINFO& tvhti, TV_ITEM& tvi)
{
BOOL res = FALSE;
::GetCursorPos((LPPOINT)&(tvhti.pt));
::ScreenToClient(m_hWnd, &(tvhti.pt));
m_TreeCtl.HitTest(&tvhti);
if (!((tvhti.flags & TVHT_ONITEMLABEL) || (tvhti.flags & TVHT_ONITEMRIGHT)))
return res;
m_TreeCtl.SelectItem(tvhti.hItem);
//get the TV_ITEM
tvi.mask = TVIF_PARAM;
tvi.hItem = tvhti.hItem;
res = m_TreeCtl.GetItem(&tvi);
return res;
}
Here's a sample use:
/****************************************************************************
* PURPOSE: handle NM_RCLICK
****************************************************************************/
void CTVView::OnRClick(NMHDR *pNMHDR,LRESULT *pResult)
{
LPARAM lParam = (LPARAM) pNMHDR;
POINT pt;
NM_TREEVIEW *pnmtv = (NM_TREEVIEW *)lParam;
LPTVITEMDATA lptvid; //Long pointer to TreeView item data
TV_HITTESTINFO tvhti;
TV_ITEM tvi;
char szPath[MAX_PATH];
UINT res = 0;
HANDLE hChange = 0;
ULONG ulAttrs=(SFGAO_FOLDER | SFGAO_FILESYSTEM | SFGAO_VALIDATE) ;
if (m_IsCriticalSection) return;
::GetCursorPos(&pt);
//did we click on an item
if ( !DoHitTest(tvhti,tvi) ) return;
...
I use this same function for NM_DBLCLK notification.
Best Wishes,
Doug
Doug and Elizabeth Overmyer
overmyer@netcom.com
-----From: "David W. Gillett"
Although you'd never find it searching from NM_DBLCK, I'd bet that
the NMHDR pointer provided in the message really points to the start
of an NM_TREEVIEW structure, whose additional fields can be used to
find this information. Indeed, it looks like ClassWizard will
probably provide such a cast when told to add a handler for this
notification.
Dave
-----From: "Frederic Steppe"
You have to ask the tree control (get it with CTreeView::GetTreeCtrl()) :
Use GetSelectedItem() to find the item that was clicked.
Use GetItemRect() to get the rectangle occupied by the item (or the item text)
If you really need to know where exactly is the mouse pointer you can use
::GetCursorPos()
Frederic Steppe (frederics@msn.com)
-----From: coutadeur.f@ccmail.cgi.fr
Hi,
Here is what ClassWizard generates for me :
treeCtrl::OnTreeDblclk(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
}
NM_TREEVIEW contains a itemNew member, wich contains a hItem value (
HTREEITEM ). This is your item !
Hope this help!
Fabrice Coutadeur
-----From: "William Cook"
You need to call GetMessagePos() to do this. You'll
probably then have to call ScreenToClient(POINT*).
Bill Cook
-----From: Niv
//////////////////////////
HTREEITEM CMyTreeView::GetTreeItemOnCursor()
{
UINT nFlags;
CPoint curPoint;
CTreeCtrl *treectl=(CTreeCtrl*)GetDlgItem(IDC_TREE1);
GetCursorPos(&curPoint);
ScreenToClient(&curPoint);
return treectl->HitTest(curPoint, &nFlags);
}
///////////////////////////
USE:
void CMyTreeView::OnDblclkTree1(NMHDR* pNMHDR, LRESULT* pResult)
{
HTREEITEM ItemSel=GetTreeItemOnCursor();
if(ItemSel)
{
YOU'RE ON IT !!!
}
/////
HOPES THAT HELPS
NIV THE "TOOL" !!!
-----From: Georg Breithaupt
I would just use the function :
The GetCursorPos function retrieves the cursor's position, in screen coordinates.
BOOL GetCursorPos( LPPOINT lpPoint );
The next to do is call the function ScreenToClient() form CWnd:
void ScreenToClient( LPPOINT lpPoint ) const;
Example:
YourNotification( ... )
{
CPoint pt;
GetCursorPos( &pt );
ScreenToClient( &pt );
// pt has the Cursorpos
}
Hope it will help
Georg
| Вернуться в корень Архива
|