Open Internet Explorer Window as a Popunder

Hello everyone,
I already have my VB app opening up an internet explorer window with no problems. Everything works fine, my only problem is I want to open the window as a popunder (i.e. leave the current explorer window open focused and have this one blurred) I haven't found any VB code that can actually control this. My guess is that I would have to state an hwnd for the new window that is lower than any other window currently open? Anyways I want to steer clear of opening an html page that has javascript embedded to blur the page, as this is a really choppy workaround.  Here is the current sub I am using to popup the window. Thanks

Public Sub LoadURL(URL)
    On Error Resume Next
    Set modObjIE = CreateObject("InternetExplorer.Application")
    modObjIE.ToolBar = False
    modObjIE.StatusBar = False
    modObjIE.ScrollBar = True
    modObjIE.Visible = True
    modObjIE.Navigate2 URL
    modlngWndIE = modObjIE.hwnd
End Sub
mikeytagAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
RobMeConnect With a Mentor Commented:
Why don't you just pass the form from which you are calling the sub and end by showing it, like this

Public Sub LoadURL(URL,formName as Form)
   On Error Resume Next
   Set modObjIE = CreateObject("InternetExplorer.Application")
   modObjIE.ToolBar = False
   modObjIE.StatusBar = False
   modObjIE.ScrollBar = True
   modObjIE.Visible = True
   modObjIE.Navigate2 URL
   modlngWndIE = modObjIE.hwnd

   formName.Show

End Sub

That will make your IE open and then just make your form get in focus again or you could use formName.SetFocus
0
 
SmallintCommented:

Try to add:

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 Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOZORDER = &H8


and in LoadURL


SetWindowPos modlngWndIE, HWND_TOPMOST, 0, 0, 0, 0, _
   SWP_NOZORDER + SWP_NOMOVE + SWP_NOSIZE

0
 
SmallintCommented:

Correction:

SetWindowPos modlngWndIE, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE + SWP_NOMOVE


0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
mikeytagAuthor Commented:
Interesting code, tried it out and it did pop the window "under" only problem was if you clicked it the window never came up into view, it was always offscreen.

I just figured out how to do it so for all of you out there who are wondering here it is:

In a module add the following:

Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
Private Declare Function AttachThreadInput Lib "user32" (ByVal idAttach As Long, ByVal idAttachTo As Long, ByVal fAttach As Long) As Long
Public Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function IsIconic Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function ShowWindow2 Lib "user32" (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long
'
' Constants used with APIs
'
Private Const SW_SHOW = 5
Private Const SW_RESTORE = 9


Public Function ForceForegroundWindow(ByVal hWnd As Long) As Boolean
   Dim ThreadID1 As Long
   Dim ThreadID2 As Long
   Dim nRet As Long
   '
   ' Nothing to do if already in foreground.
   '
   If hWnd = GetForegroundWindow() Then
      ForceForegroundWindow = True
   Else
      '
      ' First need to get the thread responsible for this window,
      ' and the thread for the foreground window.
      '
      ThreadID1 = GetWindowThreadProcessId(GetForegroundWindow, ByVal 0&)
      ThreadID2 = GetWindowThreadProcessId(hWnd, ByVal 0&)
      '
      ' By sharing input state, threads share their concept of
      ' the active window.
      '
      If ThreadID1 <> ThreadID2 Then
         Call AttachThreadInput(ThreadID1, ThreadID2, True)
         nRet = SetForegroundWindow(hWnd)
         Call AttachThreadInput(ThreadID1, ThreadID2, False)
      Else
         nRet = SetForegroundWindow(hWnd)
      End If
      '
      ' Restore and repaint
      '
      If IsIconic(hWnd) Then
         Call ShowWindow2(hWnd, SW_RESTORE)
      Else
         Call ShowWindow2(hWnd, SW_SHOW)
      End If
      '
      ' SetForegroundWindow return accurately reflects success.
      '
      ForceForegroundWindow = CBool(nRet)
   End If
End Function

Then add the following to your form/button/whatever to actually make the window go under (actually it makes the current window go over and forces it to the foreground):

Dim lwnd As Long
lwnd = GetForegroundWindow()
Call ForceForegroundWindow(lwnd)
0
 
mikeytagAuthor Commented:
Never mind, the code I provided is buggy. Sometimes it does the popunder and sometimes it doesn't.  Any other ideas would be appreciated. Thanks
0
 
bhnv9Commented:
Try this...
Paste this code in a module and call as:
open_ie(<your address>)

Option Explicit

''''''''''''''''''''''''''''
''declaration for opening internet address
Private Declare Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" _
(ByVal hWnd As Long, _
ByVal IpOperation As String, _
ByVal IpFile As String, _
ByVal IpParameters As String, _
ByVal IpDirectory As String, _
ByVal nShowCmd As Long) As Long

Public Sub open_ie(address As String)
    Call ShellExecute(0&, vbNullString, address, vbNullString, vbNullString, vbNormalNoFocus)
End Sub

The last parameter in the ShellExecute can be:
vbNormalFocus, vbMinimizeNoFocus etc.
See "Shell Constants" in the msdn library.
Hope this solves your problem
0
 
GPrentice00Commented:
This question has been classified as abandoned.  I will make a recommendation to the moderators on its resolution in a week or two.  I would appreciate any comments by the experts that would help me in making a recommendation.

It is assumed that any participant not responding to this request is no longer interested in its final deposition.

If the asker does not know how to close the question, the options are here:
http://www.experts-exchange.com/help/closing.jsp

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER

GPrentice00
Cleanup Volunteer
0
 
GPrentice00Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

 -->Accept RobMe's comment as Answer

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER

GPrentice00
Cleanup Volunteer
0
All Courses

From novice to tech pro — start learning today.