Solved

To make a application always on top?

Posted on 2000-04-17
14
422 Views
Last Modified: 2010-05-02
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?
0
Comment
Question by:sathesh_manie
[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
  • 5
  • 3
  • 2
  • +3
14 Comments
 
LVL 2

Expert Comment

by:brice123
ID: 2725446
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
 
LVL 28

Expert Comment

by:AzraSound
ID: 2725504
how do they log in?  they need to type in a password?  so you dont want to completely disable the keyboard do you?
0
 
LVL 2

Expert Comment

by:burntout
ID: 2725619
When you load the login form do it like this..

form1.Show vbModal
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 2

Expert Comment

by:brice123
ID: 2725623
Is it suffisant for you if you disable the task switching? (Alt-Tab, Start, Run, Task Manager, etc...)
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2725627
or simply create an inputbox


Dim password As String

password = InputBox "Enter password"
0
 

Expert Comment

by:AlessandroF
ID: 2725866
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
 

Expert Comment

by:BEVIS
ID: 2725872
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
 

Expert Comment

by:BEVIS
ID: 2725884
Remember to remove the forms control box and windowstate to max
0
 
LVL 1

Accepted Solution

by:
mathies earned 100 total points
ID: 2752809
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
 
LVL 28

Expert Comment

by:AzraSound
ID: 2753094
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
 
LVL 1

Expert Comment

by:mathies
ID: 2753124
If they don't accept comment it's because they need more info!!!
0
 
LVL 1

Expert Comment

by:mathies
ID: 2753140
AzraSound
If you don't like my answers, try it and you will see that everything work fine!
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2753142
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
 
LVL 28

Expert Comment

by:AzraSound
ID: 2753153
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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MsgBox 4 76
Publisher:   Unknown     VB.exe Application 1 32
VBA: copy range dynamically based on config sheet v3 6 54
2 Global Vars, 1 List Box 4 34
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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
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…

751 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