Verstecktes Fenster durch Shortcut aktivieren

Für allgemeine Fragen zur Programmierung mit PureBasic.
Benutzeravatar
mk-soft
Beiträge: 3855
Registriert: 24.11.2004 13:12
Wohnort: Germany

Re: Verstecktes Fenster durch Shortcut aktivieren

Beitrag von mk-soft »

Habe es auch mal hübsch gemacht ...

Code: Alles auswählen

;-TOP

EnableExplicit

;- Globale Variablen
Global ExitProgram

#WinMain = 0

; ***************************************************************************************

; GlobalHotkeys library
; By Gansta93
; procedure AddHotkey
; Update by mk-soft, v1.01, 08.10.2022

Procedure AddHotkey(Window, fsModifiers, Keys, HotkeyID) ; Create a new global hotkey HotkeyID in specified Window.
  ProcedureReturn RegisterHotKey_(WindowID(Window), HotkeyID, fsModifiers, Keys)
EndProcedure

Procedure RemoveHotkey(Window, HotkeyID) ; Remove Specified HotkeyID in Window.
  ProcedureReturn UnregisterHotKey_(WindowID(Window), HotkeyID)
EndProcedure

; Sample (angepasst an PB4.x)

; ***************************************************************************************

CompilerIf #PB_Compiler_IsMainFile
  
  Enumeration CustomEvent #PB_Event_FirstCustomValue
    #MyEvent_HotKey
  EndEnumeration
  
  Enumeration HotkeyID 1
    #MyHotKeyID_Alt_C
  EndEnumeration
    
  Procedure MyWindowCallback(hWnd, uMsg, wParam, lParam)
    Protected r1
    
    r1 = #PB_ProcessPureBasicEvents
    Select uMsg
      Case #WM_HOTKEY
        PostEvent(#MyEvent_HotKey, 0, 0, 0, wParam)
        
    EndSelect
    
    ProcedureReturn r1
  EndProcedure
  
  Procedure WinMain()
    
    If OpenWindow(#WinMain, #PB_Ignore, #PB_Ignore, 240, 30, "Hotkey v1.1", #PB_Window_ScreenCentered | #PB_Window_TitleBar | #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_Minimize)
      
      If CreateStatusBar(0, WindowID(#WinMain))
        AddStatusBarField(#PB_Ignore)
      Else
        ProcedureReturn
      EndIf
      StatusBarText(0, 0, "Type Alt+C for XXX")
      
      ; Add Hotkey
      If AddHotkey(#WinMain, #MOD_ALT, #VK_C, #MyHotKeyID_Alt_C) = 0
        MessageRequester("Error", "Cannot create hotkey Alt-C.")
        ProcedureReturn
      EndIf
      
      SetWindowCallback(@MyWindowCallback())
      
      Repeat
        Select WaitWindowEvent()
          Case #MyEvent_HotKey
            Select EventData()
              Case #MyHotKeyID_Alt_C
                HideWindow(0, 0)
                SetWindowState(0, #PB_Window_Normal)
                MessageRequester("Info", "Hotkey pressed")
                
            EndSelect
            
          Case #PB_Event_CloseWindow
            ExitProgram = #True
        EndSelect
      Until ExitProgram
      ; Now we remove the hotkeys.
      RemoveHotkey(0, #MyHotKeyID_Alt_C)
      
    EndIf
    
  EndProcedure: WinMain()
  
CompilerEndIf
Alles ist möglich, fragt sich nur wie...
Projekte ThreadToGUI / EventDesigner V3 / OOP-BaseClass-Modul
Downloads auf MyWebspace / OneDrive
mksft98
Beiträge: 4
Registriert: 06.10.2022 17:14

Re: Verstecktes Fenster durch Shortcut aktivieren

Beitrag von mksft98 »

Verstanden. Habe den Code von Hex0r übernommen - dennoch, auch sauber wird das ContainerGadget ohne UpdateWindow nicht dargestellt.
Antworten