flynny1st
February 8th, 2008, 04:46 AM
Hi all,
i have hooked into an external applications messages and i want to post a message to my own user message to the bottom of the message queue. However the message whilst postmessage returns a number (i.e. its successful) the message isn't getting posted.
i create my hook like so;
appHook = SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC)AppEventsHook, hinstDLL, GetWindowThreadProcessId(GetAppWnd(), NULL));
with my callback proc being
const static UINT WM_PRIVATE_MSG = RegisterWindowMessage("WM_PRIVATE_MSG");
LRESULT CALLBACK AppEventsHook (int nCode, WPARAM wParam, LPARAM lParam)
{
try
{
if(nCode == HC_ACTION)
{
LPCWPSTRUCT pCwp = (LPCWPSTRUCT) lParam;
if(pCwp->message == WM_PRIVATE_MSG)
{
MessageBox(0, "Received message!", "Got it!", MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
}
switch(pCwp->message)
{
case WM_WINDOWPOSCHANGED:
{PostMessage(pCwp->hwnd,WM_PRIVATE_MSG,NULL,NULL);
}
}
return CallNextHookEx(appHook,nCode,wParam,lParam);
ok now i have hooked into the right window i can read all events such as WM_WINDOWPOSCHANGING etc. I have also tried posting a user message like so i.e.
PostMessage(pCwp->hwnd, WM_USER+10,0,0);
and trying to catch this in the switch statement. Again ith no luck.
I'm running on Windows server 2003 coudl this make a difference?
any ideas?
many thanks,
matt.
i have hooked into an external applications messages and i want to post a message to my own user message to the bottom of the message queue. However the message whilst postmessage returns a number (i.e. its successful) the message isn't getting posted.
i create my hook like so;
appHook = SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC)AppEventsHook, hinstDLL, GetWindowThreadProcessId(GetAppWnd(), NULL));
with my callback proc being
const static UINT WM_PRIVATE_MSG = RegisterWindowMessage("WM_PRIVATE_MSG");
LRESULT CALLBACK AppEventsHook (int nCode, WPARAM wParam, LPARAM lParam)
{
try
{
if(nCode == HC_ACTION)
{
LPCWPSTRUCT pCwp = (LPCWPSTRUCT) lParam;
if(pCwp->message == WM_PRIVATE_MSG)
{
MessageBox(0, "Received message!", "Got it!", MB_ICONEXCLAMATION | MB_OK | MB_SYSTEMMODAL);
}
switch(pCwp->message)
{
case WM_WINDOWPOSCHANGED:
{PostMessage(pCwp->hwnd,WM_PRIVATE_MSG,NULL,NULL);
}
}
return CallNextHookEx(appHook,nCode,wParam,lParam);
ok now i have hooked into the right window i can read all events such as WM_WINDOWPOSCHANGING etc. I have also tried posting a user message like so i.e.
PostMessage(pCwp->hwnd, WM_USER+10,0,0);
and trying to catch this in the switch statement. Again ith no luck.
I'm running on Windows server 2003 coudl this make a difference?
any ideas?
many thanks,
matt.