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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Always on top (A Window) 3

Status
Not open for further replies.

Sylv4n

Technical User
Feb 27, 2002
83
GB
Is there a way to have a window always on top of another? I have created a image manageing application and the image is on one form in the backgound taking the whole screen, then there are up to 3 sepperate forms that are toolbars that the user can move arround, the problem is if they click on the back one it come ontop of all the others.
I have tried to on deactivate on a 'Toolbar' to set the focus to it, but when there are two toolbars you cant use the second toolbar.

Is there a "Always on top" property?

the only solution I have though of (but not tested) is to have code on the back form so that is they click it it will set focus on all of the other forms in turn.

Thanks.
 
The SetWindowPos API should provide some help for you.

The basic declaration is:

Private Declare Sub 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)

and a typical call would look something like this:

SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, (SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE) Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Module1 :

Option Explicit
Public Const SWP_NOMOVE = 2
Public Const SWP_NOSIZE = 1
Public Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2

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 Function SetTopMostWindow(hwnd As Long, Topmost As Boolean) _
As Long

If Topmost = True Then 'Make the window topmost
SetTopMostWindow = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, _
0, FLAGS)
Else
SetTopMostWindow = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, _
0, 0, FLAGS)
SetTopMostWindow = False
End If
End Function


****** Form1 *******
Command1 : SetTopMostWindow form1.hwnd , True ' set top

Command2 : SetTopMostWindow form1.hwnd , false 'wont set top
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top