?
Solved

keeping a floating form on top

Posted on 1998-10-27
2
Medium Priority
?
163 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
[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 Comments
 
LVL 2

Accepted Solution

by:
peterwest earned 150 total points
ID: 1441771
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
ID: 1441772
just the job ! chears
steve.
0

Featured Post

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.

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

800 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