Results 1 to 6 of 6

Thread: Refresh running process

  1. #1

    Thread Starter
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    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:
    1. Dim WithEvents proc As New Process()
    2.     Dim gblnProcessRunning As Boolean = False
    3.  
    4.     Private Sub LoadDocument(ByVal str As String)
    5.  
    6.         proc.EnableRaisingEvents = True
    7.  
    8.         If gblnProcessRunning Then
    9.             proc.Close()
    10.             proc.StartInfo.FileName = str
    11.             proc.Start()
    12.         Else
    13.             Try
    14.                 With proc.StartInfo
    15.                     .FileName = str
    16.                     .UseShellExecute = True
    17.                     .ErrorDialog = True
    18.                     .ErrorDialogParentHandle = Me.Handle
    19.                 End With
    20.                 proc.Start()
    21.                 gblnProcessRunning = True
    22.             Catch ex As Exception
    23.                 Debug.WriteLine(ex.Message)
    24.             End Try
    25.         End If
    26.  
    27.     End Sub
    28.  
    29.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    30.         LoadDocument("d:\tspcd\mx\801b.htm")
    31.     End Sub
    32.  
    33.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    34.         LoadDocument("d:\tspcd\mx\snm800.htm")
    35.     End Sub
    36.  
    37.     Private Sub proc_Exited(ByVal sender As Object, ByVal e As System.EventArgs) Handles proc.Exited
    38.         gblnProcessRunning = False
    39.     End Sub
    This world is not my home. I'm just passing through.

  2. #2

    Thread Starter
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536
    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.

  3. #3

    Thread Starter
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536
    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.

  4. #4
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    you can do this with Type.InvokeMember ...
    VB Code:
    1. Private InternetExplorer As Object '/// this will be your internet explorer.
    2.  
    3.     Private Sub LoadDocument(ByVal strUrl As String)
    4.         If Not InternetExplorer Is Nothing Then '/// if it's already created...
    5.             With InternetExplorer.GetType
    6.                 .InvokeMember("Height", Reflection.BindingFlags.SetProperty, Nothing, InternetExplorer, New Object() {"600"})
    7.                 .InvokeMember("Width", Reflection.BindingFlags.SetProperty, Nothing, InternetExplorer, New Object() {"800"})
    8.                 .InvokeMember("Left", Reflection.BindingFlags.SetProperty, Nothing, InternetExplorer, New Object() {"100"})
    9.                 .InvokeMember("Top", Reflection.BindingFlags.SetProperty, Nothing, InternetExplorer, New Object() {"100"})
    10.                 .InvokeMember("Visible", Reflection.BindingFlags.SetProperty, Nothing, InternetExplorer, New Object() {True})
    11.                 .InvokeMember("Navigate", Reflection.BindingFlags.InvokeMethod, Nothing, InternetExplorer, New Object() {strUrl})
    12.             End With
    13.         Else '/// if it's the first time you open / create the instance of internet explorer...
    14.             Dim typeExplorer As Type = Type.GetTypeFromProgID("InternetExplorer.Application")
    15.             InternetExplorer = Activator.CreateInstance(typeExplorer)
    16.             With InternetExplorer.GetType
    17.                 .InvokeMember("Height", Reflection.BindingFlags.SetProperty, Nothing, InternetExplorer, New Object() {"600"})
    18.                 .InvokeMember("Width", Reflection.BindingFlags.SetProperty, Nothing, InternetExplorer, New Object() {"800"})
    19.                 .InvokeMember("Left", Reflection.BindingFlags.SetProperty, Nothing, InternetExplorer, New Object() {"100"})
    20.                 .InvokeMember("Top", Reflection.BindingFlags.SetProperty, Nothing, InternetExplorer, New Object() {"100"})
    21.                 .InvokeMember("Visible", Reflection.BindingFlags.SetProperty, Nothing, InternetExplorer, New Object() {True})
    22.                 .InvokeMember("Navigate", Reflection.BindingFlags.InvokeMethod, Nothing, InternetExplorer, New Object() {strUrl})
    23.             End With
    24.         End If
    25.     End Sub
    26.  
    27.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    28.         LoadDocument("C:\index.htm")
    29.     End Sub
    30.  
    31.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    32.         LoadDocument("C:\main.htm")
    33.     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]

  5. #5

    Thread Starter
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536
    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.

  6. #6

    Thread Starter
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536
    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
  •  



Click Here to Expand Forum to Full Width