|
-
Feb 3rd, 2004, 11:05 AM
#1
Thread Starter
Frenzied Member
Refresh running process
I've got a form with two buttons on it. Clicking on the buttons displays an htm document in the default viewer.
What I want to happen is for a new viewer to be launched on the first button press and then the same viewer instance to be used for all subsequent button presses.
I've got the following code, but it doesn't reuse the viewer that is launched, it just starts up a new one.
Any ideas?
VB Code:
Dim WithEvents proc As New Process()
Dim gblnProcessRunning As Boolean = False
Private Sub LoadDocument(ByVal str As String)
proc.EnableRaisingEvents = True
If gblnProcessRunning Then
proc.Close()
proc.StartInfo.FileName = str
proc.Start()
Else
Try
With proc.StartInfo
.FileName = str
.UseShellExecute = True
.ErrorDialog = True
.ErrorDialogParentHandle = Me.Handle
End With
proc.Start()
gblnProcessRunning = True
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
LoadDocument("d:\tspcd\mx\801b.htm")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
LoadDocument("d:\tspcd\mx\snm800.htm")
End Sub
Private Sub proc_Exited(ByVal sender As Object, ByVal e As System.EventArgs) Handles proc.Exited
gblnProcessRunning = False
End Sub
This world is not my home. I'm just passing through.
-
Feb 4th, 2004, 04:24 AM
#2
Thread Starter
Frenzied Member
Somebody please give me a suggestion?
On the first button click I want to launch a new instance of Internet Explorer to display the .htm file. Every button click after this should use this same instance of IE to display the specified htm.
This world is not my home. I'm just passing through.
-
Feb 6th, 2004, 03:55 AM
#3
Thread Starter
Frenzied Member
Even some stupid ideas would be better than nothing...
This can't be impossible to do can it?
This world is not my home. I'm just passing through.
-
Feb 6th, 2004, 04:52 AM
#4
you can do this with Type.InvokeMember ...
VB Code:
Private InternetExplorer As Object '/// this will be your internet explorer.
Private Sub LoadDocument(ByVal strUrl As String)
If Not InternetExplorer Is Nothing Then '/// if it's already created...
With InternetExplorer.GetType
.InvokeMember("Height", Reflection.BindingFlags.SetProperty, Nothing, InternetExplorer, New Object() {"600"})
.InvokeMember("Width", Reflection.BindingFlags.SetProperty, Nothing, InternetExplorer, New Object() {"800"})
.InvokeMember("Left", Reflection.BindingFlags.SetProperty, Nothing, InternetExplorer, New Object() {"100"})
.InvokeMember("Top", Reflection.BindingFlags.SetProperty, Nothing, InternetExplorer, New Object() {"100"})
.InvokeMember("Visible", Reflection.BindingFlags.SetProperty, Nothing, InternetExplorer, New Object() {True})
.InvokeMember("Navigate", Reflection.BindingFlags.InvokeMethod, Nothing, InternetExplorer, New Object() {strUrl})
End With
Else '/// if it's the first time you open / create the instance of internet explorer...
Dim typeExplorer As Type = Type.GetTypeFromProgID("InternetExplorer.Application")
InternetExplorer = Activator.CreateInstance(typeExplorer)
With InternetExplorer.GetType
.InvokeMember("Height", Reflection.BindingFlags.SetProperty, Nothing, InternetExplorer, New Object() {"600"})
.InvokeMember("Width", Reflection.BindingFlags.SetProperty, Nothing, InternetExplorer, New Object() {"800"})
.InvokeMember("Left", Reflection.BindingFlags.SetProperty, Nothing, InternetExplorer, New Object() {"100"})
.InvokeMember("Top", Reflection.BindingFlags.SetProperty, Nothing, InternetExplorer, New Object() {"100"})
.InvokeMember("Visible", Reflection.BindingFlags.SetProperty, Nothing, InternetExplorer, New Object() {True})
.InvokeMember("Navigate", Reflection.BindingFlags.InvokeMethod, Nothing, InternetExplorer, New Object() {strUrl})
End With
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
LoadDocument("C:\index.htm")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
LoadDocument("C:\main.htm")
End Sub
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Feb 6th, 2004, 05:11 AM
#5
Thread Starter
Frenzied Member
Thank you. This is certainly enough to get me started again. I've got two problems with it though. I can probably sort them out myself, but if you have time to share any ideas I'd appreciate it.
1. My original intention was to launch the application that was set up on the PC as the default viewer for htm files. This code only deals with Internet Explorer. This isn't a big problem because I think all PCs will have IE on them won't they?
2. If you click one of the buttons, then close the instance of IE that was launched further button clicks raise an error - "The object invoked has disconnected from its clients."
This world is not my home. I'm just passing through.
-
Feb 13th, 2004, 03:48 AM
#6
Thread Starter
Frenzied Member
Still struggling with this. Anybody got any further ideas?
This world is not my home. I'm just passing through.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|