Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 171
  • Last Modified:

How can I keep a program window on top?

How can I keep a program window on top?
0
echobravo316
Asked:
echobravo316
  • 3
1 Solution
 
boss302_lpCommented:
do you mean, to keep the focus or to use something like the "always on top" feature in some microsoft apps?
0
 
boss302_lpCommented:
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
 
boss302_lpCommented:
Public Sub MakeNormal(hwnd As Long)
  SetWindowPos hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS
End Sub

ooops.....missed that 'T'
0
 
imessvbCommented:
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
 
DanRollinsCommented:
Moderator, my recommended disposition is:

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

DanRollins -- EE database cleanup volunteer
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.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now