Results 1 to 3 of 3

Thread: Modal mode to show forms that allows non-modal forms

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,996

    Modal mode to show forms that allows non-modal forms

    This is a simple function that can be used as a replacement to show forms "modally" but still allow to show non-modal forms:

    In a module:

    Code:
    Private Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Long)
    
    Public Sub ShowModal(nForm As Form, Optional OwnerForm)
        Dim ColF As Collection
        Dim ColE As Collection
        Dim f As Form
        Dim c As Long
        
        Set ColF = New Collection
        Set ColE = New Collection
        For Each f In Forms
            If Not f Is nForm Then
                ColF.Add f
                ColE.Add f.Enabled
                f.Enabled = False
            End If
        Next
        nForm.Show , IIf(IsMissing(OwnerForm), Screen.ActiveForm, OwnerForm)
        Do While IsFormLoaded(nForm)
            DoEvents
            Sleep 1
        Loop
        For c = 1 To ColF.Count
            ColF(c).Enabled = ColE(c)
        Next
    End Sub
    
    Private Function IsFormLoaded(nForm As Form) As Boolean
        Dim f As Form
        
        For Each f In Forms
            If f Is nForm Then
                IsFormLoaded = True
                Exit Function
            End If
        Next
    End Function
    Usage:

    Code:
    ShowModal Form2

  2. #2
    Frenzied Member
    Join Date
    May 2014
    Location
    Kallithea Attikis, Greece
    Posts
    1,289

    Re: Modal mode to show forms that allows non-modal forms

    In M2000 Interpreter (written in VB6) I have another system, using a number for each "modal" state, so we can open two or more modal forms, one over the other, and maybe between them some other forms, so each time a modal form open, the number from enabled forms (over previous modal form(s)) take the new number from new modal. So each time a modal form close, re-enable only those forms which previous disabled. For each modal form i use a non modal way to open, and set a loop for waiting to close. So I didn't use the modal way of vb6, and the forms behind can work (using a form of threads in the script language M2000). These forms are user forms (we made them on the fly - in a running vb6 application) which populated with controls which have the same "base" control, and classes which take the actual events. These forms are without title as vb6 forms but we see title and another in task bar (by using a second always minimized form for each user form).
    This is the GuiM2000.frm (the user form)
    https://github.com/M2000Interpreter/...n/GuiM2000.frm
    There are two variables: Private mModalid As Double, mModalIdPrev As Double
    And a TestModal()
    Public Sub TestModal(alfa As Double)
    If mModalid = alfa Then
    mModalid = mModalIdPrev
    mModalIdPrev = 0
    Enablecontrol = True
    End If
    End Sub
    Property Get Modal() As Double Modal = mModalid
    End Property
    Property Let Modal(RHS As Double)
    mModalIdPrev = mModalid
    mModalid = RHS
    End Property

    Following mModalid in the source you can see how it works.

    There one more function, the PopUp which open as modal but when modal form lost focus then close automatic and enabling all other forms. This used also as dropdown windows for menu or lists (handled from GuiDropDown.cls).

    I didn't use subclassing (hooks), only a rotated hook for middle mouse button. Rotated means that every usercontrol (there is only one glist4.ctr) register for hook and unregister when lost focus, So with one hook we can serve every isercontrol. This is not working well in IDE. I read and see about new subclassing, but I want something which can disabled/enabled, rotating by the way I did.
    Three windows, which are not modal, with a "console" window behind (which can't take, stay behind always, but take mouse move, clicks, and keyboard events. using script). We can open a modal "msbox", without stopping the threads in each form. The theads are from the scripting language M2000.
    Attachment 183271

    This is another screen shot showing a test form, which is a different form (not in the group of user forms, so this form never disabled from modal user forms, and if console showing - the main form of the m2000 environment), has this as parent form, so it is always in front, but not always in front the user forms. From this form we can stop threads and execute step by step the scripting language. But we can't stop events from forms which the scripting language handle.
    So we can open the test form, enter the slow step execution, and when closing one form then a message box open (modal) (from event servicing by the script) and we can select the modal message box or the test form (which never disabled by modal system). That is the benefit to use your own modal mechanism.
    Attachment 183272

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,996

    Re: Modal mode to show forms that allows non-modal forms

    Hello georgekar, yes, that seems something similar.

    BTW, a related function is to test whether VB6 is currently modal, I mean modal in the VB6 modality: it is here.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width