Solved

Bring Process.Start - Iexplorer to top

Posted on 2013-01-30
19
448 Views
Last Modified: 2013-12-27
I have a windows mobile application coded with Visual Basic.  I have a button that opens an HTML document, but it doesn't come to the top completely.  I can see that it is open since I see the IE bar at the top, but the actual document is not visible until I close the current window.

How do I get the HTML window to come to the top?

Here is the code that connects to the button.

 Process.Start("\Windows\iexplore.exe", "\Storage Card\My Documents\WetForm\AGCSpeciesSynC.html")

The screen that the button is on was called with
frmLookup.ShowDialog()
0
Comment
Question by:MurphyPH
  • 9
  • 6
  • 2
  • +1
19 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
>The screen that the button is on was called with
>frmLookup.ShowDialog()


That probably is the reason that it does not come to top. For testing, does it come to top if you use a form which is shown with Show()?
0
 
LVL 35

Expert Comment

by:YZlat
Comment Utility
set TopMost to True
0
 
LVL 35

Expert Comment

by:YZlat
Comment Utility
Oh wait, it only works for forms
0
 

Author Comment

by:MurphyPH
Comment Utility
It is odd that I can see the top blue bar of the explorer window, but the body of the window won't show up until I close the frmlookup window.  Is there some way I can send the frmlookup window back then forward again.  I tried the following but it didn't work.
 
frmLookup.SendToBack()

Process.Start("\Windows\iexplore.exe", "\Storage Card\MyDocuments\WetForm\AGCSpeciesSynA-B.html")
                       
frmLookup.BringToFront()

Perhaps there is some sort of a refresh.iexplorer  or iexplorer.BringToFront()
0
 

Author Comment

by:MurphyPH
Comment Utility
Hopefully this additional info helps.
Program flow.

From a project screen I tap a menu item called Veg then tap one of the submenu items to one of the strata layers (Tree,Sapling,Shrub…) screens.

On the strata menu screen I tap the lookup button that calls the following routine from the Main.vb
DoLookupSpecies(txtSp1, "Spename", "Spename", txtsp1indicator)

This then opens up the lookup form with
frmLookup.ShowDialog()

I have a button on the lookup form that opens an html file in Iexplorer using the following code;
Process.Start("\Windows\iexplore.exe", "\Storage Card\MyDocuments\WetForm\AGCSpeciesSynA-B.html")

The top bar of Iexplorer shows up, but the area below the bar doesn't show up an the lookup form is still visible.

I want to see the full iexplorer window, and when I close it, return to the lookup screen.

As a temporary workaround I used the code from the Exit button on the lookup screen to close the lookup screen before opening the iexplorer window.
fcancel = True
ID = ""
strname = ""
Me.Close()

This allows the iexplorer window to show completely, but it takes me back to the strata screen instead of the lookup screen when iexplorer is closed.
0
 

Author Comment

by:MurphyPH
Comment Utility
Codecruiser - Using Show() instead of ShowDialog() didn't make a difference.  

Thanks all for trying.
0
 
LVL 16

Expert Comment

by:hjgode
Comment Utility
Hello

instead of playing with VB.Net options you should just use the native win api call ShowWindow or better SetWindowPos for the IE window handle:

theory:
CreateProcess() / StartProcess()
IntPtr hWnd = FindWindow(InternetExplorer)
SetWindowPos(... TopeMost)

that yhould work.

For a much better user experience you should watch the window list to knwo, when IE is minimized and then bring your apps form back to the top.
0
 
LVL 16

Expert Comment

by:hjgode
Comment Utility
A much easier approach to control the display of web content is to use the webbrowser control in a new form. So you can show hide the content as you need.
0
 

Author Comment

by:MurphyPH
Comment Utility
Hjgodge,
This sounds promising, but I am too much of a rookie to really figure out the details.  Can you expand on the:
CreateProcess() / StartProcess()
IntPtr hWnd = FindWindow(InternetExplorer)
SetWindowPos(... TopeMost)

code as well as where it belongs.

Does this all go in the button click code?  And where does the actual call of the html file happen?

Thanks
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 16

Expert Comment

by:hjgode
Comment Utility
Welcome back to the basics:

OK some snippets:

Imports System.RunTime.InteropServices 'from my small brain

Declare Function CreateProcess Lib "coredll.dll" (ByVal imageName As String, ByVal cmdLine As String, ByVal lpProcessAttributes As IntPtr, ByVal lpThreadAttributes As IntPtr, ByVal boolInheritHandles As Int32, ByVal dwCreationFlags As Int32, ByVal lpEnvironment As IntPtr, ByVal lpszCurrentDir As IntPtr, ByVal si As Byte(), ByVal pi As IntPtr) As Integer

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct ProcessInfo
{
    public IntPtr hProcess;
    public IntPtr hThread;
    public Int32 ProcessId;
    public Int32 ThreadId;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct SecurityAttributes
{
    public int length;
    public IntPtr lpSecurityDescriptor;
    public bool bInheritHandle;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct StartupInfo
{
    public uint cb;
    public string lpReserved;
    public string lpDesktop;
    public string lpTitle;
    public uint dwX;
    public uint dwY;
    public uint dwXSize;
    public uint dwYSize;
    public uint dwXCountChars;
    public uint dwYCountChars;
    public uint dwFillAttribute;
    public uint dwFlags;
    public short wShowWindow;
    public short cbReserved2;
    public IntPtr lpReserved2;
    public IntPtr hStdInput;
    public IntPtr hStdOutput;
    public IntPtr hStdError;
}

sub launchIE(sHtml as string)
     Dim pi as ProcessInfo
     CreateProcess("\WINDOWS\iexplore.exe", sHtml, IntPtr.Zero, IntPtr.Zero, False, 0, _
	IntPtr.Zero, Nothing, IntPtr.Zero, pi)
    'pi has now the process handle you can use to kill later if you want
end sub

Open in new window


I am sorry, but I am not a native VB.NET coder. To find more about pinvoke see pinvoke.net (for coredll).

Here is another example:
Private Declare Function CreateProcess Lib "coredll.Dll" (ByVal strImageName As String, ByVal strCmdLine As String, ByVal pProcessAttributes As IntPtr, ByVal pThreadAttributes As IntPtr, ByVal bInheritsHandle As Integer, ByVal dwCreationFlags As Integer, ByVal pEnvironment As IntPtr, ByVal pCurrentDir As IntPtr, ByVal bArray() As [Byte], ByVal oProc As ProcessInfo) As Integer

Private Sub ShowPPCWebSite()
  Dim pi As New ProcessInfo
  CreateProcess("iexplore.exe", "www.microsoft.com/mobile/pocketpc/default.asp",   IntPtr.Zero, IntPtr.Zero, 0, 0, IntPtr.Zero, IntPtr.Zero, New [Byte](128) {}, pi)
End Sub 'ShowPPCWebSite

Private Sub StartIE()
  Dim pi As New ProcessInfo
  CreateProcess("iexplore.exe", "", IntPtr.Zero, IntPtr.Zero, 0, 0, IntPtr.Zero, IntPtr.Zero, New [Byte](128) {}, pi)
End Sub 'StartIE

Public Class ProcessInfo
  Public Process As Integer
  Public Thread As Integer
  Public ProcessID As Integer
  Public ThreadID As Integer
End Class 'ProcessInfo

Open in new window

see http://www.c-sharpcorner.com/uploadfile/dipalchoksi/invoking-unmanaged-dll-functions-from-compact-framework-for/

AND HERE is another example with wait: http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_21054990.html
0
 
LVL 83

Expert Comment

by:CodeCruiser
Comment Utility
Bear in mind that he is using .net compact framework so not all namespaces may be available.
0
 

Author Comment

by:MurphyPH
Comment Utility
Thanks hjgode,
That almost worked, but gave me the same results as I had, with the IE screen open, but the area below the top blue bar still showing the previous screen instead of the html file.

I am probably missing a line of code that brings that to the top.

Here is what I am using:
 Dim pi As New ProcessInfo
        CreateProcess("iexplore.exe", "\Storage Card\My Documents\WetForm\AGCSpeciesSynD-E.html", IntPtr.Zero, IntPtr.Zero, 0, 0, IntPtr.Zero, IntPtr.Zero, New [Byte](128) {}, pi)
0
 
LVL 16

Expert Comment

by:hjgode
Comment Utility
Hello

attached is a (verified working) sample using CreateProcess. If that does show correct you have done something special to your code (for example any form manipulation like SetForeGround).

the main form    IEM started from VB form
If you still have problems, please submit a FULL usable code sample showing the problem.
IEM-Launch-Test.zip
0
 

Author Comment

by:MurphyPH
Comment Utility
Thanks, I appreciate your effort, But I am too much of a rookie to know what to do with the files you sent.  My ap was built by someone else, and I know just enought to tweak it.  The ap is for windows mobile with lots of complications as defined above.

I wouldn't know what to put where, and even if it works separately it still might not cope with the issue I am having.

I have other screens/forms on this same ap that have the IE open properly, so getting IE to open isn't the issue.  The issue is getting it to open in this particular situation where I have one particular form with this issue.  Here is the program flow.

Program flow.
From a project screen I tap a menu item called Veg, then tap one of the submenu items to one of the strata layers (Tree,Sapling,Shrub…) screens.
On the strata screen I tap the lookup button that calls the following routine from the Main.vb using:

DoLookupSpecies(txtSp1, "Spename", "Spename", txtsp1indicator)

This then opens up the lookup form with:

Public Sub DoLookupSpecies(ByRef txtControl As TextBox, ByVal strDisplayMember As String, ByVal strValueMember As String, ByVal txtInd As TextBox)
        Cursor.Current = Cursors.WaitCursor
        Dim ColumnName As String
        Dim ColumnValue As String
        frmLookup.mstrDisplayName = strDisplayMember
        frmLookup.mstrValueMember = strValueMember
        frmLookup.ShowDialog()



This form has a datagrid in it.  This is the code that sets up the datagrid.
Private Sub Lookup_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'This fills the listbox1 with data
        If mstrDisplayName = "ScientificName" Then
            DataGrid1.Visible = True
                DataGrid1.DataSource = tdSpeciesLookup_Scientific
                Dim tsScientific As New DataGridTableStyle

                Dim dgtbc_ScientificName As New DataGridTextBoxColumn
                dgtbc_ScientificName.MappingName = "ScientificName"
                dgtbc_ScientificName.HeaderText = "Scientific Name"
                dgtbc_ScientificName.Width = 375

                Dim dgtbc_Scientific As New DataGridTextBoxColumn
                dgtbc_Scientific.MappingName = "Spename"
                dgtbc_Scientific.HeaderText = "Spename"
                dgtbc_Scientific.Width = 5

                Dim dgtbc_Common As New DataGridTextBoxColumn
                dgtbc_Common.MappingName = "CommonName"
                dgtbc_Common.HeaderText = "Common Name"
                dgtbc_Common.Width = 300

                Dim dgtbc_WetIndicator As New DataGridTextBoxColumn
                dgtbc_WetIndicator.MappingName = "WetIndicator"
                dgtbc_WetIndicator.HeaderText = "Indicator"
                dgtbc_WetIndicator.Width = 100

                tsScientific.GridColumnStyles.Add(dgtbc_ScientificName)
                tsScientific.GridColumnStyles.Add(dgtbc_Scientific)
                tsScientific.GridColumnStyles.Add(dgtbc_Common)
                tsScientific.GridColumnStyles.Add(dgtbc_WetIndicator)
                DataGrid1.TableStyles.Clear()
                DataGrid1.TableStyles.Add(tsScientific)

            End If
        Cursor.Current = Cursors.Default
    End Sub

I have a different button on the lookup form that opens an html file in Iexplorer.  

It works...BUT...The top bar of Iexplorer shows up, but in the area below the bar the lookup form is visible instead of the IE screen. (Sorry, I can’t get screen print to show you the situation on the emulator.)

What I want (and have achieved on some of the other screens/forms in this same ap) is to see the full iexplorer window, and when I close it, return to the lookup screen.

As a temporary workaround I used the existing code from the Exit button on the lookup screen to close the lookup screen before opening the iexplorer window.

fcancel = True
ID = ""
strname = ""
Me.Close()

This allows the iexplorer window to show completely, but it takes me back to the strata screen instead of the lookup screen.
0
 
LVL 16

Expert Comment

by:hjgode
Comment Utility
The problem is not the way you launch Internet Explorer, the problem is the form itself and it's settings (for example the fullscreen setting).

Without the code or a complete list of all settings applied to the form it will be impossible to help.

Sorry
0
 

Author Comment

by:MurphyPH
Comment Utility
Thanks for trying.  All the other screens that show IE properly are also full screen.  I am guessing that it has something to do with the datagrid and a listbox on this particular screen that do not occur on the others.  The ap is proprietary and I don't know how to easily isolate the items that need work.  I will try to figure that out.
0
 
LVL 16

Accepted Solution

by:
hjgode earned 500 total points
Comment Utility
I dont believe that listbox and datagrid are the cause, it will be a form property like WinodwState= Maximized or TopMost setting. You may also post the exefile in any way, I can analyze those too.
0
 

Author Comment

by:MurphyPH
Comment Utility
I have to set this aside for a while but I will try to get you what you need.  If I give you the .exe, sdf, and html you should be able to run it on an emulator.
0
 

Author Closing Comment

by:MurphyPH
Comment Utility
Sorry I totally lost track of this and don't have time to get back to it now.  I owe you some points for all your input.  Thanks.
0

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

Join & Write a Comment

Suggested Solutions

With Windows Embedded Handheld, called Windows Mobile, Microsoft re-designed the user interface. The Start Icon moved down to the bottom, inside the menu bar area.   If you need to hide the Start Icon and/or the SIP (soft input panel, softwar…
As the title indicates, I have done this before. It chills me everytime I update the OS on my phone, (http://www.experts-exchange.com/articles/18084/Upgrading-to-Android-5-0-Lollipop.html) because one time I did this and I essentially had a bricked …
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

772 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

8 Experts available now in Live!

Get 1:1 Help Now