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: 213
  • Last Modified:

modal form

Hello,

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

form1.show vbmodal

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

Take care.
Hesham
0
tocos
Asked:
tocos
  • 3
  • 2
1 Solution
 
hongjunCommented:
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_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

Hope the above solution is of help

hongjun
0
 
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.

Regards,
Hesham
0
 
hongjunCommented:
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
tocosAuthor Commented:
didn't work out for me ..
It only disable the affected form but I'm still accessing any of the running applications.
0
 
SilentRageCommented:
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)
    Wend
    Me.Show
    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
    Next
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.
0
 
tocosAuthor Commented:
Hello SilentRage,

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

Hesham
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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