Solved

How I can make a ONTOP window?

Posted on 1998-06-26
3
153 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
ID: 1464434
0
 
LVL 4

Accepted Solution

by:
tomook earned 50 total points
ID: 1464435
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
ID: 1464436
chuckwicked:
Why did you reject my answer?  What tomook did was cut and paste from the article I answered with.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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 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…
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…

809 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