Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Studio Chat / Detecting closing main Window

Author
Message
Creative Magic Man
11
Years of Service
User Offline
Joined: 14th Nov 2012
Location: Frinton On Sea, Essex, UK
Posted: 28th Jul 2020 13:51
Is there a way to detect when you close the main Window on the PC.

Ie. when you click on the cross in the top right hand corner of the Window.

This would make it a more ideal place to save variables and parameters in my App.

Amazing creations start with a Fuzzy Vision
Dave - Creator, Developer and Visionary
Fuzzy Visions
SFSW
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 28th Jul 2020 17:17
Agreed, it's an important option. I've requested it previously: https://forum.thegamecreators.com/thread/224683 and https://github.com/TheGameCreators/AGK-Studio/issues/426

I hope it will someday be added.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
SFSW
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 29th Jul 2020 06:35
Will it be similarly cross-platform as AppGameKit itself is designed to be (including Linux)?
Creative Magic Man
11
Years of Service
User Offline
Joined: 14th Nov 2012
Location: Frinton On Sea, Essex, UK
Posted: 29th Jul 2020 16:21

It is not a major issue with my App, but it would be nice to save parameters etc. when you close it down instead of writing to the folder a few times while it is running.

I have already bothered MadBit a couple of times on his excellent browser plugin so I will leave him alone for a while . . . . well, at the moment, at least!

Thank you for all your feedback.
Amazing creations start with a Fuzzy Vision
Dave - Creator, Developer and Visionary
Fuzzy Visions
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 29th Jul 2020 22:24
You could use MadBit's plugin to remove the title bar and add your own close button
SFSW
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 30th Jul 2020 01:10
Yes, but an internal AppGameKit solution would be much preferred to accommodate default Windows UI controls and no potential plugin dependencies/limitations (ie platform, bit format, runtimes, includes, etc). Just something like 'GetWindowExitState()' to intercept the exit and prompt the user to confirm, save, etc. Then we can just use 'end' to close the app when ready.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 30th Jul 2020 01:15
Very true. I only offer the advice as a "short term" solution
Qugurun
Valued Member
9
Years of Service
User Offline
Joined: 8th Dec 2014
Playing: AppGameKit
Posted: 31st Jul 2020 02:47
Creative Magic Man
11
Years of Service
User Offline
Joined: 14th Nov 2012
Location: Frinton On Sea, Essex, UK
Posted: 31st Jul 2020 22:28
I have used a workaround by creating a small invisible sprite in the top right hand corner of the Window, near the close window cross.

Now you can detect just before a user closes the window as they would be moving the cursor to this location to close the app.

If they move the cursor back into the window ( and not closed down the app ) then all you have done is just saved the current parameters of your program.

Amazing creations start with a Fuzzy Vision
Dave - Creator, Developer and Visionary
Fuzzy Visions
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 31st Jul 2020 23:35
Ha! Very clever
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 1st Aug 2020 01:56
lots of apps have both Exit and Save & Exit options. one perspective is that we have to trust that users knows what they're about to do if they click something. another is to account for "mistakes".

i suppose that's where "confirm" comes into play ("Are you sure you want to quit?" (and "Expert mode")), but i sometimes hit the X intent on nothing being saved when i do.

i guess i've never really thought much about a "proper" exit. hence, my 2 cents (that aren't quite worth that in this case )
[My Itch.io Home]
[CODE lang=AGK] Your Code Here [/CODE]
[VIDEO=youtube] VideoID [/VIDEO]
Creative Magic Man
11
Years of Service
User Offline
Joined: 14th Nov 2012
Location: Frinton On Sea, Essex, UK
Posted: 1st Aug 2020 07:56
Your 2 cents is always appreciated 'Virtual Nomad' and it is good to hear different devs. opinions.

AGK is mainly a game making platform, and many games do not require this feature for their projects. But as Devs' have been using AppGameKit in many different ( none game ) ways it would benefit TGC to have a full set of tools at their disposal if the dev need them.

BTW. . .
That was my 2 cents as well
Amazing creations start with a Fuzzy Vision
Dave - Creator, Developer and Visionary
Fuzzy Visions
Bored of the Rings
User Banned
Posted: 1st Aug 2020 13:23
so for window close, you need to be able to wait for a windows event of 0x10.
Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others
Creative Magic Man
11
Years of Service
User Offline
Joined: 14th Nov 2012
Location: Frinton On Sea, Essex, UK
Posted: 1st Aug 2020 15:26
Can you implement/detect the window event ( 0x10 ) in Tier 1 ?
Amazing creations start with a Fuzzy Vision
Dave - Creator, Developer and Visionary
Fuzzy Visions
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 3rd Aug 2020 06:40
Quote: "Can you implement/detect the window event ( 0x10 ) in Tier 1 ?"


for Windows, this would involve subclassing the window with a user proc and then detect SC_CLOSE in WM_SYSCOMMAND message

for this you would need to expose a bunch of WinAPI commands:
FindWindow
GetWindowThreadProcessId
SetWindowsHookEx

and the following macros:
HIWORD()
LOWORD()

beware that some AV's dont like apps with hooks so you could also go the GWL_WNDPROC route with Set/GetWindowLong (or GetWindowLongPtr for 64 bit)

This is of course assuming a OpenGL window reacts to the same messages as an API window... of this i am not sure and would need some experiments, I'll post back here later

PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 3rd Aug 2020 08:23 Edited at: 3rd Aug 2020 08:33
Here is a small plugin (windows only) that will intercept the close message and allow you to save files or what ever you require.

This small example will allow you to click the close button 3 times before exiting the app


WARNING: once you register the window "WC.Register" you are responsible for closing the window.

Edit: BTW this avoids using hooks, I opted to go with SetWindowLongPtr with GWLP_WNDPROC so this should keeps AV's happy.

Attachments

Login to view attachments
Sph!nx
15
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 3rd Aug 2020 14:59
Very nice! Thanks for sharing.
Regards Sph!nx
SFSW
21
Years of Service
User Offline
Joined: 9th Oct 2002
Location:
Posted: 3rd Aug 2020 17:24
Very nice indeed, viable solution for Windows in the meantime until hopefully AppGameKit can have an option implemented internally. Are the DLL's compiled statically to avoid runtime dependencies?
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 3rd Aug 2020 17:53
Quote: "Are the DLL's compiled statically to avoid runtime dependencies?"


Yes PureBasic is statically linked to the API so no dependencies.
Creative Magic Man
11
Years of Service
User Offline
Joined: 14th Nov 2012
Location: Frinton On Sea, Essex, UK
Posted: 3rd Aug 2020 20:32
Thank you very much 'PartTimeCoder'.

I shall add this to my App later.

Amazing creations start with a Fuzzy Vision
Dave - Creator, Developer and Visionary
Fuzzy Visions
Creative Magic Man
11
Years of Service
User Offline
Joined: 14th Nov 2012
Location: Frinton On Sea, Essex, UK
Posted: 26th Oct 2020 15:03
Where is the actual Windows plugin to download 'PartTimeCoder' ?
Amazing creations start with a Fuzzy Vision
Dave - Creator, Developer and Visionary
Fuzzy Visions
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 28th Oct 2020 21:38
Quote: "Where is the actual Windows plugin?"

attached to PTCs 08/03 post?
[My Itch.io Home] [#LowRezJamAGK2020]
[AGK Resource Directory] [TGC @ GitHub]
[CODE lang=AGK] YOUR CODE HERE [/CODE]
[VIDEO=youtube] VIDEO ID [/VIDEO]
[Google Forum Search]
Creative Magic Man
11
Years of Service
User Offline
Joined: 14th Nov 2012
Location: Frinton On Sea, Essex, UK
Posted: 28th Oct 2020 23:53
Sorry about that. I missed it. I was just looking only at the code.

This is what all this coding does to you!

Must get out more often and . . . oh darn, can't do that either in these times.

Thanks again.
Amazing creations start with a Fuzzy Vision
Dave - Creator, Developer and Visionary
Fuzzy Visions

Login to post a reply

Server time is: 2024-03-29 00:32:27
Your offset time is: 2024-03-29 00:32:27