Sign in to follow this  

Using SendMessage with IE in C#

Recommended Posts

I've stumbled upon a problem that has me absolutely stumped. How do I properly send a WM_CHAR and a WM_LBUTTONDOWN to an Internet Explorer window? Here's what I got so far... //Import the win32 API functions [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern IntPtr FindWindowEx(IntPtr parent, IntPtr next, string sClassName, IntPtr sWindowTitle); [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam); //start the IE process and go to google (just to test this out) ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = "C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE"; psi.Arguments = ""; psi.Windowstyle = ProcessWindowstyle.Normal; System.Diagnostics.Process.Start(psi); //when my application will be running there will be no other IE instances //open so it is safe to assume the one returned is the one we just opened, //we get a handle to it here IntPtr iHandle = FindWindowEx(IntPtr.Zero, IntPtr.Zero, "IEFrame", IntPtr.Zero); //send WM_CHAR to the IE window with 'A' as the character passed SendMessage(iHandle, 0x0102, 65, 0); If only it was this simple. SendMessage returns 0 which indicates that IE did in fact get the message and handled it however it considers proper. But, no character is posted to the input form that is currently in focus. I realize I am probably missing a lot here, and google has led me on several dead ends with no clear answers. From what I understand access to the current input form in focus in IE isn't that simple becuase IE doesn't implement them as actual windows. So, long story short. How do I open up an IE process and send it some text to the text box that is currently in focus? And, taking it a step further, how do I send it a click message?

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this