Solved

keeping a floating form on top

Posted on 1998-10-27
2
158 Views
Last Modified: 2010-04-30
How do I force a form to remain ontop of all other forms running on the windows desktop , even if it does not have focus ?
for example say i was using a form to provide a toolbar for another form and wanted it to alway stay on top of that form.
0
Comment
Question by:spg01
2 Comments
 
LVL 2

Accepted Solution

by:
peterwest earned 50 total points
Comment Utility
Hi there,

I've always used the code below - it was taken from the VB Knowledge Base.   Put the following code in a module.

      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" Alias "SetWindowPos" (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


To use this function just put the following in the Form_Load event of the form you want on top:

        Dim lRetVal as Long
        lRetVal = SetTopMostWindow(Me.Hwnd,True)

And then - in the Form_Unload event put:

        Dim lRetVal as Long
        lRetVal = SetTopMostWindow(Me.Hwnd,False)

This just stops it from being the topmost window.

Hope it helps,

Pete

0
 

Author Comment

by:spg01
Comment Utility
just the job ! chears
steve.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now