Solved

How I can make a ONTOP window?

Posted on 1998-06-26
3
151 Views
Last Modified: 2010-05-03
I need to create an application and it must be set as ONTOP window. The ICQ is a good example for this.
0
Comment
Question by:chuckwicked
  • 2
3 Comments
 
LVL 6

Expert Comment

by:clifABB
Comment Utility
0
 
LVL 4

Accepted Solution

by:
tomook earned 50 total points
Comment Utility
I originally stole this code from Microsoft. Check out the KB article clifABB cited as well. Note that this does not work if you run from the VB environment, you will have to compile an EXE and run it.
Put this in a module:
'---------- start of module code.
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
'--------- End of module code

To set a window to always on top:
    Dim lR As Long
    lR = SetTopMostWindow(Form1.hwnd, True)

To remove always on top:
    Dim lR As Long
    lR = SetTopMostWindow(Form1.hwnd, False)

0
 
LVL 6

Expert Comment

by:clifABB
Comment Utility
chuckwicked:
Why did you reject my answer?  What tomook did was cut and paste from the article I answered with.
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…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

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

16 Experts available now in Live!

Get 1:1 Help Now