DoubleClick Area Validation in CListView :: MFC

kuphryn

Senior member
Jan 7, 2001
400
0
0
Hello.

In one of my programs, I created view derived from CListView. Everything works great. I implemented a double click feature where if the user double clicks an item, the program instantiates a dialog box, allowing the user the edit the text belonging to that item.

I used the exact code Jeff Prosise presents in his book. There is one thing I would like to change. Current, the user has to click exact a spot inside the text belong to each item of the CListView. For example:

---------------
item 1
---------------
item 2
---------------
item 3
---------------

In the above sample, the user would have to click *on* one of the item text to be considered a valid double click. I would like to have it such that the user only needs to click a point inside the *item box*. So for example, the user can click any point as long as it is inside a specific *item box*.

Prosise uses this funtion to validate the point.

// GetListCtrl()->HitTest(point);

I believe HitTest(...) check a specific text, not the item box in general. Is there a way to check using a broader item box area instead of specific item text?

Thanks,
Kuphryn
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
The button message gives you the point that the mouse cursor is at.

I use the following code is a specialized control

CRect rect ;
CPoint p ( GetMessagePos() ) ; // can also use the point passed in by the button message

ScreenToClient ( &p ) ;
GetClientRect ( rect ) ;

if ( rect.PtInRect ( p ) )
{
// in bounds - do whatever
}
else
{
// out of limits - do what ever
}

 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
^^

In case you overlooked this. Did not see acknowlegement that it answered or helped
 

kuphryn

Senior member
Jan 7, 2001
400
0
0
Thanks.

I did receive a notice of your post. However, I am not sure if the code you posted will work for what I am trying to do. Your code seems to measure the rect of the CListView. I need a way to determine whether a point is inside of the rect of *an item*.

Here is the code I am using right now from Jeff Prosise's book.

-----
void COriginIPEnhancedView::eek:nNMDblclk(NMHDR *pNMHDR, LRESULT *pResult)
{
DWORD dsPos = ::GetMessagePos();
CPoint clickPnt(static_cast<int>(LOWORD(dsPos)), static_cast<int>(HIWORD(dsPos)));
GetListCtrl().ScreenToClient(&clickPnt);
int curIndex = GetListCtrl().HitTest(clickPnt);

if (curIndex != -1)
{
// do something
}
}
-----

Kuphryn
 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
IF you know the rectangle you are looking for within the CLIstView, use that rectangle coordinates instead of the ClientREct coordinates.

All the intention is to test a point X/Y to see if the X value is >= x0 and <= x1 and the Y value >= y0 and <= y1.

It is your implimentatino that will determine the rectangle coordinates.