Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need new browser window "always on top" (but not necessarily focused)

Status
Not open for further replies.

NewFromMattel

Programmer
Jun 24, 2003
41
US
Here's my situation...

I am popping up a new specially sized browser window to run scrolling messages. So users can see messages that may get updated concerning their work. (The audience is a very known group, and can be a controlled group).

What I need is a way (activex?) to force the new popup window to be "Always on Top". Not necessarily focused though. And I've tried modeless windows, but that works only for the window that "spawned" the popup. I need it to be OS wide. Hence my guess of the activex control, or dll.

Any ideas? Oh, and since it is a "controlled" group of users, I can test for the existance of the activex or popup, and use it if it's there, and any other people that get this popup just won't have the always on top feature.

TIA
 
I'm assuming that you are using the webbrowser control on a form, if so try this.

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 SWP_NOMOVE = 2
Private Const SWP_NOSIZE = 1
Private Const Flags = SWP_NOMOVE Or SWP_NOSIZE
Private Const HWND_TOP = 0
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Sub Form_Load()
Call SetWindowPos(Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, Flags)
End Sub
 
Actually no. I'm calling a new browser window from an existing browser window. Using the javascript window.open() command.
 
Did u get it working?

I have exactly the same challenge in my app,
hope u can help me out.
 
Nope not yet. I'm sure it can be done. But don't know how. It appears that most people use a java or vb "wrapper" to call the HTML into. But I can't do that. If I figure it out, or find the answer, I'll make sure to post it here. Keep your email notification turned on for this thread.
 
NewFromMattel,

DrJavaJoe had the right idea back on Jan. 19. Since you're using an existing browser, and not a webbrowser control on a VB form, it's just a matter of find the handle (hwnd) to use for the browser. This is just a quick test that works with IE, so if you're using a different browser, you'll need to figure out the class name to use. For IE, the class name is "IEFrame"

Just paste this code in a standard module (.bas):

Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public 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
Public Const SWP_NOMOVE = 2
Public Const SWP_NOSIZE = 1
Public Const Flags = SWP_NOMOVE Or SWP_NOSIZE
Public Const HWND_TOP = 0
Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2

Public IEhwnd As Long


Then put a command button on your form with this code:

IEhwnd = FindWindow("IEFrame", vbNullString)
' FindWindow will find the handle for an IE browser window

Call SetWindowPos(IEhwnd, HWND_TOPMOST, 0, 0, 0, 0, Flags)
' Use that handle (IEhwnd) in the SetWindowPos function


The IE browser window will now be on top of all other windows. To reverse it, do the same SetWindowPos call with HWND_NOTOPMOST.

This was just a simple test with one browser window open. If there are multiple browsers open, you'll have to do some additional coding to determine the correct one to use.

Good luck,

Don
 
Thanks for the response! I appreciate it. I'm going to try to implement this, and when I do... I'll let you know how it works.

Again... thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top