?
Solved

How can I keep a program window on top?

Posted on 2003-02-28
5
Medium Priority
?
167 Views
Last Modified: 2010-05-01
How can I keep a program window on top?
0
Comment
Question by:echobravo316
[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
  • 3
5 Comments
 

Expert Comment

by:boss302_lp
ID: 8046299
do you mean, to keep the focus or to use something like the "always on top" feature in some microsoft apps?
0
 

Accepted Solution

by:
boss302_lp earned 60 total points
ID: 8046310
for "always on top":

put this in general declarations of form:

Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, Y, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const TOPMOST_FLAGS = SWP_NOMOVE Or SWP_NOSIZE

paste this into your forms code somewhere:


Public Sub MakeNormal(hwnd As Long)
   SetWindowPos hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, OPMOST_FLAGS
End Sub
Public Sub MakeTopMost(hwnd As Long)
   SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS
End Sub


now when you want to make always on top attribute, use
Call MakeTopMost(hwnd)
and to make attribute normal,
Call MakeNormal(hwnd)


hope this helps
0
 

Expert Comment

by:boss302_lp
ID: 8046316
Public Sub MakeNormal(hwnd As Long)
  SetWindowPos hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS
End Sub

ooops.....missed that 'T'
0
 

Expert Comment

by:imessvb
ID: 8062685
you might also want to put the code in a timer that keeps making your app topmost, since if other app make their app topmost your "previous" topmost will be placed behind theirs
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 9001723
Moderator, my recommended disposition is:

    Accept boss302_lp's comment(s) as an answer.

DanRollins -- EE database cleanup volunteer
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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

765 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