|
-
April 18th, 2004, 10:07 AM
#1
Win32 Hit Test problems
I have created a shortcut menu for a tree and am triggering processing off the Win32 WM_CONTEXTMENU message (activated by right click). However, I am having problems with making the item right-clicked be the selected item in the tree view. I thought the way to do this was using the Hit Test, but it does not seem to work. I have consulted the Win32 help file and a few other Internet sources, but I cannot figure out what I am doing wrong.
Any help or pointers would be appreciated. Below you will find the code I`m using to process the WM_CONTEXTMENU message.
I often get the "No item selected" error. Thanks, Alan
case WM_CONTEXTMENU:
{
hit_test.pt.x = LOWORD(lParam);
hit_test.pt.y = HIWORD(lParam);
hit_test.flags = TVHT_ONITEMRIGHT;
Selected = TreeView_HitTest(tree_hwnd, &hit_test);
if (Selected != NULL)
{
TreeView_SelectItem(tree_hwnd, Selected);
TrackPopupMenuEx(hMenu, TPM_VERTICAL, (int)LOWORD(lParam), (int)HIWORD(lParam), hwnd, NULL);
}
else MessageBox(NULL, TEXT("No item selected"),
TEXT("ERROR"), MB_OK | MB_ICONWARNING);
}
break;
-
April 19th, 2004, 01:39 AM
#2
I think u should convert mouse's co-ordinates to client co-ordinates first.
Trust urself!
-
April 19th, 2004, 09:29 PM
#3
Got it
It turns out that both the WM_CONTEXTMENU message and the TrackPopUpMenuEx use screen coordinates, but the Hit Test needs client coordinates. Doing the ScreentoClient conversion solved the problem. Code may be found below.
Thanks for pointing me in the right direction. Alan
case WM_CONTEXTMENU:
{
POINT point;
point.x = LOWORD(lParam);
point.y = HIWORD(lParam);
ScreenToClient(hwnd, &point);
hit_test.pt.x = point.x;
hit_test.pt.y = point.y;
hit_test.flags = TVHT_ONITEMRIGHT;
Selected = TreeView_HitTest(tree_hwnd, &hit_test);
if (Selected != NULL)
{
TreeView_SelectItem(tree_hwnd, Selected);
TrackPopupMenuEx(hMenu, TPM_VERTICAL, (int)LOWORD(lParam),
(int)HIWORD(lParam), hwnd, NULL);
}
else MessageBox(NULL, TEXT("No item selected"),
TEXT("ERROR"), MB_OK | MB_ICONWARNING);
}
break;
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|