Hi,

how can I detect a right mouseklick on a listview headerbutton with getting the pressed columnindex ?

Thanks,
Nordwind64
Posted on 2003-10-03 13:46:04 by Nordwind64
Posted on 2003-10-03 13:56:08 by QvasiModo
LVN_COLUMNCLICK will only report left button clicks, I think you are forced to subclass the header control and watch for the WM_RBUTTONDOWN message.
Posted on 2003-10-03 14:37:43 by donkey
You're right, I didn't think of that... :(
So I guess it's LVM_GETHEADER and subclassing. Unless there's a better way of getting the header control handle (as I remember that message was not available in older versions of the common controls library).
Posted on 2003-10-03 14:44:32 by QvasiModo
You can always check for the WM_CONTEXTMENU message in the main window proc then do a ChildWindowFromPoint followed by a HDM_HITTEST on the returned window. No subclassing and a rather elegant solution if you ask me :)

This will do it:

LOCAL hHeader				:DWORD

LOCAL hhti :HDHITTESTINFO

.IF uMsg == WM_CONTEXTMENU
invoke GetCursorPos,ADDR hhti.pt
invoke ScreenToClient,hListview,ADDR hhti.pt
invoke ChildWindowFromPoint,hListview,hhti.pt.x,hhti.pt.y
mov hHeader,eax
; you can do a check here to make sure that it's your header
invoke GetCursorPos,ADDR hhti.pt
invoke ScreenToClient,hHeader,ADDR hhti.pt
invoke SendMessage,hHeader,HDM_HITTEST,0,ADDR hhti
; eax has the item number
Posted on 2003-10-03 14:56:54 by donkey

You can always check for the WM_CONTEXTMENU message in the main window proc then do a ChildWindowFromPoint followed by a HDM_HITTEST on the returned window. No subclassing and a rather elegant solution if you ask me :)

Much better indeed ;)
You should really make a collection of all your snippets one of this days :)
Posted on 2003-10-03 15:09:31 by QvasiModo
Hi,

another solution is to get header hwnd with ListView_GetHeader and then watch for WM_NOTIFY/NM_RCLICK notifications with this hwnd.

Japheth
Posted on 2003-10-04 01:31:39 by japheth
Hi,

thank you very much !!!
Donkey, you're the best, again...
Japheth, I will try that.

Thanks,
Nordwind64
Posted on 2003-10-04 01:45:45 by Nordwind64

Hi,

another solution is to get header hwnd with ListView_GetHeader and then watch for WM_NOTIFY/NM_RCLICK notifications with this hwnd.

Japheth

Wouldn't you have to subclass the listview to do that, the header is a child of the listview not the main window so I would assume no header notifications would be sent to the main window.
Posted on 2003-10-04 02:37:18 by donkey
Hi donkey,

one should think so. But it works without subclassing. Perhabs if this is an undocumented feature its not a good idea to use it. Dont know that.

japheth
Posted on 2003-10-04 04:44:29 by japheth
Alternatively you could process that in the message loop, but I guess it wouldn't be very elegant...
Posted on 2003-10-04 11:09:56 by QvasiModo
heres another way



LONG HitColumn(HWND hWnd,DWORD dimx)
{
DWORD i=0,sumx=0,x;

while (1)
{
x=ListView_GetColumnWidth(hWnd,i);
sumx+=x;
if(dimx<sumx)
{
return i;
}
i++;
}

}


process ur message (right mouse click on the list view) and call it like this:



POINT mpt;
LV_HITTESTINFO hit;

GetCursorPos(&mpt);
ScreenToClient(hList,mpt);
hit.pt=mpt;
hit.flags=LVHT_ABOVE | LVHT_BELOW | LVHT_NOWHERE | LVHT_ONITEMICON | LVHT_ONITEMLABEL | LVHT_ONITEMSTATEICON | LVHT_TOLEFT | LVHT_TORIGHT;
hit.iItem=0;

iSelected = HitColumn(hList,hit.pt.x); // column header index


you can easily code it in asm, c,..etc
original code was taken from the PowerBasic forums (great guys!) and it works great.
have fun.
Posted on 2003-10-04 16:01:13 by wizzra