Dealing with the 'x' in a Dialog Box

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
fthomas
Pro Scripter
Posts: 91
Joined: Fri Oct 03, 2008 6:40 pm

Dealing with the 'x' in a Dialog Box

Post by fthomas » Wed Jul 23, 2014 7:50 pm

Good day all,

I'm trying to create a pretty sophisticated dialog box in macro scheduler, and I'm stuck when it comes to someone clicking the 'x' in the top right hand corner. I'd like to capture that click and present an Ask box confirming closing the box.

How can that be done?

Thanks!

Frank

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Dealing with the 'x' in a Dialog Box

Post by Marcus Tettmar » Wed Jul 23, 2014 9:31 pm

Yes. Set a handler for the OnClose or OnCloseQuery event.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

fthomas
Pro Scripter
Posts: 91
Joined: Fri Oct 03, 2008 6:40 pm

Re: Dealing with the 'x' in a Dialog Box

Post by fthomas » Thu Jul 24, 2014 5:35 pm

Thanks Marcus, but do you have an example of this? I'm still finding that the window is closing on me and I cannot stop this.

I'd like to mimic the functionality of the 'cancel' button where I have a dialog hander such as:

Code: Select all

AddDialogHandler>Dialog1,MSButton2,OnClick,VerifyCancel

SRT>VerifyCancel
Ask>Are You Sure You Wish To Cancel?,varVerifyCancel
if>varVerifyCancel=YES
CloseDialog>Dialog1
Exit>0
Endif>
END>VerifyCancel
Thanks!

Frank

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Dealing with the 'x' in a Dialog Box

Post by Marcus Tettmar » Thu Jul 24, 2014 6:51 pm

This works for me:

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 454
  Top = 162
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 212
  ClientWidth = 476
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object MSButton1: tMSButton
    Left = 133
    Top = 137
    Width = 75
    Height = 25
    Caption = 'Cancel'
    TabOrder = 8
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,MSButton1,OnClick,doCancel

Show>Dialog1,r

SRT>doCancel
  Ask>Are you sure?,yesNo
  If>YesNo=YES
    CloseDialog>Dialog1
  Endif
END>doCancel
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

fthomas
Pro Scripter
Posts: 91
Joined: Fri Oct 03, 2008 6:40 pm

Re: Dealing with the 'x' in a Dialog Box

Post by fthomas » Fri Jul 25, 2014 2:31 pm

Good day Marcus,

I tried your program and yes, the way you have the cancel button working - I want the same functionality with the 'x' at the top right hand side of the window. I want the dialog to stay open and confirm closing it if someone clicks the 'x' as well.
click the x.jpg
Thanks!

Frank

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Dealing with the 'x' in a Dialog Box

Post by JRL » Fri Jul 25, 2014 3:21 pm

Its a little more complicated to deal with the close dialog "X" than to have a separate button. But I understand why you'd want to have control. I'm notorious for picking the "X" when I really didn't want to close the window.

I don't know of any way to do this using a modal dialog. Here is Marcus' example converted to a non-modal dialog and with a close dialog handler, flag variables and labels added to control what happens when the "X" is selected. You will notice that we can't stop the dialog from closing, what happens is we let it close then reopen it if the user selects "No" when asked, "Are you sure?".

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 454
  Top = 162
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 212
  ClientWidth = 476
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object MSButton1: tMSButton
    Left = 133
    Top = 137
    Width = 75
    Height = 25
    Caption = 'Cancel'
    TabOrder = 8
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog1
AddDialogHandler>Dialog1,MSButton1,OnClick,doCancel
AddDialogHandler>Dialog1,,OnClose,doCancel

Label>DisplayDialog
Let>ReDisplayDialogFlag=0
Show>Dialog1

Label>Loop
  Wait>0.01
  If>ReDisplayDialogFlag=1
    Goto>DisplayDialog
  EndIf
Goto>Loop

SRT>doCancel
  If>ReDisplayDialogFlag=0
    Ask>Are you sure?,yesNo
    If>YesNo=YES
      Let>ReDisplayDialogFlag=2
      CloseDialog>Dialog1
      //You may want to Exit> here
      //Exit>0
    Else
      Let>ReDisplayDialogFlag=1
    Endif
  EndIf
END>doCancel

fthomas
Pro Scripter
Posts: 91
Joined: Fri Oct 03, 2008 6:40 pm

Re: Dealing with the 'x' in a Dialog Box

Post by fthomas » Fri Jul 25, 2014 5:22 pm

Thanks JRL,

I kind of thought that may be the way, but I wasn't sure how to implement or if the fields would retain their values. But all looks good!

Thanks a bunch.

Frank

User avatar
Phil Pendlebury
Automation Wizard
Posts: 543
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Re: Dealing with the 'x' in a Dialog Box

Post by Phil Pendlebury » Wed Sep 24, 2014 12:50 pm

Another option for you in case you hadn't thought of it... Personally, I usually remove those "windows" options completely so folks have to use my controls.

Code: Select all

Dialog>UADialaog1
object UADialaog1: TForm
  Left = 845
  Top = 507
  HelpContext = 5000
  BorderIcons = []
  BorderStyle = bsSingle
  Caption = 'UAD Mover 4'
  ClientHeight = 288
  ClientWidth = 345
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  Menu = MainMenu
  OldCreateOrder = True
  Position = poScreenCenter
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
etc...
uad.JPG
Phil Pendlebury - Linktree

Jamball77
Newbie
Posts: 14
Joined: Tue Aug 11, 2015 2:25 pm

Re: Dealing with the 'x' in a Dialog Box

Post by Jamball77 » Thu Sep 24, 2015 2:09 pm

I like Phil Pendlebury post idea of removing the X in the title bar.

I'm using MS 14

* Go to the dialog editor
* Click the background or title bar to give the whole form focus
* Look at the properties window should say something like "Properties for: dialog"
* scroll down in properties to BORDER ICONS and deselect biSystemMenu from the dropdown menu.
remove_X from Windows Title Bar.jpg

User avatar
Phil Pendlebury
Automation Wizard
Posts: 543
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Re: Dealing with the 'x' in a Dialog Box

Post by Phil Pendlebury » Fri Sep 25, 2015 2:29 pm

Or use what I posted above:

Code: Select all

BorderIcons = []
BorderStyle = bsSingle
Phil Pendlebury - Linktree

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts