Send a Message to a Window programmatically
-
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..!!!"
-
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..!!!"
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 ofWM_RBUTTONDOWN
is guarded byif(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
-
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..!!!"
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 useReplyMessage
to override this.«_Superman_» _I love work. It gives me something to do between weekends.
-
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 useReplyMessage
to override this.«_Superman_» _I love work. It gives me something to do between weekends.
«_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..!!!"
-
«_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..!!!"
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++.