Author Topic: Intercept Dialog's Close Box  (Read 1650 times)

0 Members and 1 Guest are viewing this topic.

Offline peaslee

  • Partner Developer
  • Hero Member
  • *****
  • Posts: 1191
  • Location: Site Y
Intercept Dialog's Close Box
« 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.
Bruce Peaslee
"Born too loose."
iTired (There's a nap for that.)
Well, I headed for Las Vegas
Only made it out to Needles

Offline Sam

  • Newbie
  • *
  • Posts: 29
Re: Intercept Dialog's Close Box
« Reply #1 on: October 26, 2016, 09:44:47 PM »
Catch the WM_CLOSE message in your window/dialog procedure and proceed from there.

Offline peaslee

  • Partner Developer
  • Hero Member
  • *****
  • Posts: 1191
  • Location: Site Y
Re: Intercept Dialog's Close Box
« Reply #2 on: October 27, 2016, 10:46:49 AM »
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

Offline Egil

  • Paid Subscriber
  • Hero Member
  • *****
  • Posts: 912
    • LA2PJ
Re: Intercept Dialog's Close Box
« Reply #3 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)

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



« Last Edit: October 27, 2016, 01:34:40 PM by Egil »
Support Amateur Radio  -  Have a ham  for dinner!

Offline fasecero

  • Full Member
  • ***
  • Posts: 249
  • I'm sorry for my English.
Re: Intercept Dialog's Close Box
« Reply #4 on: October 27, 2016, 02:13:21 PM »
Just in case I can make an example of this but not in Aurora code

Offline peaslee

  • Partner Developer
  • Hero Member
  • *****
  • Posts: 1191
  • Location: Site Y
Re: Intercept Dialog's Close Box
« Reply #5 on: October 27, 2016, 04:03:42 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

Offline LarryMc

  • Administrator
  • Hero Member
  • *****
  • Posts: 5964
  • 'All I like is finishing'
Re: Intercept Dialog's Close Box
« Reply #6 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.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Offline Egil

  • Paid Subscriber
  • Hero Member
  • *****
  • Posts: 912
    • LA2PJ
Re: Intercept Dialog's Close Box
« Reply #7 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
Support Amateur Radio  -  Have a ham  for dinner!

Offline LarryMc

  • Administrator
  • Hero Member
  • *****
  • Posts: 5964
  • 'All I like is finishing'
Re: Intercept Dialog's Close Box
« Reply #8 on: October 28, 2016, 07:20:51 AM »
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

Offline peaslee

  • Partner Developer
  • Hero Member
  • *****
  • Posts: 1191
  • Location: Site Y
Re: Intercept Dialog's Close Box
« Reply #9 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.

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

Offline Egil

  • Paid Subscriber
  • Hero Member
  • *****
  • Posts: 912
    • LA2PJ
Re: Intercept Dialog's Close Box
« Reply #10 on: October 29, 2016, 04:15:18 AM »
Glad you solved your problem.

Quote
I 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!

Offline peaslee

  • Partner Developer
  • Hero Member
  • *****
  • Posts: 1191
  • Location: Site Y
Re: Intercept Dialog's Close Box
« Reply #11 on: October 29, 2016, 08:13:00 AM »
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