Hi Brian,
it should be as easy as calling:
Let us know!Dialog End CBHNDL
Petr
I searched the example files, the offline help file, and the forums, and I couldn't find an answer to something that seems like it should be really easy:
How do you close a dialog window from within your dialog callback?
For example, if you want to detect that the user has pressed the escape key, and shut the program down when they do that, how do you get the window to close?
I set up a timer in my dialog window callback like so:
and I try to send myself a %WM_CLOSE event, but this causes the app to crash when I hit escape.Case %WM_TIMER If GetAsyncKeyState(%VK_ESCAPE) Then Dialog Send CBHNDL, %WM_CLOSE, 0, 0 End If
Clicking on the close box, and having my normal %WM_CLOSE code run works perfectly.
Any ideas? This has got to be simple, but I just couldn't find any examples of it.
*Brian
Hi Brian,
it should be as easy as calling:
Let us know!Dialog End CBHNDL
Petr
Learn 3D graphics with ThinBASIC, learn TBGL!
Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB
Yes! That works perfectly. Previously I tried Dialog End hDlg, where hDlg was the dialog window's handle, and that crashed my application.
*Brian
Consider using GetWindowKeyState: http://www.thinbasic.com/public/prod...owkeystate.htm
GetAsyncKeyState(%VK_ESCAPE) will return %TRUE even when your window is not the current one, so if you put your window in the background under other windows and press ESC, you window will always receive the state of the ESC key.
Instead GetWindowKeyState(CBHNDL, %VK_ESCAPE) will return %TRUE when ESC is pressed but only if your window is the actual foreground window.
... Case %WM_TIMER If GetWindowKeyState(CBHNDL, %VK_ESCAPE) Then Dialog End CBHNDL End If ...
Last edited by ErosOlmi; 30-09-2015 at 07:36.
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Hi Eros,
Is there a performance hit trying to deal with the Windows message que using an on the fly interpreter?
With Script BASIC I let IUP take on the job.
Ciao John,
so far I would say no problem but of course it depends on what you need to do with a script.
Dealing with window messages is always a challenge. Even compiled applications sometimes lose some message
Important is not to insert long operations in respond to a message otherwise your application seems blocked.
Messages are queued by windows and unless your operation is very long ... you always get messages from the queue without missing any of them.
One way to do long jobs in response to a message is to let different threads do the work but thinBasic is still not multi threads, maybe future versions.
In any case, usually there are many ways to achieve the same operations, sometimes a little optimization, some tricks or a native compiled functions inside thinBasic can solve the problem. That's why thinBasic has some many native commands: because they are compiled in the language and when used they are fast.
That said, I would never use thinBasic to loop for all pixels of a multi megapixel image in order to make some image transformation on the fly. That's not a work for an interpreted language.
In that case I would develop a thinBasic compiled module with some native functions that do the job.
Ciao
Eros
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Thanks Eros for the insight into the Windows message loop.
I filter out mouse movement messages at the C extension module level which helps. Having IUP doing much of the GUI low level work allows me to focus more on the original task.
Bookmarks