Announcement

Collapse
No announcement yet.

Application quitting - what about HotKeys?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Application quitting - what about HotKeys?

    In the DlgProc, my app creates HotKeys:

    Code:
       Select Case CbMsg
    
       Case %wm_initdialog
          '-----------------------------------------------------------------------------------------------
          'set up Hot Keys:
          iRet = Timer
          ReDim nAtom(%HK_Suspend To %HK_Suspend + iNumCmds -1)        
          nAtom(%HK_Suspend) = GlobalAddAtom ("My Hotkeys" + Str$(iRet + %HK_Suspend))  ' iRet makes unique identifier
          RegisterHotKey CbHndl, nAtom(%HK_Suspend), %CTRL, Asc("S")   'CTRL-S    'Suspend
          '
          nAtom(%HK_Resume)  = GlobalAddAtom ("My Hotkeys" + Str$(iRet + %HK_Resume))  
          RegisterHotKey CbHndl, nAtom(%HK_Resume), %CTRL, Asc("R")   'CTRL-R    'Resume
    Should I do anything to destroy the HotKeys before the app terminates?

    Or (like arrays, etc.) do they get cleaned up automatically by PB or Windows, or is this a potential problem?

  • #2
    See doc for GlobalAddAtom:
    Global atoms are not deleted automatically when the application terminates. For every call to the GlobalAddAtom function, there must be a corresponding call to the GlobalDeleteAtom function.
    See doc for RegisterHotKey. That includes a link to the UnRegisterHotKey function. I'll bet you can guess what that one does.

    MCM
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Thanks for that!!!

      OK, so would this be the proper placement? It's in the same DlgProc callback...

      Code:
              Case %wm_destroy
                  For iCount = 1 To iNumCmds
                      UnregisterHotKey CbHndl, nAtom(iCount)
                      GlobalDeleteAtom nAtom(iCount)
                  Next iCount

      Comment


      • #4
        OK, so would this be the proper placement?
        The proper placement is the same for all of these things: When you are done with them, you free, release, close or destroy them.

        If when you receive the WM_DESTROY notification for some window you are done with the hotkeys, then WM_DESTROY sounds like the right place to clean up.

        MCM
        Michael Mattias
        Tal Systems (retired)
        Port Washington WI USA
        [email protected]
        http://www.talsystems.com

        Comment

        Working...
        X