View Full Version : Cancel TBGL_Window-closebutton?
ReneMiner
30-11-2015, 14:01
Is it possible to avoid closing the TBGL-Window via the System-Window-Close-Button ("X", up-right, red mostly if you point it)
I want to ask my user, if he wants to save on exit ("Yes|No|Cancel")
- but in case he closes the window using the system-close-button, i can only offer "Yes|No" currently
(in some "lost-on-screen, small" msgbox that can be easily overseen because it has no parent...)
since the window is closed and resources (as Fonts & Textures) are released already.
Can i trap this?
From visual basic i know there will be raised an event
simplified example:
Sub myWindow_Close(ByRef Cancel As Boolean)
' if the user sets:
Cancel = TRUE
' within this sub then
' window won't close
End Sub
can we bind something as this:
TBGL_BindWindowEvent( hWnd, %TBGL_OnWindowClose, "myWindow_Close")
???
ErosOlmi
30-11-2015, 15:09
Usually the way to prevent closing in User Interface scripts (and standard Windows) is to use this method:
http://www.thinbasic.com/community/showthread.php?9299-How-to-prevent-Dialog-from-closing-before-confirmation&p=70172#post70172
I do not know in TBGL Windows.
Petr Schreiber
30-11-2015, 19:57
Hi Rene,
I think the easiest approach would be to eliminate the close box, if you don't want it.
Instead of:
%TBGL_WS_WINDOWED | %TBGL_WS_CLOSEBOX | %TBGL_WS_DONTKEEPASPECTRATIO
...use just:
%TBGL_WS_WINDOWED | %TBGL_WS_DONTKEEPASPECTRATIO
Another alternative would be embedding the TBGL into ThinBASIC dialog - then you can handle all events you need.
Petr
Petr Schreiber
30-11-2015, 22:42
Binding the close event is technically possible. I am just scratching my head whether to go this route or not.
I would not like to end up duplicating the UI stuff we already have in... UI module. Let me think about it!
Petr
ReneMiner
01-12-2015, 12:35
TBGL works windowed too - not limited to fullscreen only.
So we should be able to react if the render-surface is about to disappear and to make sure the user really wants this before all resources are destroyed - or should we just rigorous create them again?
I would not like have to port all stuff to a canvas - to rewrite all the input and to enlarge the final bundle about the size of UI-module for just this - since it's my intention not have to Uses "UI" nor Callbacks and the reason to create own controls only using TBGL_Rect & TBGL_PrintFont2d. Later I will add rendering quads and some simple to use texture-handling (mostly loading of many different file-formats) for some textured controls. Then the re-creation could become a little more effort.
Still there's no window but just the small, easy to oversee msgbox that keeps the script running.
I try to avoid to Declare external Subs & Functions as much as possible- so I'm already really happy about TBGL_PushLogicOp.
But in case there were a possibility to use some win32-function that allows to cancel the window closing then i would prefer it over Uses "UI".
ErosOlmi
01-12-2015, 13:29
I think Petr was referring not to transform into a Canvass (too much work) but to have a TBGL control over a standard UI Window (TBGL_BindCanvas) in order to let the Window to handle non TBGL events in a callback.
The rest would be handled as usual in TBGL.
An example in C:\thinBasic\SampleScripts\TBGL\EntityBased\TBGL_Control_Targeting_GettingInfo.tbasic
Ciao
Eros
Petr Schreiber
01-12-2015, 21:23
Eros got it exactly as I mentioned - on the other side I understand Rene's avoidance of multi-module scripts.
I will have a look during weekend, I think I should be able to achieve what is needed :)
Petr