?
Solved

Open Internet Explorer Window as a Popunder

Posted on 2003-03-07
8
Medium Priority
?
272 Views
Last Modified: 2013-12-25
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
0
Comment
Question by:mikeytag
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 7

Expert Comment

by:Smallint
ID: 8086792

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
 
LVL 7

Expert Comment

by:Smallint
ID: 8086829

Correction:

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


0
 

Author Comment

by:mikeytag
ID: 8087489
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:mikeytag
ID: 8089235
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
 

Expert Comment

by:bhnv9
ID: 8096980
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
 

Accepted Solution

by:
RobMe earned 300 total points
ID: 8099322
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
 
LVL 6

Expert Comment

by:GPrentice00
ID: 9053185
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
 
LVL 6

Expert Comment

by:GPrentice00
ID: 9116517
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

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

762 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