Jump to content
  • Advertisement
Sign in to follow this  

Using SendMessage with IE in C#

This topic is 4515 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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 = "http://www.google.com/"; 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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!