if(nCode == HCBT_ACTIVATE)
{
counter++;
::PostMessage(hparentWin,USER_MESSAGE_1,wParam,lParam);//send a user
message to my application's main window
}
return CallNextHookEx(hHook,nCode,wParam,lParam);
}
But the code can not run rightly.
who can help me, it would be better to supply the code.
How does it fail?
Let me guess: Do you have the hook handle in a shared segment in the DLL? If
you don't when the hook procedure runs in any application but the one that
planted it, it will see a null window handle.
Regards,
Will
Yes, but in Win32 processes each run in their own address apaces. So if the
subclasser and subclassee are in different process then special steps need
to be taken well before you can think of call SetWindowLong:
And as one of the suggested methods involves using a hook, the OP's idea
about using a CBT hook to catch window activations is the canonical approach
in the _general_ case.
Regards,
Will
#pragma data_seg(".SHARED_SECT")
HWND hparentWin = NULL;
#pragma data_seg()
Create and add a .def file to your project and add the following lines to it
SECTIONS
.SHARED_SECT Read Write Shared
This makes the section .SHARED_SECT shared and hence all the variables in
this section (hparentWin) will be shared across all aplications that load
the dll. So from your application just set the hparentWin to the handle of
your window and you should be getting the messages, if you correctly called
SetWindowsHookEx().
"msnews.micorsoft.com" <fqyd...@163.com> wrote in message
news:envgaG9...@TK2MSFTNGP11.phx.gbl...