Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Using OIE To Open IE From VB6 App

Posted on 2007-10-09
8
Medium Priority
?
967 Views
Last Modified: 2013-11-26
Using the code below, is there a way to force the opened IE window to have focus? There are multiple menu choices,  so the user may open 2 or more IE windows. The first window opens on top, but, if the first window is left open, the subsequent windows open behind the app. Thank you.



Dim strLink As String
Dim strFullLink As String


strLink = "http://intranet/default.aspx"

    Dim oIE As New InternetExplorer
   
    With oIE
        .Toolbar = False
        .MenuBar = False
        .Visible = True
        .FullScreen = False
        .AddressBar = False
                     
       
    End With

Select Case strReport
   
        Case "Misc Report"
            oIE.Navigate "http://intranet/default.aspx?Report=MiscReport&Year=2007&Dept=123&Class=XYZ"
           
        Case "Test Report"
            strFullLink = strLink & "?Report=" & strReport
            strFullLink = strFullLink & "&Year=" & strYear
            If strDept <> "" Then
                strFullLink = strFullLink & "&Dept=" & strDept
            End If


oIE.Navigate strFullLink
0
Comment
Question by:frizzell
  • 4
  • 4
8 Comments
 
LVL 17

Accepted Solution

by:
inthedark earned 2000 total points
ID: 20055054
Here are the API calls that will work........

Option Explicit

Private Enum FromSetOnTopConstants
    fsHWND_BOTTOM = 1
    fsHWND_BROADCAST = &HFFFF&
    fsHWND_DESKTOP = 0
    fsHWND_NOTOPMOST = -2
    fsHWND_TOP = 0
    fsHWND_TOPMOST = -1
   
    fsSWP_NOACTIVATE = &H10
    fsSWP_SHOWWINDOW = &H40
    fsSWP_NOSIZE = &H1
    fsSWP_NOMOVE = &H2
End Enum
Private Declare Function SetWindowPos Lib "user32" (ByVal Hwnd As Long, _
                                       ByVal hWndInsertAfter As Long, _
                                       ByVal X As Long, _
                                       ByVal Y As Long, _
                                       ByVal cx As Long, _
                                       ByVal cy As Long, _
                                       ByVal wFlags As Long) As Long



Private Sub Form_Load()

Dim oIE As New InternetExplorer

   
With oIE
    .ToolBar = False
    .MenuBar = False
    .Visible = True
    .FullScreen = False
    .AddressBar = False
End With

oIE.Navigate "http://www.bbc.co.uk"


' forece to stay on top
SetWindowOnTop oIE.Hwnd, fsHWND_TOPMOST

DoEvents

Dim oIE2 As New InternetExplorer


With oIE2
    .ToolBar = False
    .MenuBar = False
    .Visible = True
    .FullScreen = False
    .AddressBar = False
End With
oIE2.Navigate "http://www.sky.com"

DoEvents

' make normal so as not to upset the operator
SetWindowOnTop oIE.Hwnd, fsHWND_NOTOPMOST


End Sub

Private Sub SetWindowOnTop(plHWND As Long, Optional pos As FromSetOnTopConstants = fsHWND_TOPMOST)

' Call SetWindowOnTop(Obj.HWND,HWND_TOPMOST)

' Description
'     Makes Obj the top-most window
'
' Parameters
'     Name                    Type     Value
'     -------------------------------------------------------------------------
'     Pos                     Integer  HWND_TOPMOST   if form is to be on top
'                                      HWND_NOTOPMOST if form is be not on top
'     Obj.HWND                Long     The HWND of the window to set on top
'
' Returns
'     Nothing
'
' Last modified by Jens Balchen 10.03.1996

   SetWindowPos plHWND, CLng(pos), 0, 0, 0, 0, fsSWP_NOMOVE Or fsSWP_NOSIZE Or fsSWP_NOACTIVATE Or fsSWP_SHOWWINDOW

End Sub
0
 

Author Comment

by:frizzell
ID: 20068125
I haven't had time to try your code, because unfortunately my computer needs to be rebuilt. Thank you for the suggestion.
0
 
LVL 17

Expert Comment

by:inthedark
ID: 20077030
>my computer needs to be rebuilt

So does mine, it works for a few hours then randomly just switches off.  

Bad luck, hope you get it sorted soon and it does not cost too much........
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:frizzell
ID: 20085317
I've tested your code in my project, and it works well. Now the problem is that each IE window stays on top,  so to return to the application the user must drag the window out of the way. Is there a simple way to make the focus return to the application window while still keeping the IE windows open in the background? Thank you.
0
 

Author Comment

by:frizzell
ID: 20085346
Just to clarify: I want the focus to return to the app when it is clicked, not automatically. As it exists, when a user clicks on the app window, the IE windows stay on top.
0
 
LVL 17

Expert Comment

by:inthedark
ID: 20086053
Ok so I think I understand how you need it to work, so just a few simple mods.....


Private Sub mnu_MyMenuOption_Click()

zOpenIE "http://MyServer/MyPage.htm"

End Sub

Private Sub  zOpenIE(psURL As String)

Dim oIE As New InternetExplorer
   
With oIE
    .ToolBar = False
    .MenuBar = False
    .Visible = True
    .FullScreen = False
    .AddressBar = False
End With

oIE.Navigate "http://www.bbc.co.uk"

' force to stay on top
SetWindowOnTop oIE.Hwnd, fsHWND_TOPMOST
DoEvents

' Now we may have to monitor page status but not sure right now.....
' But weshould now relegate the new IEWindow to a normal window
' It will stay on top but allow the app window to become top most

SetWindowOnTop oIE.Hwnd, fsHWND_NOTOPMOST

End Sub
0
 
LVL 17

Expert Comment

by:inthedark
ID: 20086065
Woops....

oIE.Navigate psURL
0
 

Author Comment

by:frizzell
ID: 20093082
The program is now working as I intended. Thank you for all of your coding assistance.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month14 days, 11 hours left to enroll

578 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