modal form


How to show a system wide modal form?
I don't mean: vbmodal

I mean a way to make a modal form on top of all the running applications on Window.

Take care.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hi...u can use the 'SetTopmostWindow Me.hwnd' call to set the focus for the main form on top. the function
would use the 'setwindowpos' api to do that and it would look something like:

Private Declare Sub 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)

Sub SetTopmostWindow(ByVal hwnd As Long, Optional topmost As Boolean = True)
  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

Hope the above solution is of help

tocosAuthor Commented:
Hello hongjun,

Thank you for your fast response ..
What you gave here .. is a topmost for over all the application .. but is not modal .. as you still can access all the running applications.

I needed this form as a modal form that will disable accessing of all the running application.

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.

tocosAuthor Commented:
didn't work out for me ..
It only disable the affected form but I'm still accessing any of the running applications.
A long time ago I did a lot of research on this.  I found that the best way to sieze control of the machine, is by hiding all the visible windows.  Another very good way is to have your window on top and covering the whole screen, but maybe you prefer how this looks instead:

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal sClassName As String, ByVal sWindowTitle As String) As Long
Private Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Private Const SW_HIDE = 0
Private Const SW_SHOW = 5
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Const GW_HWNDNEXT = 2

Dim HiddenWindows As New Collection
Private Sub Form_Load()
Dim hParent As Long
    hParent = FindWindow(vbNullString, vbNullString)
    While hParent <> 0
        If IsWindowVisible(hParent) Then
            ShowWindow hParent, SW_HIDE
            HiddenWindows.Add hParent
            Debug.Print hParent
        End If
        hParent = GetWindow(hParent, GW_HWNDNEXT)
    Me.Print "Close this form to bring everything back"
End Sub
Private Sub Form_Unload(Cancel As Integer)
    For Each Window In HiddenWindows
        ShowWindow Window, SW_SHOW
End Sub

Try the code above and see how you like it.  Make sure to only run the compiled exe though.  It seems that from the environment, sometimes a window may be missed.  dunno why.

The only way a user may do anything besides interact with your form, is by pressing the Windows key, and doing CTRL+ALT+DEL.  CTRL+ALT+DEL can be disabled under Win9x, but it's not recommended.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tocosAuthor Commented:
Hello SilentRage,

I think this scenario is the best I can get .. thank you

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

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.