Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Send a Message to a Window programmatically

Send a Message to a Window programmatically

Scheduled Pinned Locked Moved C / C++ / MFC
question
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    QuickDeveloper
    wrote on last edited by
    #1

    Hi I am trying to send a Message to my Internet Explorer Window.I got the handle and able to maximize the window but unable to send message. Can anyone tell me if something is wrong in SendMessage call below?Is the message queued?Send message should wait until the message is processed right?

    int _tmain(int argc, _TCHAR* argv[])
    {

    HWND hwnd=FindWindow(L"IEFrame",NULL);
    	
    if(NULL != hwnd)
    {
      printf("\\n  Retrieved the window handle \\n");
      ShowWindow(hwnd,SW\_MAXIMIZE);// This line works and the browser window is maximized as well.
      LRESULT lr=SendMessage(hwnd,WM\_RBUTTONDOWN,NULL,NULL);//Here,nothing happens,even though i change the message to any other (like WM\_LBUTTONDOWN etc)
    
    	  if(lr == 0) //Since if app process WM\_RBUTTONDOWN it should return zero
    	  {
                          printf(" \\n Message Sent \\n"); //Strangely ,this output is printed though i don't see any action on browser
    	  }
    	  else
    	  {
    		 printf("\\n Failed to send message \\n"); 
    	  }
    }
    else
    {
    	printf("\\n Failed to retrieve handle \\n");
    }
    return 0;
    

    }

    "Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"

    M _ 2 Replies Last reply
    0
    • Q QuickDeveloper

      Hi I am trying to send a Message to my Internet Explorer Window.I got the handle and able to maximize the window but unable to send message. Can anyone tell me if something is wrong in SendMessage call below?Is the message queued?Send message should wait until the message is processed right?

      int _tmain(int argc, _TCHAR* argv[])
      {

      HWND hwnd=FindWindow(L"IEFrame",NULL);
      	
      if(NULL != hwnd)
      {
        printf("\\n  Retrieved the window handle \\n");
        ShowWindow(hwnd,SW\_MAXIMIZE);// This line works and the browser window is maximized as well.
        LRESULT lr=SendMessage(hwnd,WM\_RBUTTONDOWN,NULL,NULL);//Here,nothing happens,even though i change the message to any other (like WM\_LBUTTONDOWN etc)
      
      	  if(lr == 0) //Since if app process WM\_RBUTTONDOWN it should return zero
      	  {
                            printf(" \\n Message Sent \\n"); //Strangely ,this output is printed though i don't see any action on browser
      	  }
      	  else
      	  {
      		 printf("\\n Failed to send message \\n"); 
      	  }
      }
      else
      {
      	printf("\\n Failed to retrieve handle \\n");
      }
      return 0;
      

      }

      "Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"

      M Offline
      M Offline
      Mattias G
      wrote on last edited by
      #2

      It might be that MSIE doesn't respond to WM_RBUTTONDOWN the way you hope. For all we know, it could be hooking in to some interrupt table or using a proprietary driver or ... Chances are that the handling of WM_RBUTTONDOWN is guarded by if(GetFocus() != this->m_hWnd) ... or similar. [EDIT] I just assumed that you've already tried with complete arguments (WPARAM/LPARAM) to the message?

      modified on Thursday, April 21, 2011 7:47 AM

      1 Reply Last reply
      0
      • Q QuickDeveloper

        Hi I am trying to send a Message to my Internet Explorer Window.I got the handle and able to maximize the window but unable to send message. Can anyone tell me if something is wrong in SendMessage call below?Is the message queued?Send message should wait until the message is processed right?

        int _tmain(int argc, _TCHAR* argv[])
        {

        HWND hwnd=FindWindow(L"IEFrame",NULL);
        	
        if(NULL != hwnd)
        {
          printf("\\n  Retrieved the window handle \\n");
          ShowWindow(hwnd,SW\_MAXIMIZE);// This line works and the browser window is maximized as well.
          LRESULT lr=SendMessage(hwnd,WM\_RBUTTONDOWN,NULL,NULL);//Here,nothing happens,even though i change the message to any other (like WM\_LBUTTONDOWN etc)
        
        	  if(lr == 0) //Since if app process WM\_RBUTTONDOWN it should return zero
        	  {
                              printf(" \\n Message Sent \\n"); //Strangely ,this output is printed though i don't see any action on browser
        	  }
        	  else
        	  {
        		 printf("\\n Failed to send message \\n"); 
        	  }
        }
        else
        {
        	printf("\\n Failed to retrieve handle \\n");
        }
        return 0;
        

        }

        "Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"

        _ Offline
        _ Offline
        _Superman_
        wrote on last edited by
        #3

        You're probably sending the message to the wrong window handle. IE's window hierarchy is quite complex. Use spy to get handles of the child windows and try sending the message to the child windows to figure out which window responds as you expect. As for SendMessage waiting till the message is processed, an application can use ReplyMessage to override this.

        «_Superman_»  _I love work. It gives me something to do between weekends.

        _Microsoft MVP (Visual C++)

        Polymorphism in C

        Q 1 Reply Last reply
        0
        • _ _Superman_

          You're probably sending the message to the wrong window handle. IE's window hierarchy is quite complex. Use spy to get handles of the child windows and try sending the message to the child windows to figure out which window responds as you expect. As for SendMessage waiting till the message is processed, an application can use ReplyMessage to override this.

          «_Superman_»  _I love work. It gives me something to do between weekends.

          _Microsoft MVP (Visual C++)

          Polymorphism in C

          Q Offline
          Q Offline
          QuickDeveloper
          wrote on last edited by
          #4

          «_Superman_» wrote:

          Use spy to get handles of the child windows and try sending the message to the child windows to figure out which window responds as you expect.

          Yes,I used Spy++ to get the handle of window.The window is being maximized when using ShowWindow but looks like no messages are being posted. Also as replied by "Mattias G" above this reply, i gave coordinates in WPARAM/LPRAM - SendMessage(hwnd,WM_RBUTTONDOWN,100,100) but to no avail. I will try to send messages to child windows (Maybe webpage inside browser) and verify. Thanks for the reply !

          "Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"

          A 1 Reply Last reply
          0
          • Q QuickDeveloper

            «_Superman_» wrote:

            Use spy to get handles of the child windows and try sending the message to the child windows to figure out which window responds as you expect.

            Yes,I used Spy++ to get the handle of window.The window is being maximized when using ShowWindow but looks like no messages are being posted. Also as replied by "Mattias G" above this reply, i gave coordinates in WPARAM/LPRAM - SendMessage(hwnd,WM_RBUTTONDOWN,100,100) but to no avail. I will try to send messages to child windows (Maybe webpage inside browser) and verify. Thanks for the reply !

            "Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"

            A Offline
            A Offline
            Abhi Lahare
            wrote on last edited by
            #5

            Probably you need to get IWebBrowser2 [^] Interface and then from there you need to figure it out how to get window handle you are looking for. I hope there is only one "IFrame" Window in the Spy++.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups