The Window Closer X
#1
Hello everyone,  I am using the QB64 for windows compatibility converted all the QB 4.5 to QB64 it has been working for 6 years now.  Anyway one of my users asked me to disable the X on closing the program because they didn't want it to close in the middle of what they were doing so I put in the the command 'ex = _EXIT'.  This works like it states you can't close the program with the X on the window.  Now to kill the program when it freezes they have to kill the process in windows.  Is there a why to use ON KEY to close it?  I have tried ON KEY(1) with a subroutine and GOSUB it will not do the code when I press F1 so somehow the ON KEY is not working for me. I am using QB64 Version 1.1 Revision 20170120/51 does it work in more recent versions and where do I find them now.   Alt + F4 should be what the Window close X button uses I think but maybe I am wrong.   

Is there anyone that may know something to help me or should I leave it the way it is.
Reply
#2
QB64 1.1 is a bit outdated. The latest version is 3.5.0. Maybe that will solve your problem.

https://github.com/QB64-Phoenix-Edition/...tag/v3.5.0
Reply
#3
Hi @Ron welcome to the forum!

This works for me on my Windows 10 laptop:
Code: (Select All)
_Title "Test F4 key to exit" 'b+ 2023-02-08 mod wiki On Key(n) example
Key(4) On ' F1 too important use F4 to quit
On Key(4) GoSub quit
Print "Press F4 to quit!"
temp = _Exit
Do
    Cls
    count = count + 1
    Print count
    _Limit 30 ' <<< really needed to slow down looping
Loop 'never ending loop
End ' just in case no fall through to gosub
quit: ' set to quit when press F4
End
Return

Never used On Key before, looks like you need additional Key(n) On as part of setup. And probably used to deactivate too, ie Key(n) Off

I tested on QB64pe 3.4.1 but see no reason why an earlier version would not work. I did have to slow the looping down with _Limit to catch the Key.

PS oh looky keys for the arrows!
b = b + ...
Reply
#4
When you catch the _EXIT, you can check how they were trying to close it and then use SYSTEM to close. Looking at the Wiki page on _EXIT, the function returns what method the user was using to attempt to close the program. If they pressed the X, you can just ignore it. If you wanted it to close on CTRL + BREAK, like in the example, you could then use SYSTEM when the return value matches.
Ask me about Windows API and maybe some Linux stuff
Reply
#5
(02-08-2023, 06:58 PM)Ron Wrote: Anyway one of my users asked me to disable the X on closing the program because they didn't want it to close in the middle of what they were doing so I put in the the command 'ex = _EXIT'. ...

Welcome to the forums.

I have indicated the sentence of the quotation which is a cause for concern. Writing programs for somebody else, eh? This other person must hate icons and toolbars. The program could close out of a memory leak, hardware problem or power outage, and then I wouldn't want to deal with the reaction to that.

The user could also press [CTRL][ALT][DELETE] "in the middle of what they were doing", IJS. But I'm just babbling and paranoid. Arrow

I'm just curious: could you give away even a little bit what you're trying to do with "_EXIT" and "ON... KEY"? I don't recommend "ON... KEY GOSUB/GOTO" because at keypress it could totally interrupt a critical operation being performed. However it's annoying having to put "KEY() STOP" before that operation, finish the operation and then "KEY() ON".
Reply
#6
(02-08-2023, 07:28 PM)bplus Wrote: Hi @Ron welcome to the forum!

This works for me on my Windows 10 laptop:
Code: (Select All)
_Title "Test F4 key to exit" 'b+ 2023-02-08 mod wiki On Key(n) example
Key(4) On ' F1 too important use F4 to quit
On Key(4) GoSub quit
Print "Press F4 to quit!"
temp = _Exit
Do
    Cls
    count = count + 1
    Print count
    _Limit 30 ' <<< really needed to slow down looping
Loop 'never ending loop
End ' just in case no fall through to gosub
quit: ' set to quit when press F4
End
Return

Never used On Key before, looks like you need additional Key(n) On as part of setup. And probably used to deactivate too, ie Key(n) Off

I tested on QB64pe 3.4.1 but see no reason why an earlier version would not work. I did have to slow the looping down with _Limit to catch the Key.

PS oh looky keys for the arrows!

Thank You bplus did not know you had to turn the key on first will test it out.
Reply
#7
Thank You everyone I got it to recognize F4 and then I ask if they really want to exit and only accept y to exit 

Yes an old program started in the 80s and I started on it in 2017 and brought it over to QB64.  It is 100,000 lines of code but only am touching it when they need to add or change stored in the program variables I told them it is the wrong way to do it started to import from csv files but they don't change too often.  So I maintain while building an order entry system for them in FULLSTACK which was also new for me.  BASIC I USED way back in 1987 then never touched again until 2016.  

Thanks Again all is working or will be working as I expect still testing it.

Ron.
Reply
#8
Simplest form of this is just:
Code: (Select All)
x = _EXIT
DO
    CLS
    PRINT "Alt-F4 to quit and close."
    IF _KEYDOWN(15872) AND (_KEYDOWN(100308) OR _KEYDOWN(100307)) THEN SYSTEM 'Alt-F4
    _LIMIT 30
LOOP
Reply




Users browsing this thread: 8 Guest(s)