void ListView_GetContextMenuPoint(HWND p_list,LPARAM p_coords,POINT & p_point,int & p_selection) { if ((DWORD)p_coords == (DWORD)(-1)) { int firstsel = ListView_GetFirstSelection(p_list); if (firstsel >= 0) { ListView_EnsureVisible(p_list, firstsel, FALSE); RECT rect; WIN32_OP_D( ListView_GetItemRect(p_list,firstsel,&rect,LVIR_BOUNDS) ); p_point.x = (rect.left + rect.right) / 2; p_point.y = (rect.top + rect.bottom) / 2; WIN32_OP_D( ClientToScreen(p_list,&p_point) ); } else { RECT rect; WIN32_OP_D(GetClientRect(p_list,&rect)); p_point.x = (rect.left + rect.right) / 2; p_point.y = (rect.top + rect.bottom) / 2; WIN32_OP_D(ClientToScreen(p_list,&p_point)); } p_selection = firstsel; } else { POINT pt = {(short)LOWORD(p_coords),(short)HIWORD(p_coords)}; p_point = pt; POINT client = pt; WIN32_OP_D( ScreenToClient(p_list,&client) ); LVHITTESTINFO info = {}; info.pt = client; p_selection = ListView_HitTest(p_list,&info); } }
bool ListView_GetContextMenuPoint(HWND p_list,LPARAM p_coords,POINT & p_point,int & p_selection) { if ((DWORD)p_coords == (DWORD)infinite) { int firstsel = ListView_GetFirstSelection(p_list); if (firstsel >= 0) { RECT rect; if (!ListView_GetItemRect(p_list,firstsel,&rect,LVIR_BOUNDS)) return false; p_point.x = (rect.left + rect.right) / 2; p_point.y = (rect.top + rect.bottom) / 2; if (!ClientToScreen(p_list,&p_point)) return false; } else { RECT rect; if (!GetClientRect(p_list,&rect)) return false; p_point.x = (rect.left + rect.right) / 2; p_point.y = (rect.top + rect.bottom) / 2; if (!ClientToScreen(p_list,&p_point)) return false; } p_selection = firstsel; return true; } else { POINT pt = {(short)LOWORD(p_coords),(short)HIWORD(p_coords)}; p_point = pt; POINT client = pt; if (!ScreenToClient(p_list,&client)) return false; LVHITTESTINFO info; memset(&info,0,sizeof(info)); info.pt = client; p_selection = ListView_HitTest(p_list,&info); return true; } }