BBC BASIC for Windows
Programming >> User Interface >> How to disable the CLOSE button on a Dialogue Box
http://bb4w.conforums.com/index.cgi?board=ui&action=display&num=1393196908

How to disable the CLOSE button on a Dialogue Box
Post by kingsmiller on Feb 23rd, 2014, 8:34pm

Can anyone help, I am stumped (yet again).

I want the user to exit via my designated Exit Button. To that end I can disable the main Close Button by ...

SC_CLOSE = &F060
SYS "GetSystemMenu", @hwnd%, 0 TO sysmenu%
SYS "EnableMenuItem", sysmenu%, SC_CLOSE, 1

And enable it again when I need too.

But that then leaves me the CLOSE BUTTON on the Dialogue Box, how do I disable those.

I think that I have read somewhere that WINLIB2B.BBC contains a routine to close the CLOSE button - but that seems not to work for me.

Many Thanks .. Bill

Re: How to disable the CLOSE button on a Dialogue
Post by admin on Feb 23rd, 2014, 10:08pm

on Feb 23rd, 2014, 8:34pm, kingsmiller wrote:
I think that I have read somewhere that WINLIB2B.BBC contains a routine to close the CLOSE button - but that seems not to work for me.

It does work. Using WINLIB2B will suppress the automatic closing of the dialogue box when you click on the close button or press the Esc key. They will still generate an IDCANCEL message (code 2), so it may be that the reason it didn't appear to work for you is that you're closing the window yourself on receipt of that message. If so, don't!

A weakness of this approach is that the close button will still look as though it ought to work, so you might want to consider disabling it - you can use the code you listed but with @hwnd% replaced by the dialogue box's window handle - or removing the dialogue's Title Bar entirely.

Richard.

Re: How to disable the CLOSE button on a Dialogue
Post by kingsmiller on Feb 24th, 2014, 08:30am

Richard - Thanks for getting back with an answer so quickly.

I have tried to remove the title bar and that is quite straightforward. But I would like to keep the title bars as it gives instruction for the User.

Disabling the Dialogue Box CLOSE button as you suggested would be best option for me.

I have changed the code as you suggested to -

:
DEFPROCtask
LOCAL Y%
PROC_showdialog(dlg2%)

SC_CLOSE = &F060
SYS "GetSystemMenu", dlg2%, 0 TO sysmenu%
SYS "EnableMenuItem", sysmenu%, SC_CLOSE, 1

SYS "SendDlgItemMessage",!dlg2%, 300, STM_SETIMAGE, 0, hbitmap2% : REM Display the Logo
SYS "CheckRadioButton",!dlg2%,101,123,101: REM

etc etc ...

As you can see I have placed it after PROC_showdialog(dlg2%) but it is still active. Could you tell me what I am doing wrong.

Many Thanks .. Bill

Re: How to disable the CLOSE button on a Dialogue
Post by kingsmiller on Feb 24th, 2014, 08:51am

Sorry Richard - I have just spotted my mistake - my code should have read -

:
DEFPROCtask
LOCAL Y%
PROC_showdialog(dlg2%)

SC_CLOSE = &F060
SYS "GetSystemMenu", !dlg2%, 0 TO sysmenu%
SYS "EnableMenuItem", sysmenu%, SC_CLOSE, 1

SYS "SendDlgItemMessage",!dlg2%, 300, STM_SETIMAGE, 0, hbitmap2% : REM Display the Logo
SYS "CheckRadioButton",!dlg2%,101,123,101: REM Select Gm2 as default

Regards .. Bil

Re: How to disable the CLOSE button on a Dialogue
Post by JGHarston on Mar 2nd, 2014, 10:13pm

on Feb 23rd, 2014, 8:34pm, kingsmiller wrote:
I want the user to exit via my designated Exit Button. To that end I can disable the main Close Button by ...

The first thing you should be asking yourself when you want to break the established user interface is "why?". The user will naturally go straight to the Close icon, trying to direct them to use something else to Close the application is breaking their established paradigm.

(I've just had three weeks of training users on a new system every time saying "now close the window, but not with the Close icon, but with the icon labelled Close!")

If you want your program to do something when the user closes it, then catch the close event.

Re: How to disable the CLOSE button on a Dialogue
Post by kingsmiller on Mar 3rd, 2014, 07:48am

Many thanks for your reply.

You are quite correct in what you are saying, I think I should re-evaluate my coding, as you say the user will naturally always go for the CLOSE button.

I will look again at using the CLOSE button.

Kind Regards .. Bill