PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Jean-pierre Leroy on August 27, 2015, 02:32:44 PM

Title: Mutiple identical FORM not closing properly before the last answer in messageBox
Post by: Jean-pierre Leroy on August 27, 2015, 02:32:44 PM
I'm pretty sure that the solution to this problem is easy; I spent almost the whole day to find a solution by myself; I searched also in the forum without success; so I really hope that someone can help me.

Description:

Simple project with a main form FORM1, that open a non-modal form called FORM2.

- I click 3 times on the button so I have now 3 FORMs called (Form N°1, Form N°2 and Form N°3) on my screen; each form has is own unique handle.
- I click on the cross of the 3 FORMs in this order (Form N°1, Form N°2 and Form N°3) in order to close them, without responding immediately to the messageBox question.
- Now when I click on the button "Yes", on Form N°1, the Form N°1 didn't close.
- Now when I click on the button "Yes", on Form N°2, the Form N°2 didn't close
- Now when I clik on the button "Yes", on Form N°3 all the 3 forms are closed.

You help will be greatly appreciated.

Here is the code in Form1


Global lFormNumber As Long
'--------------------------------------------------------------------------------
Function FORM1_COMMAND1_BN_CLICKED ( _
                                   ControlIndex     As Long,  _  ' index in Control Array
                                   hWndForm         As Dword, _  ' handle of Form
                                   hWndControl      As Dword, _  ' handle of Control
                                   idButtonControl  As Long   _  ' identifier of button
                                   ) As Long
                                                                                 
    FORM2_SHOW(HWND_FORM1, %FALSE)                                 

End Function


Here is the code in Form2


'--------------------------------------------------------------------------------
Function FORM2_WM_CLOSE ( _
                        hWndForm As Dword _  ' handle of Form
                        ) As Long

    Select Case MessageBox(hWndForm, "Close the FORM with handle N°"+Format$(hWndForm)+" ?" & $CrLf, _
                            APP.ProductName, %MB_YESNO Or %MB_DEFBUTTON1 Or %MB_ICONQUESTION Or %MB_SYSTEMMODAL)       
                                               
        Case %IDNO
       
            Function = -1
            Exit Function
           
    End Select       
   
    FF_CloseForm(hWndForm)                                                                     

End Function

'--------------------------------------------------------------------------------
Function FORM2_WM_CREATE ( _
                         hWndForm As Dword, _      ' handle of Form
                         ByVal UserData As Long _  ' optional user defined Long value
                         ) As Long

    Incr lFormNumber                         
    FF_TextBox_SetText(HWND_FORM2, "Non modal FORM N°"+Format$(lFormNumber)+" (handle N°"+Format$(hWndForm)+")")     
 
End Function
Title: Re: Mutiple identical FORM not closing properly before the last answer in messageBox
Post by: Eddy Van Esch on August 27, 2015, 03:30:46 PM
What happens if you remove %MB_SYSTEMMODAL from the MessageBox call ..?
Title: Re: Mutiple identical FORM not closing properly before the last answer in messageBox
Post by: Jean-pierre Leroy on August 27, 2015, 05:03:12 PM
Quote
What happens if you remove %MB_SYSTEMMODAL from the MessageBox call ..?
I just tried without %MB_SYSTEMMODAL and sadly I've the same behavior.

Thank for your for help on this topic.

Regards,
Jean-Pierre
Title: Re: Mutiple identical FORM not closing properly before the last answer in messageBox
Post by: Paul Squires on August 27, 2015, 10:20:23 PM
This is such a strange situation. I do not have an explanation for this yet. Not sure why it happens this way.
Title: Re: Mutiple identical FORM not closing properly before the last answer in messageBox
Post by: David Kenny on August 28, 2015, 04:34:55 AM
It's definitely not FF.  By adding some output right under the MessageBox statement, we can see that the none of the calls to the system MessageBox returns until the last MessageBox invoked  is closed. Then they all return at once (well any that were closed before the last MessageBox invoked).  Try the same tests with this code modification. 
    Select Case MessageBox(hWndForm, "Close the FORM with handle N°"+Format$(hWndForm)+" ?" & $CrLf, _
                            APP.ProductName, %MB_YESNO Or %MB_DEFBUTTON1 Or %MB_ICONQUESTION Or %MB_SYSTEMMODAL)       
                                               
    ztrace "msgbox just closed" '<-- Added

This is not the first time we have seen undesirable results with Window's MessageBox.  It's just because we don't have full control of all aspects of MessageBox. Peter Vorster had an issue recently. http://www.planetsquires.com/protect/forum/index.php?topic=3696.0 (http://www.planetsquires.com/protect/forum/index.php?topic=3696.0) 

I was putting together some code to show Peter how to get around the problem.  I put it on the back burner when I had other things come up.  I didn't ever get back to it.  I will try to post something soon that might help.

David

Title: Re: Mutiple identical FORM not closing properly before the last answer in messageBox
Post by: Eddy Van Esch on August 28, 2015, 04:42:28 AM
If you don't want to waste more time, maybe the best work-around is to design your own messagebox ... ?
Title: Re: Mutiple identical FORM not closing properly before the last answer in messageBox
Post by: Jean-pierre Leroy on August 28, 2015, 08:02:23 AM
Thank you all for your help on this topic.

@David
QuoteIt's definitely not FF
Right you're; I made the same program with PowerBASIC only and I got exactly the same results.

@Eddy
Quote
If you don't want to waste more time, maybe the best work-around is to design your own messagebox ... ?
Thank for this idea, but I prefer to use only standard controls.

@all
To be consistent within my application I found a specific setting for the messageBox https://msdn.microsoft.com/en-us/library/windows/desktop/ms645505%28v=vs.85%29.aspx

For the modality of the dialog box I now use %MB_TASKMODAL with NULL for the hWnd parameter; with these settings the user needs to answer the question before clicking on another close button; here is the full explanation of %MB_TASKMODAL:

Quote
MB_TASKMODAL Same as MB_APPLMODAL except that all the top-level windows belonging to the current thread are disabled if the hWnd parameter is NULL. Use this flag when the calling application or library does not have a window handle available but still needs to prevent input to other windows in the calling thread without suspending other threads.

Hope that helps.

Regards,
Jean-Pierre