Show/Hide menu in WindowedScreen

Just starting out? Need help? Post your questions and find answers here.
User avatar
Otrebor
Enthusiast
Enthusiast
Posts: 198
Joined: Mon Mar 17, 2014 1:42 pm
Location: São Paulo, Brasil
Contact:

Show/Hide menu in WindowedScreen

Post by Otrebor »

Hi
When my program switches to fullscreen (windowed), its hide the menu until the mouse is moved.
i would like to know if is possible to avoid the moving of window while the menu show/hide? Or minimize the effect...
I found that with -1 in Y parameter of windowedScreen the effect is minimized (at least on my computer).

Here a very simple code to demonstrate:

Code: Select all

Procedure Init_Vars()
  Global fullscreen,screenh,screenw
  
  hWndM = OpenWindow(0,0,0,640,500,"Example",#PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_MinimizeGadget)
  CanvasGadget(0, 0, 0, 640, 480)
                
  InitSprite()

  If ExamineScreenModes()
    While NextScreenMode()
      If ScreenModeWidth()=640 And ScreenModeHeight()=480 
        ScreenW=ScreenModeWidth():ScreenH=ScreenModeHeight()
        Break
      EndIf
    Wend
  EndIf
  
  AddKeyboardShortcut(0, #PB_Shortcut_F4, 10)
  CreateMenu(0,WindowID(0))
  MenuTitle("File")
  MenuItem(10,"FullScreen")
  MenuItem(20,"Quit")
  
  
EndProcedure
Procedure menutime(*THREAD)
  Shared tmenu
  
  tmenu=2
  Delay(3000) 
  tmenu=1 
 
EndProcedure
Procedure menu()
  Shared threadmenu
 
  Event=WindowEvent()
  If Event= #PB_Event_Menu
    If EventMenu()=10 
      If Not fullscreen
        fullscreen=1
        StopDrawing()
        FreeGadget(0)
        SetMenuItemState(0,10,1)
        OpenWindowedScreen(WindowID(0),0,-1,screenw,screenh,1,0,0,#PB_Screen_NoSynchronization)
        StartDrawing(ScreenOutput())
        SetWindowLongPtr_(WindowID(0), #GWL_STYLE, GetWindowLongPtr_(WindowID(0), #GWL_STYLE)&~ #WS_THICKFRAME &~ #WS_DLGFRAME)
        threadmenu=CreateThread(@menutime(),0)
        SetWindowState(0,#PB_Window_Maximize)
      Else
        fullscreen=0
        HideMenu(0,0)
        StopDrawing()
        SetMenuItemState(0,10,0)
        SetWindowLongPtr_(WindowID(0), #GWL_STYLE, GetWindowLongPtr_(WindowID(0), #GWL_STYLE) |#WS_DLGFRAME)
        SetWindowState(0,#PB_Window_Normal)
        CanvasGadget(0, 0, 0, 640, 480)
      EndIf
    EndIf
  ElseIf EventMenu()=20
    End
  EndIf 
  
EndProcedure
Procedure events(hWndM, uMsg, wParam, lParam)
  Shared moux,mouy,fullscreen,tmenu,threadmenu
  
  
  result = #PB_ProcessPureBasicEvents 
  Select uMsg 
      
    Case #WM_NCCALCSIZE 
      If fullscreen
        Debug "changed"
      EndIf  
      
    Case #WM_MOUSEMOVE 
       If fullscreen
        CursorInfo.POINT
        GetCursorPos_(CursorInfo) 
        If tmenu=0 And (CursorInfo\x <> moux And CursorInfo\y > 19)               
          threadmenu=CreateThread(@menutime(),0)
          moux=CursorInfo\x 
          HideMenu(0,0)
        ElseIf CursorInfo\y < 19 And CursorInfo\y <> mouy
          SetCursorPos_(CursorInfo\x,20)
          mouy=CursorInfo\y
          moux=CursorInfo\x
        ElseIf tmenu > 0
          If IsThread(threadmenu):KillThread(threadmenu):EndIf
          threadmenu=CreateThread(@menutime(),0)
          moux=CursorInfo\x        
        EndIf
      EndIf
      
    Case #WM_CLOSE
      End
      
  EndSelect
  
  ProcedureReturn result 
  
EndProcedure
Procedure menus()
  Shared tmenu
  
  If fullscreen =0
    StopDrawing()
    StartDrawing(CanvasOutput(0))
    Box(0,0,640,480,RGB(0,0,125))
    DrawText(300,190,"CANVAS")
    DrawText(280,210,"F4 Fullscreen")
    menu()
  Else
    StopDrawing()
    FlipBuffers()
    menu()
    If tmenu=1
      HideMenu(0,1)
      tmenu=0
    EndIf
    StartDrawing(ScreenOutput())
    Box(0,0,640,480,RGB(125,0,0))
    DrawText(280,100,"SCREEN")
    DrawText(270,120,"WINDOWED")
  EndIf

  ;...
EndProcedure
  
Init_Vars()
SetWindowCallback(@events())
Repeat  
  Delay(10)
  menus()
ForEver
 


User avatar
Otrebor
Enthusiast
Enthusiast
Posts: 198
Joined: Mon Mar 17, 2014 1:42 pm
Location: São Paulo, Brasil
Contact:

Re: Show/Hide menu in WindowedScreen

Post by Otrebor »

I found this code and did some modification:

Code: Select all

#Window = 0


Procedure CreateMenuEx(ID.l, WindowID.l, Position.l)
   Shared NewWindow  
  
  ; ID = Numéro du menu
  ; WindowID = fenêtre associé au menu
  ; Position = Position du menu sur la fenêtre
  ; si -1 : menu en bas de la fenêtre
  ; si x > 0 : menu décalé de x pixel du haut de la fenêtre

  x = WindowWidth(0)
  If Position = -1
    Position = WindowHeight(0) - MenuHeight()
  EndIf
 
  NewWindow = OpenWindow(#PB_Any, 0, 60, 199, 20, "Menu", #PB_Window_BorderLess)
  Resultat = CreateMenu(ID, WindowID(NewWindow))
 
  SetWindowLong_(WindowID(NewWindow), #GWL_STYLE, GetWindowLong_(WindowID(NewWindow), #GWL_STYLE) | #WS_CHILD | #WS_CLIPCHILDREN)
  SetParent_(WindowID(NewWindow), WindowID(WindowID))
 
  ProcedureReturn Resultat
EndProcedure

Procedure CloseMenuEx(WindowID)
  ;UseWindow(WindowID)
  UseGadgetList(WindowID(WindowID))
EndProcedure


Procedure time(*TH)
  Shared NewWindow
  
  Delay (5000)
  CloseWindow_(NewWindow)
  
EndProcedure





OpenWindow(#Window, 0, 0, 200, 200, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #WS_CLIPCHILDREN)
; ne pas oublier de mettre la constante #WS_CLIPCHILDREN dans les paramètre de la fenêtre

SetWindowLongPtr_(WindowID(0), #GWL_STYLE, GetWindowLongPtr_(WindowID(0), #GWL_STYLE)&~ #WS_THICKFRAME &~ #WS_DLGFRAME)
SetWindowColor(0,RGB(100,100,150))

If CreateMenuEx(0, #Window, 0)
  MenuTitle("Fichier")
  MenuItem(0, "Quitter")
  CloseMenuEx(#Window) ; On ferme le menu
EndIf

CreateThread(@time(), 0)

Repeat
  Event = WaitWindowEvent()
 
  If Event = #PB_Event_Menu
    Select EventMenu() ; menu et barre d'outils
      Case 0
        Event = #PB_Event_CloseWindow
    EndSelect
  EndIf
 
Until Event = #PB_Event_CloseWindow
I would like to know if is possible to close the window where the menu is located?
Thanks!
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: Show/Hide menu in WindowedScreen

Post by RASHAD »

Escape to close

Code: Select all

#Window = 0


Procedure CreateMenuEx(ID.l, WindowID.l, Position.l)
   Shared NewWindow  
  
  ; ID = Numéro du menu
  ; WindowID = fenêtre associé au menu
  ; Position = Position du menu sur la fenêtre
  ; si -1 : menu en bas de la fenêtre
  ; si x > 0 : menu décalé de x pixel du haut de la fenêtre

  x = WindowWidth(0)
  If Position = -1
    Position = WindowHeight(0) - MenuHeight()
  EndIf
 
  NewWindow = OpenWindow(#PB_Any, 0, 60, 199, 20, "Menu", #PB_Window_BorderLess)
  Resultat = CreateMenu(ID, WindowID(NewWindow))
 
  SetWindowLong_(WindowID(NewWindow), #GWL_STYLE, GetWindowLong_(WindowID(NewWindow), #GWL_STYLE) | #WS_CHILD | #WS_CLIPCHILDREN)
  SetParent_(WindowID(NewWindow), WindowID(WindowID))
 
  ProcedureReturn Resultat
EndProcedure

Procedure CloseMenuEx(WindowID)
  ;UseWindow(WindowID)
  UseGadgetList(WindowID(WindowID))
EndProcedure


Procedure time(*TH)
  Shared NewWindow
  
  Delay (5000)
  CloseWindow_(NewWindow)
  
EndProcedure


OpenWindow(#Window, 0, 0, 200, 200, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #WS_CLIPCHILDREN)
; ne pas oublier de mettre la constante #WS_CLIPCHILDREN dans les paramètre de la fenêtre

SetWindowLongPtr_(WindowID(0), #GWL_STYLE, GetWindowLongPtr_(WindowID(0), #GWL_STYLE)&~ #WS_THICKFRAME &~ #WS_DLGFRAME)
SetWindowColor(0,RGB(100,100,150))

If CreateMenuEx(0, #Window, 0)
  MenuTitle("Fichier")
  MenuItem(0, "Quitter")
  CloseMenuEx(#Window) ; On ferme le menu
EndIf

thread = CreateThread(@time(), 0)
Repeat
  Select WaitWindowEvent()  
  Case #WM_KEYDOWN
    If EventwParam() = 27
      If IsThread(thread)
        KillThread(thread)
        Quit = 1
      EndIf
    EndIf
 
  Case #PB_Event_Menu
    Select EventMenu() ; menu et barre d'outils
      Case 0
    EndSelect
  EndSelect
 
Until Quit = 1
Egypt my love
User avatar
Otrebor
Enthusiast
Enthusiast
Posts: 198
Joined: Mon Mar 17, 2014 1:42 pm
Location: São Paulo, Brasil
Contact:

Re: Show/Hide menu in WindowedScreen

Post by Otrebor »

Thank you, RASHAD!

I wasn't very clear in my question...I want to know if is possible to close the window where the menu is located, but keep opened the window (0).
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4636
Joined: Sun Apr 12, 2009 6:27 am

Re: Show/Hide menu in WindowedScreen

Post by RASHAD »

Change

Code: Select all

Global NewWindow
.
.
.
Case #WM_KEYDOWN
  If EventwParam() = 27
    SetParent_(WindowID(NewWindow),0)
    CloseWindow(NewWindow)
  EndIf
Egypt my love
User avatar
Otrebor
Enthusiast
Enthusiast
Posts: 198
Joined: Mon Mar 17, 2014 1:42 pm
Location: São Paulo, Brasil
Contact:

Re: Show/Hide menu in WindowedScreen

Post by Otrebor »

Thanks!
Post Reply