Results 1 to 7 of 7

Thread: How to close dialog box from within callback

  1. #1

    How to close dialog box from within callback

    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:
        Case %WM_TIMER
          If GetAsyncKeyState(%VK_ESCAPE) Then
            Dialog Send CBHNDL, %WM_CLOSE, 0, 0
          End If
    
    and I try to send myself a %WM_CLOSE event, but this causes the app to crash when I hit escape.

    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

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732
    Hi Brian,

    it should be as easy as calling:
    Dialog End CBHNDL
    
    Let us know!


    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

  3. #3
    Yes! That works perfectly. Previously I tried Dialog End hDlg, where hDlg was the dialog window's handle, and that crashed my application.

    *Brian

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    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

  5. #5
    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.
    ScriptBasic Project Manager
    Project Site
    support@scriptbasic.org

  6. #6
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    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

  7. #7
    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.
    ScriptBasic Project Manager
    Project Site
    support@scriptbasic.org

Similar Threads

  1. COM Callback
    By steinie in forum COM
    Replies: 1
    Last Post: 11-09-2011, 10:32
  2. close one dialog from another one and back
    By Lionheart008 in forum UI (User Interface)
    Replies: 0
    Last Post: 12-03-2010, 21:17
  3. close dialog from second dialog
    By Lionheart008 in forum thinBasic General
    Replies: 0
    Last Post: 05-11-2009, 21:26
  4. Confusion with DIALOG GET/SET CLIENT, DESKTOP GET SIZE and DIALOG SET LOC
    By Michael Hartlef in forum UI (User Interface)
    Replies: 3
    Last Post: 03-10-2008, 19:23

Members who have read this thread: 1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •