Window Min, Max & Close Buttons An- & Ausschalten

Hier könnt Ihr gute, von Euch geschriebene Codes posten. Sie müssen auf jeden Fall funktionieren und sollten möglichst effizient, elegant und beispielhaft oder einfach nur cool sein.
Benutzeravatar
nco2k
Beiträge: 892
Registriert: 08.09.2004 23:13

Window Min, Max & Close Buttons An- & Ausschalten

Beitrag von nco2k »

hi folks,

hab grad sowas gesucht, aber irgendwie nicht gefunden. also habe ich auf msdn geschaut und es selbst gecodet.

ich hoffe, dass es für den einen oder anderen, nützlich ist.

Code: Alles auswählen

Procedure SetWindowMinButton(hWnd.l, Show.l)
  If (Show = #True Or Show = #False) And hWnd
    nWindowLong.l = GetWindowLong_(hWnd, #GWL_STYLE)
    If nWindowLong
      If Show = #True
        SetWindowLong_(hWnd, #GWL_STYLE, nWindowLong | #WS_MINIMIZEBOX)
      ElseIf Show = #False
        SetWindowLong_(hWnd, #GWL_STYLE, nWindowLong & (#WS_MINIMIZEBOX ! - 1))
      EndIf
      SetWindowPos_(hWnd, 0, 0, 0, 0, 0, #SWP_NOZORDER | #SWP_NOMOVE | #SWP_NOSIZE | #SWP_FRAMECHANGED)
    EndIf
  EndIf
EndProcedure

Procedure SetWindowMaxButton(hWnd.l, Show.l)
  If (Show = #True Or Show = #False) And hWnd
    nWindowLong.l = GetWindowLong_(hWnd, #GWL_STYLE)
    If nWindowLong
      If Show = #True
        SetWindowLong_(hWnd, #GWL_STYLE, nWindowLong | #WS_MAXIMIZEBOX)
      ElseIf Show = #False
        SetWindowLong_(hWnd, #GWL_STYLE, nWindowLong & (#WS_MAXIMIZEBOX ! - 1))
      EndIf
      SetWindowPos_(hWnd, 0, 0, 0, 0, 0, #SWP_NOZORDER | #SWP_NOMOVE | #SWP_NOSIZE | #SWP_FRAMECHANGED)
    EndIf
  EndIf
EndProcedure

Procedure SetWindowCloseButton(hWnd.l, Show.l)
  If (Show = #True Or Show = #False) And hWnd
    hSysMenu = GetSystemMenu_(hWnd, #False)
    If hSysMenu
      EnableMenuItem_(hSysMenu, #SC_CLOSE, #MF_BYCOMMAND | Show ! 1)
      DrawMenuBar_(hWnd)
    EndIf
  EndIf
EndProcedure

Enumeration
  #GadgetButton_DisableMinBox
  #GadgetButton_DisableMaxBox
  #GadgetButton_DisableCloseBox
  #GadgetButton_Exit
EndEnumeration

If OpenWindow(0, 0, 0, 200, 145, "Disable Window Close Box - Example", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_ScreenCentered)
  If CreateGadgetList(WindowID(0))
    ButtonGadget(#GadgetButton_DisableMinBox, 5, 5, 190, 25, "Disable Minimize Box", #PB_Button_Toggle)
    ButtonGadget(#GadgetButton_DisableMaxBox, 5, 35, 190, 25, "Disable Maximize Box", #PB_Button_Toggle)
    ButtonGadget(#GadgetButton_DisableCloseBox, 5, 65, 190, 25, "Disable Close Box", #PB_Button_Toggle)
    ButtonGadget(#GadgetButton_Exit, 5, 115, 190, 25, "Exit")
    AddKeyboardShortcut(0, #PB_Shortcut_Alt | #PB_Shortcut_F4, 0)
    AddKeyboardShortcut(0, #PB_Shortcut_Escape, 0)
    
    Repeat
      WinEvent.l = WaitWindowEvent()
      If WinEvent = #PB_Event_Gadget
        Select EventGadget()
          Case #GadgetButton_DisableMinBox
            SetWindowMinButton(WindowID(0), GetGadgetState(#GadgetButton_DisableMinBox) ! 1)
          Case #GadgetButton_DisableMaxBox
            SetWindowMaxButton(WindowID(0), GetGadgetState(#GadgetButton_DisableMaxBox) ! 1)
          Case #GadgetButton_DisableCloseBox
            SetWindowCloseButton(WindowID(0), GetGadgetState(#GadgetButton_DisableCloseBox) ! 1)
          Case #GadgetButton_Exit
            If GetGadgetState(#GadgetButton_DisableCloseBox) = 0
              End
            EndIf
        EndSelect
      ElseIf WinEvent = #PB_Event_Menu And EventMenu() = 0
        If GetGadgetState(#GadgetButton_DisableCloseBox) = 0
          End
        EndIf
      EndIf
    Until WinEvent = #PB_Event_CloseWindow
    
  EndIf
EndIf

End
have fun. <)

edit 3: für pb4.00 angepasst.

c ya,
nco2k
Zuletzt geändert von nco2k am 23.06.2006 07:02, insgesamt 3-mal geändert.
~|__/
..o.o.. <--- This is Einkaufswagen. Copy Einkaufswagen into your signature to help him on his way to world domination.
Benutzeravatar
NicTheQuick
Ein Admin
Beiträge: 8807
Registriert: 29.08.2004 20:20
Computerausstattung: Ryzen 7 5800X, 64 GB DDR4-3200
Ubuntu 24.04.2 LTS
GeForce RTX 3080 Ti
Wohnort: Saarbrücken

Beitrag von NicTheQuick »

Das gibts glaube ich auch schon bei den PBOSL in einer Lib von Danilo.

Aber trotzdem nützlich. :allright:
Benutzeravatar
nco2k
Beiträge: 892
Registriert: 08.09.2004 23:13

Beitrag von nco2k »

> Das gibts glaube ich auch schon bei den PBOSL in einer Lib von Danilo.
in PBOSL konnte ich nur ShowClosebutton() finden, was aber afaik das sysmenu komplett entfernt und somit alle buttons:

Code: Alles auswählen

If OpenWindow(0, 0, 0, 300, 300, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_ScreenCentered, "test")
  
  ShowCloseButton(WindowID(0), #False)
  
  While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend
  
EndIf

End
ich glaub danilos funktion macht das gleiche wie:

Code: Alles auswählen

hWnd.l = OpenWindow(0, 0, 0, 300, 300, #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_ScreenCentered | #PB_Window_SystemMenu, "Example")
If hWnd
  
  SetWindowLong_(hWnd, #GWL_STYLE, GetWindowLong_(hWnd, #GWL_STYLE) & (#WS_SYSMENU ! - 1))
  SetWindowPos_(hWnd, 0, 0, 0, 0, 0, #SWP_NOZORDER | #SWP_NOMOVE | #SWP_NOSIZE | #SWP_FRAMECHANGED)
  
  While WaitWindowEvent() <> #PB_Event_CloseWindow : Wend
  
EndIf
worüber ich mich ein wenig geärgert hab und deswegen eine eigene variante gecodet hab. :)

> Aber trotzdem nützlich. :allright:
danke, freut mich. :)

c ya,
nco2k
~|__/
..o.o.. <--- This is Einkaufswagen. Copy Einkaufswagen into your signature to help him on his way to world domination.
Benutzeravatar
Knight_Rider_2000
Beiträge: 145
Registriert: 05.02.2007 20:46
Kontaktdaten:

Beitrag von Knight_Rider_2000 »

Danke ihr wart wieder mir eine große Hilfe
PB 4.20,Blitz3D 1.98,Microsoft Visual Studio 2005 Professional, Microsoft Visual Studio 2008 Professional
Antworten