problem with mousehook

hi,
i've created a mousehook for a window i've created using the following code

ButtonWND = CreateWindowEx(WS_EX_LEFT, className, butText, WS_CHILD, atoi(xVal), atoi(yVal), atoi(width), atoi(height), currentWND, NULL, currentHInstance, NULL);
ShowWindow(ButtonWND, SW_SHOWDEFAULT);

HHOOK__* MouseHook = InstallMouseLauncher(NULL, ButtonProcessID, ButtonWND, fieldVal);

InstallMouseLauncher is as follows

DllExport HHOOK__* WINAPI InstallMouseLauncher(HINSTANCE__* wHnd, DWORD processID, HWND__* window, LPTSTR field)
{
MouseWindowHandle = window;
fieldName = field;
HHOOK__* mouseHook = (HHOOK)SetWindowsHookEx(WH_MOUSE, (HOOKPROC)LauncherMouseHook, wHnd, processID);
return mouseHook;
}

now a hook is returned for MouseHook and i can see the button on the screen. The problem is that the button doesnt seem to be recognised.

If i simply put a printout in the callback function for the mousehook, printing out the GET_STATE variable it returns 0 and nothing else. If i refine the print out to wait for get_state to equal 108 (a button press) then it doesnt register and nothing gets printed out.

Am i missing anything out?

Many Thanks,

Matt.
[1270 byte] By [flynny1st] at [2007-11-20 8:15:49]
# 1 Re: problem with mousehook
The last parameter of SetWindowsHookEx is thread ID and not process ID.

Are you trying to hook only a perticular thread or all UI applications ?
Krishnaa at 2007-11-9 13:30:15 >
# 2 Re: problem with mousehook
Hi,

Thanks for the quick response. I only want to hook into the newly created window (Button) mouse messages.

i apologise i forgot to put in the method i use for getting the ButtonProcessID

ButtonWND = CreateWindowEx(WS_EX_LEFT, className, butText, WS_CHILD, atoi(xVal), atoi(yVal), atoi(width), atoi(height), currentWND, NULL, currentHInstance, NULL);
ShowWindow(ButtonWND, SW_SHOWDEFAULT);

DWORD ButtonProcessID = GetWindowThreadProcessId(ButtonWND, NULL);

MouseHook = InstallMouseLauncher(NULL, ButtonProcessID, ButtonWND, fieldVal);

is GetWindowThreadProcessId the correct method?

Many Thanks,

Matt.
flynny1st at 2007-11-9 13:31:14 >
# 3 Re: problem with mousehook
No, it gives you the process ID and you need the thread ID.
Krishnaa at 2007-11-9 13:32:22 >
# 4 Re: problem with mousehook
Hi Krishnaa,

is there a method for getting the thread ID? looking through the Win32 API i cannot see any method for doing this. do you know the name of the method i should use?
flynny1st at 2007-11-9 13:33:16 >
# 5 Re: problem with mousehook
Where is that thread, is it in another process ? I think you should set global hook and watch for perticular window and process it only.
Krishnaa at 2007-11-9 13:34:26 >
# 6 Re: problem with mousehook
What i have done is I have hooked into my program. The program then sits there and polls untill the required child window is opened (waiting for WM_CREATE). When this is detected i want to add my own button to the screen, adding mouse functionaility.)

I'm correctly detecting the window being opened and the button is been added. Will the window be in the same process as i have created it and the hook in the callback function?

I have also tried creating a mouse hook for the child window and filtering on the name of the window i have created, however this too, didn't work. (even though i am returned a hook, although i assume it is because i am not passing it the correct threadID).

Thanks,

Matt.
flynny1st at 2007-11-9 13:35:23 >
# 7 Re: problem with mousehook
Hooked into your own program ? why not edit its source ?
Krishnaa at 2007-11-9 13:36:26 >
# 8 Re: problem with mousehook
no sorry its not my program. the problem is i want to add some functionailty to this program , there is however no development kit for it.

I mean as I have created the window inside my event hook for the program the window i created will be in the same process will it not?

Matt.
flynny1st at 2007-11-9 13:37:29 >
# 9 Re: problem with mousehook
hi,

just to add i have now tried the following with no luck

creating a global variable CLaunchDLLApp theApp;

and then using the following to create the mouse hook

MouseHook = SetWindowsHookEx(WH_MOUSE, (HOOKPROC)LauncherMouseHook, theApp.m_hInstance, ButtonThreadProcessID);

and also

MouseHook = SetWindowsHookEx(WH_MOUSE, (HOOKPROC)LauncherMouseHook, theApp.m_hInstance, 0);

and finally

MouseHook = SetWindowsHookEx(WH_MOUSE, (HOOKPROC)LauncherMouseHook, 0, 0);

all of which returning a hook but failing to pick up any mouse functions.

One thing to note is that the external program i'm trying to hook into is written in .NET will this make any difference?
flynny1st at 2007-11-9 13:38:26 >
# 10 Re: problem with mousehook
worked it out.

the button is being drawn below the other objects, however because i call UpdateWindow(ButtonWND); after i've added etc. it is still drawn there. do you know of any way i can force this to be added last or added to the top of the layer?

Thanks for your help
flynny1st at 2007-11-9 13:39:26 >