Handle of running application

  • Thread starter Thread starter James
  • Start date Start date
J

James

Hello everyone,

I have a windows application that starts Internet Explorer and I need to get
access to this page. Ideally I would like to have the document loaded into a
WebBrowser control. Also I would like to close IE after I'm finished.

What are the ingredients needed?


-james
 
Thanks Mike,

I do that at first but the website opens a new page with the info I want.

I have read an article from the book called 'Visual Basic 2005 Cookbook'
that uses the System.Diagnostics.Process.GetProcesses. Now I have the handle
to IE but now what? Hmmm? To bad a the webmaster starts a new IE!!!

This code is from the book.

For Each oneProcess As System.Diagnostics.Process In
System.Diagnostics.Process.GetProcesses
If oneProcess.MainWindowTitle.Contains("Bus Stop Schedule") Then
MessageBox.Show(oneProcess.MainWindowTitle)
End If
Next
 
So are you saying that the page in the webcontrol is redirected to a new IE
window, or that the webcontrol contains a redirected page? If it is the
latter, then you can handle the Navigated or Navigating events to see where
the new URL is pointing.
 
Hey Mike,
I load the web page into a web control. When I change some textboxes/inputs
I then execute the onclick for the form using InvokeMember. This runs but
the reply comes up in IE not the web control. The web master does this for
all such forms!!! Arg!

If there is a better way please let me know! Sure wish they used Web
Services though!!!

However, I have found a solution, see http://support.microsoft.com/kb/176792
For the people who are interested I included my code (below) as this method
is not that friendly.

My webcontrol loads this page.
http://www.edmonton.ca/portal/serve...control=SetCommunity&CommunityID=218&PageID=0

In the top right corner of this page you will see "Today's Bus Stop
Schedule". Using a webcontrol I fill in the bus stop, (eg. 1468), as needed
and run the onclick. On the reply page the code below will ferret out the
info I need. If your interested use bus stop id 1468.


Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
'
' ShDocVw & msHTML dll's
' You have to add these two dll's.
' They are found in the \windows\system32 folder
' To add shdocvw you may have to add the shdocvw.tlb - tells VS
how/what to add
'
' Variables IE an SWs are globally declared (msHTML, ShDocVw
respectively)

' Info from web page reply i need
Dim bsTime As String
Dim bsRoute As String


For Each IE In SWs

'locate my reply page
If IE.LocationName.Contains("Bus Stop Schedule") Then

'must have a mshtml.htmldocument to access GetElementById
'Note cannot cType to system.windows.forms.htmldocument :(
Dim IEDoc As mshtml.HTMLDocument = IE.Document

'Get an htmlelement
'note cannot convert to an htmlelement so object is used
Dim elementGetItem As Object =
IEDoc.getElementById("dgdBusSchedule__ctl1_lblDepartureDate")

'elementGetItem is in fact an htmlelement so I can use it as
such - no intellisence :(
bsTime = elementGetItem.innertext

elementGetItem =
IEDoc.getElementById("dgdBusSchedule__ctl1_lnkRouteNumber")
bsRoute = elementGetItem.innertext

MessageBox.Show("Next bus @: " & bsTime, "Bus Route: " &
bsRoute)

Exit For
End If

Next

End Sub
 
Are you trying to read the information off the page and display it in your
application? Sounds like you're trying to parse the page if you were wanting
to hook to a web service. If so, just use the HttpWebRequest and
HttpWebResponse classes and do the POST yourself. Get the data returned from
the response and stick it into a viewer on your app somewhere, or parse the
data out of the page.
 
Thanks Jeff,
I will look into your suggestion.

The transit web site will not load the reply page, it always crashes (on my
htc touch) . It is a really handy site, but you have to be at a computer. If
it worked on my htc touch, it would be much better I deem. So I created a
little server that accepts and delivers the info I need - quite neat in
fact. I always know when the next bus is no matter where or what I'm doing.

The draw back is the page pops up and then closes - not elegant but it works
without error! Having more then one system I don't care too much.

Thanks for your suggestion, I will endeavor to get familiar with
HttpWebRequest and HttpWebResponse.


-James
 
Hi Jeff,
I was doing some research into using HttpWebRequest & HttpWebResponse. The
application I have is too complex for using this method. I can get my first
page all good, and even populate a WebBrowser control. What cannot be done
is run the apropriate onclick (Button). Using POST and SUBMIT generates
errors from the server. Once again I shake my finger at this
webmaster/programmer (naughty,naughty). It could be worse, she could make
small changes frequently (fingers now crossed). Wish they would use
web-services!

If the first page had the info I needed, or was just a straight forward
POST|SUBMIT this would be ace.

Also, HttpWebRequest and HttpWebResponse are considered Obsolete - so I was
using WebRequest and WebResponse - which are the same more or less.


-James
 
Back
Top