February 16, 2020, 12:11:56 pm

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Intercept Dialog's Close Box

Started by Bruce Peaslee, October 26, 2016, 04:48:44 pm

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Bruce Peaslee

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.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Sam

Catch the WM_CLOSE message in your window/dialog procedure and proceed from there.

Bruce Peaslee

I've tried that. It doesn't appear to recognize the message.

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


The messagebox does not appear and the dialog closes.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Egil

October 27, 2016, 01:06:16 pm #3 Last Edit: October 27, 2016, 01:34:40 pm by Egil
Adding this code worked for me with EB long time ago:

Code Select
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. :-[ :-[



Support Amateur Radio  -  Have a ham  for dinner!

fasecero

Just in case I can make an example of this but not in Aurora code

Bruce Peaslee

Quote from: Egil on October 27, 2016, 01:06:16 pm
Adding this code worked for me with EB long time ago:

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


Egil


Closer. The messagebox appears, but the dialog still closes.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

LarryMc

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.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Egil

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
Support Amateur Radio  -  Have a ham  for dinner!

LarryMc

Egil's solution looks the easiest in this case
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Bruce Peaslee

I think I finally got it. While looking for articles on subclassing, I found a technique, here in IWB.

Code Select

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.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Egil

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
Support Amateur Radio  -  Have a ham  for dinner!

Bruce Peaslee

Oops. This thread is not supposed to be in the Aurora section.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles