Seite 1 von 1

Window Min, Max & Close Buttons An- & Ausschalten

Verfasst: 20.01.2006 09:50
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

Verfasst: 20.01.2006 11:18
von NicTheQuick
Das gibts glaube ich auch schon bei den PBOSL in einer Lib von Danilo.

Aber trotzdem nützlich. :allright:

Verfasst: 20.01.2006 11:34
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

Verfasst: 06.04.2007 21:03
von Knight_Rider_2000
Danke ihr wart wieder mir eine große Hilfe