To make a application always on top?

I have designed an application for logging into the system to keep track of the users. so it the usere should not omot that screen how can i make the screen always on the top. and make the kleyboard disabled while that particular form is in the action. Once the user has logged in then the user can acces the keyboard. Can any one help me?
sathesh_manieAsked:
Who is Participating?
 
mathiesCommented:
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 Const SWP_FRAMECHANGED = &H20
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const SWP_SHOWME = SWP_FRAMECHANGED Or SWP_NOMOVE Or SWP_NOSIZE
Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -1



Public Sub StayOnTop(lngObjHwnd As Long, Optional blnRemoveFromTop As Boolean = False)

   'Put a window Stay on Top mode or remove from top

   Dim lngTemp As Long

On Error GoTo ErrorHandle

   If Not blnRemoveFromTop Then
      lngTemp = SetWindowPos(lngObjHwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE)
   Else
      lngTemp = SetWindowPos(lngObjHwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE + SWP_NOSIZE)
   End If
   
   Exit Sub
   
ErrorHandle:
   Err.Raise Err.Number, Err.Source, Err.Description, Err.HelpFile, Err.HelpContext

End Sub
0
 
brice123Commented:
Here is a general procedure that can be called to make a form the topmost window and to revert to the normal status.

Private 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

Sub SetTopmostWindow(ByVal hWnd As Long, Optional topmost As Boolean = True)
    Const HWND_NOTOPMOST = -2
    Const HWND_TOPMOST = -1
    Const SWP_NOMOVE = &H2
    Const SWP_NOSIZE = &H1
    SetWindowPos hWnd, IIf(topmost, HWND_TOPMOST, HWND_NOTOPMOST), 0, 0, 0, 0, _
        SWP_NOMOVE + SWP_NOSIZE
End Sub

When you wish to create a topmost window simply call this procedure passing the handle of the window:
 
SetTopmostWindow Me.hWnd

When you want to return to the normal status, call the same function passing False as the second argument:

SetTopmostWindow Me.hWnd, False
0
 
AzraSoundCommented:
how do they log in?  they need to type in a password?  so you dont want to completely disable the keyboard do you?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
burntoutCommented:
When you load the login form do it like this..

form1.Show vbModal
0
 
brice123Commented:
Is it suffisant for you if you disable the task switching? (Alt-Tab, Start, Run, Task Manager, etc...)
0
 
AzraSoundCommented:
or simply create an inputbox


Dim password As String

password = InputBox "Enter password"
0
 
AlessandroFCommented:
With this code you can set a form that is Always on top as the standard account form: The window is not resized, moved or altered in any way.

--------
Example
--------
Window_SetAlwaysOnTop Form1.hwnd, True


---------------------
function declaration
---------------------
Const SWP_NOSIZE = &H1
Const SWP_NOMOVE = &H2
Const SWP_NOREDRAW = &H8
Const HWND_TOPMOST = -1
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

--------------
Function code:
--------------

'-------------------------------------------------------------------------------
' FUNCTION    : Window_SetAlwaysOnTop(HWND, Boolean)
' DESCRIPTION : This function will set a window "always on top".
'               WIN32 API function are called to set/unset the window topmost.
'               The window is not resized, moved or altered in any way.
' PARAMETERS  : - hwnd: Long            Window to set alwasy on top.
'               - AlwaysOnTop: Boolean  Flag to set/unset always on top.
' RETURN      : True if the function succeded,
'               False if an error occured and the operation cannot be performed.
' EXAMPLE     : Window_SetAlwaysOnTop Form1.hwnd, True
'-------------------------------------------------------------------------------
Function Window_SetAlwaysOnTop(hwnd As Long, AlwaysOnTop As Boolean) As Boolean
    If AlwaysOnTop Then
        Window_SetAlwaysOnTop = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOREDRAW Or SWP_NOSIZE Or SWP_NOMOVE)
    Else
        Window_SetAlwaysOnTop = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOREDRAW Or SWP_NOSIZE Or SWP_NOMOVE)
    End If
End Function
0
 
BEVISCommented:
copy this into a module
Option Explicit

Public Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByRef lpvParam As Any, ByVal fuWinIni As Long) As Long
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Public 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 Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Const SWP_SHOWWINDOW = &H40
Public Const SWP_NOACTIVATE = &H10
Public Const HWND_TOPMOST = -1


place a command button and a textbox on your form where you can enter the password that is "Password" in this case

Option Explicit

Private Sub Command1_Click()
Dim x As Long
Dim tbwnd&
Dim showwnd&
If Text1.Text = "Password" Then
  x = SystemParametersInfo(97, False, CStr(1), 0)
  tbwnd& = FindWindow("shell_traywnd", "")
  showwnd& = ShowWindow(tbwnd&, 1)
  Form1.Hide
  Unload Form1
End If
End Sub

Private Sub Form_Load()
Dim x As Long
Dim tbwnd&, wFlags
Dim showwnd&
x = SystemParametersInfo(97, True, CStr(1), 0)
tbwnd& = FindWindow("shell_traywnd", "")
showwnd& = ShowWindow(tbwnd&, 0)
wFlags = SWP_NOMOVE Or SWP_NOSIZE Or SWP_SHOWWINDOW Or SWP_NOACTIVATE
SetWindowPos Form1.hwnd, HWND_TOPMOST, 0, 0, 0, 0, wFlags
End Sub

0
 
BEVISCommented:
Remember to remove the forms control box and windowstate to max
0
 
AzraSoundCommented:
mathies i noticed you running around today posting answers to all these questions, many of which already have sufficient comments and proposed answers which are the same as yours.  whats your deal man?
0
 
mathiesCommented:
If they don't accept comment it's because they need more info!!!
0
 
mathiesCommented:
AzraSound
If you don't like my answers, try it and you will see that everything work fine!
0
 
AzraSoundCommented:
or maybe theyve been busy and havent had a chance to respond yet. usually if it doesnt work for them theyll let us know. youre solution is no different from two comments posted already. if those dont suffice neither does yours.  chill out and just post comments.  it looks like youve been on this site awhile, you should know how things work by now.
0
 
AzraSoundCommented:
i'm not denying that they work, the point is the same damn solution was posted twice before yours.  who cares, post what you want.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.