IonicWind Software

Aurora Compiler => GUI => Topic started by: Bruce Peaslee on October 26, 2016, 04:48:44 PM

Title: Intercept Dialog's Close Box
Post by: Bruce Peaslee on October 26, 2016, 04:48:44 PM
I think we talked about this before, but I cannot find it.

I have a modal dialog where I want to intercept clicking the close box so that I can ask the user if she means it.
Title: Re: Intercept Dialog's Close Box
Post by: Sam on October 26, 2016, 09:44:47 PM
Catch the WM_CLOSE message in your window/dialog procedure and proceed from there.
Title: Re: Intercept Dialog's Close Box
Post by: Bruce Peaslee on October 27, 2016, 10:46:49 AM
I've tried that. It doesn't appear to recognize the message.

Select @MESSAGE
  Case WM_CLOSE
    MessageBox 0, "Closing", "L", 0


The messagebox does not appear and the dialog closes.
Title: Re: Intercept Dialog's Close Box
Post by: Egil on October 27, 2016, 01:06:16 PM
Adding this code worked for me with EB long time ago:

case @IDCANCEL
MESSAGEBOX(dlg,"Are You sure?","error",@MB_ICONSTOP | @MB_RETRYCANCEL)


Unpack enclosed  example. Maybe thats what you are trying to do?


Egil


EDIT: Posted an incorrect example, sorry. Have to search my old archive for the right one. Will post it as soon as it is found. :-[ :-[



Title: Re: Intercept Dialog's Close Box
Post by: fasecero on October 27, 2016, 02:13:21 PM
Just in case I can make an example of this but not in Aurora code
Title: Re: Intercept Dialog's Close Box
Post by: Bruce Peaslee on October 27, 2016, 04:03:42 PM
Quote from: Egil on October 27, 2016, 01:06:16 PM
Adding this code worked for me with EB long time ago:

case @IDCANCEL
MESSAGEBOX(dlg,"Are You sure?","error",@MB_ICONSTOP | @MB_RETRYCANCEL)


Egil

Closer. The messagebox appears, but the dialog still closes.
Title: Re: Intercept Dialog's Close Box
Post by: LarryMc on October 28, 2016, 05:38:59 AM
Bruce
I think you'll have to sub-class your dialog's message handler so that the WM_CLOSE message is handled in the sub-classed handler which is where the messagebox will be coded also.  If the answer to the MB is ok-close then the sbuclass returns to the regular handler; if the answer is don't close then the regular handler is bypassed. 

For all other messages other than WM_CLOSE the subclass handler simply returns to the regular handler.

hope that makes sense.
Title: Re: Intercept Dialog's Close Box
Post by: Egil on October 28, 2016, 06:14:26 AM
Bruce,

Have searched my old backups for hours now, whitout success, can't remember what I called the file. Will continue searching.
But when I think of it, the idea for my EB code was ignited by a post in the Aurora section. And after some searching I found the origin:

http://www.ionicwind.com/forums/index.php?topic=2214.msg19420#msg19420

Guess that's what you are looking for?


Egil
Title: Re: Intercept Dialog's Close Box
Post by: LarryMc on October 28, 2016, 07:20:51 AM
Egil's solution looks the easiest in this case
Title: Re: Intercept Dialog's Close Box
Post by: Bruce Peaslee on October 28, 2016, 09:08:15 PM
I think I finally got it. While looking for articles on subclassing, I found a technique, here in IWB.


Select @MESSAGE
    Case WM_SYSCOMMAND
        If (@CODE == SC_CLOSE) and (dlgAgenda_ItemsPending() > 0)
    If MessageBox( dlgAgenda, msg, "Warning", @MB_YESNO|@MB_ICONEXCLAMATION) == @IDYES
        CloseDialog(dlgAgenda)
    EndIf
    Return true
EndIf


I am not positive why it works, but I am too tired tonight to figure it out.

Thanks for all of the suggestions.
Title: Re: Intercept Dialog's Close Box
Post by: Egil on October 29, 2016, 04:15:18 AM
Glad you solved your problem.

QuoteI am not positive why it works, but I am too tired tonight to figure it out.

To avoid the Dialog to exit, you have to return a non-zero value.

(Unable to test it in Aurora on this computer, so posting a working snippet in the IWB section)


Egil
Title: Re: Intercept Dialog's Close Box
Post by: Bruce Peaslee on October 29, 2016, 08:13:00 AM
Oops. This thread is not supposed to be in the Aurora section.