Article ID: 125694
Article Last Modified on 7/11/2005
case WM_NOTIFY:
{
if ((((LPNMHDR)lparam)->code == NM_RCLICK))
{
HWND hChildWnd;
POINT pointScreen, pointLVClient, pointHeader;
DWORD dwpos;
dwPos = GetMessagePos();
pointScreen.x = LOWORD (dwPos);
pointScreen.y = HIWORD (dwPos);
pointLVClient = pointScreen;
// Convert the point from screen to client coordinates,
// relative to the listview
ScreenToClient (ghwndLV, &pointLVClient);
// Because the header turns out to be a child of the
// listview control, we obtain its handle here.
hChildWnd = ChildWindowFromPoint (ghwndLV, pointLVClient);
// NULL hChildWnd means R-CLICKED outside the listview.
// hChildWnd == ghwndLV means listview got clicked: NOT the
// header.
if ((hChildWnd) && (hChildWnd != ghwndLV))
{
char szClass [50];
// Verify that this window handle is indeed the header
// control's by checking its classname.
GetClassName (hChildWnd, szClass, 50);
if (!lstrcmp (szClass, "SysHeader32"))
{
HD_HITTESTINFO hdhti;
char szBuffer [80];
// Transform to client coordinates
// relative to HEADER control, NOT the listview!
// Otherwise, incorrect column number is returned.
pointHeader = pointScreen;
ScreenToClient (hChildWnd, &pointHeader);
hdhti.pt = pointHeader;
SendMessage (hChildWnd,
HDM_HITTEST,
(WPARAM)0,
(LPARAM) (HD_HITTESTINFO FAR *)&hdhti);
wsprintf (szBuffer, "Column %d got clicked.\r\n",
hdhti.iItem);
MessageBox (NULL, szBuffer, "Test", MB_OK);
}
}
}
return 0L;
}
Keywords: kbhowto kblistview kbctrl KB125694