Announcement

Collapse

Forum Guidelines

This forum is for finished source code that is working properly. If you have questions about this or any other source code, please post it in one of the Discussion Forums, not here.
See more
See less

Hotkey

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

  • Hotkey

    Global "hotkey" could be useful in utilities.
    In this sample, when you press Alt-F10 in any app, your dialog receives this message and is able to do what it wants.
    You have 3 sec to close a dialog by Alt-F4.
    Of course, you can registrate any other key.

    Code:
       #Compile Exe
       #Register None
       #Dim All
       #Include "Win32Api.Inc"
       %ID_Text = 201
    
       CallBack Function DlgProc
          Static nAtom As Dword
          Select Case CbMsg
             Case %WM_INITDIALOG
                nAtom = GlobalAddAtom ("My Hotkey" + Str$(Timer))
                RegisterHotKey CbHndl, nAtom, 1, %VK_F10 ' Alt-F10
                SetTimer CbHndl, 1, 5000, ByVal 0
             Case %WM_DESTROY
                UnregisterHotKey CbHndl, nAtom
                GlobalDeleteAtom nAtom
             Case %WM_HOTKEY
                ShowWindow CbHndl, 1
                SetTimer CbHndl, 1, 3000, ByVal 0
                '  CbWparam = nAtom
                Control Set Text CbHndl, %ID_TEXT, "Alt-F10 pressed at " + Time$
             Case %WM_TIMER
                KillTimer CbHndl, 1
                ShowWindow CbHndl, 0
          End Select
       End Function
    
       Function PbMain
          Local hDlg As Long
          Dialog New 0, "HotKey (Alt-F10)",,, 300, 40, %WS_SYSMENU, _
             %WS_EX_TOPMOST Or %WS_EX_TOOLWINDOW To hDlg
          Control Add Label, hDlg, %ID_Text, "Press Alt-F10 in another apps or Close this dialog", _
             5, 10, 290, 15, %SS_CENTER
          Dialog Show Modal hDlg Call DlgProc
       End Function

  • #2
    Semen,
    I think GlobalAddAtom returns a WORD not a DWORD.

    James




    ------------------

    Comment


    • #3
      James --
      In Win32Api.Inc
      Code:
      DECLARE FUNCTION GlobalAddAtom LIB "KERNEL32.DLL" ALIAS "GlobalAddAtomA" (lpString AS ASCIIZ) AS LONG
      DECLARE FUNCTION GlobalDeleteAtom LIB "KERNEL32.DLL" ALIAS "GlobalDeleteAtom" (BYVAL nAtom AS LONG) AS LONG
      but I agree with you (Win32.Hlp).

      From another side, DWORD instead of WORD doesn't bring troubles (unlike WORD instead of DWORD/LONG)

      ------------------

      Comment


      • #4
        It returns a DWORD, but the value is limited to the range of a WORD.


        ------------------
        Lance
        PowerBASIC Support
        mailto:[email protected][email protected]</A>
        Lance
        mailto:[email protected]

        Comment

        Working...
        X