Link to home
Start Free TrialLog in
Avatar of tocos
tocos

asked on

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
Avatar of hongjun
hongjun
Flag of Singapore image

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
Avatar of tocos
tocos

ASKER

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
Avatar of tocos

ASKER

didn't work out for me ..
It only disable the affected form but I'm still accessing any of the running applications.
ASKER CERTIFIED SOLUTION
Avatar of SilentRage
SilentRage

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of tocos

ASKER

Hello SilentRage,

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

Hesham