CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    Mar 2007
    Posts
    210

    Posting USER + X messageS

    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;

    Code:
    appHook = SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC)AppEventsHook, hinstDLL, GetWindowThreadProcessId(GetAppWnd(), NULL));
    with my callback proc being

    Code:
    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.

    Code:
    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.
    Last edited by flynny1st; February 8th, 2008 at 10:34 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured