Use mshtml.HTMLDocument to control a browser window

Posted on 2007-10-06
Last Modified: 2008-01-09
I have an mshtml.HTMLDocument that I fetched from an Internet Server_Explorer window, as in
         mshtml.HTMLDocument document = null;
         uint WM_HTML_GETOBJECT = RegisterWindowMessage("WM_HTML_GETOBJECT");
         SendMessageTimeout(hWnd, WM_HTML_GETOBJECT, IntPtr.Zero, IntPtr.Zero,                                                               SendMessageTimeoutFlags.SMTO_NOTIMEOUTIFNOTHUNG, 1000, out lngRes);
         document = (mshtml.HTMLDocument) ObjectFromLresult(
                                 lngRes, typeof(mshtml.HTMLDocument).GUID, IntPtr.Zero);

I ordinarily fill in the form by hand and click the Go button.  I want to change that to an automated process, which is why I have this question.

The HTML in the document contains
      <INPUT class=oFF size=15 value=ABC name=p>
      <INPUT class=oFF type=submit value=Go>
The INPUT field named p contains the value I would like to send to the host and the INPUT field named Go is the button I would like to push.

I'm assuming that mshtml.HTMLDocument will allow me to do this.

Am I right?
If I'm right, how do I do that?
If I'm wrong, how else should I approach the problem?

Thank you.
Question by:josgood
    LVL 96

    Expert Comment

    by:Bob Learned
    Would it be possible to use the WebBrowser control?

    LVL 13

    Accepted Solution


    Thank you for answering my question.  You were the only one to do so.  The WebBrowser control is a definite possibility, but I haven't looked into it.

    I looked into mshtml and have worked out an answer.

    mshtml.HTMLDocument provides an Index method that requires both an object name and an index into the collection of document attributes.  By iterating over the attribute collection, I can find the index of the attribute I'm interested in.  I already know the object name.  So then Index(object-name,index) returns an object that I can cast to the necessary type.

    There has to be a better way.  The iteration should not be necessary and I am uncomfortable with the cast .  But it works, and that's OK for now.

    LVL 96

    Expert Comment

    by:Bob Learned

    The only thing that matters is whether you have something that works for you.

    LVL 13

    Author Comment

    I agree.  Perfection can wait, I'm busy.  <G>

    I'll ask community support to close out this question.

    Have a great day!
    LVL 1

    Expert Comment

    Closed, 500 points refunded.
    Community Support Moderator

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now