Click here to Skip to main content
15,896,377 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I was trying to write a hook for an application using the SetWindowsHookEx.
I created a DLL and hooked to the application by statically linking to it.
I was getting proper notifications for the button and edit controls etc. But when i tried for CListCtrl/CListView it is not working. I get a lot of messages. But i cant get anything meaning full out of it.
When i checked with spy++ also it is not showing CLitstCtr. Is there a way to get the messages from CListCtr?

My intention is to log all the events happening on a CListCtrl in my application.
I have event handlers for handling the event properly. My code is simple . Create a DocView application with CListView as the view class. make it report style and have some items in it. Create a dll which export functions to hook the application. These exposed dll function will be calling SetWindowsHookEx .
eg:
SetWindowsHookEx(WH_GETMESSAGE,
(HOOKPROC)msghook,
hInst,
0);
Here msghook is the function which i use for finding the messages. Inside the function we convert lparam to get the message (LPMSG msg = (LPMSG)lParam;)
I get proper messages for normal controls. But for CListCrel there is noting which i can use.
Is there any way to hook a CListView

WBR,
Sourabh
Posted
Updated 31-Jan-13 20:06pm
v3
Comments
Sergey Alexandrovich Kryukov 1-Feb-13 1:25am    
First of all, why would you hook? What's the purpose? Do you understand that you should not use hooks for regular UI development?

If you have appropriate purpose, you can do it, but... There are too many ways to screw up things, especially in such a difficult technique as hooks. Without seeing your code, we cannot help.

—SA
doubts.vc 1-Feb-13 2:04am    
Hi,
Thanks for the quick response.
My intention is to log all the events happening on a CListCtrl in my application.
I have event handlers for handling the event properly. My code is simple . Create a DocView application with CListView as the view class. make it report style and have some items in it. Create a dll which export functions to hook the application. These exposed dll function will be calling SetWindowsHookEx .
eg:
SetWindowsHookEx(WH_GETMESSAGE,
(HOOKPROC)msghook,
hInst,
0);
Here msghook is the function which i use for finding the messages. Inside the function we convert lparam to get the message (LPMSG msg = (LPMSG)lParam;)
I get proper messages for normal controls. But for CListCrel there is noting which i can use.
Is there any way to hook a CListView
Sergey Alexandrovich Kryukov 1-Feb-13 2:08am    
According to Microsoft documentation, you need a separate DLL only if you need a global hook. So, in this case, you can call it right in your application, which will be a bit easier...
—SA
Sergey Alexandrovich Kryukov 1-Feb-13 2:14am    
Yes, looks correct, especially if you say it works with other controls... I would question that you really don't hook messages; maybe you just fail to recognize them; it happens sometimes...
—SA
Sergey Alexandrovich Kryukov 1-Feb-13 2:19am    
Here is another idea. This is a list control. Do you try to recognize it by its HWND? It can be wrong. Some controls, internally, have other window instances inside, with separate HWND. A simple example is a combo box, it actually has 3 different HWNDs: one is a text box, another is a list, and one more is "interfacing" HWND, and it never is hooked with the events, only two others are. So, try to investigate it using GetWindow API on the control's HWND, and see what's inside, in children...
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900