Window Menu Grief

Just starting out? Need help? Post your questions and find answers here.
calypso
User
User
Posts: 17
Joined: Sun Mar 26, 2023 7:23 am
Location: Vancouver BC Canada

Window Menu Grief

Post by calypso »

I am at wits end - if that means anything to those from the late 70s to early 80's.
I have been trying to find how to only close a 2nd window (about) by left click on the X but it always exits the program for the various ways I have tried.

I have a program with a menu, the menu has "File" which when clicked on shows a sub-menu with "About", a separator line, and "Exit".
the "Exit" obviously exits the program, as does clicking on the X on the main form.

When selecting the "About" a second window is opened and displays an image. Then when clicking on the X of the About window the program exits instead of just closing the About window. I need to be able to click on the About window X and have it only close the About window.

I have been trying to get this to work for 3 days (not 24hrs/day) now and have gotten nowhere. I can't get a grasp of how the event loop deals with menu items.

My current portion of code is below. This is the last issue I need to resolve with the program I am working on. Everything else is working fine.

Any help is appreciated

Code: Select all

Repeat
    EventID  =WaitWindowEvent()
    MenuID   =EventMenu()
    GadgetID =EventGadget()
    WindowID =EventWindow()

    Select EventID
      Case #PB_Event_CloseWindow                                    ;close window event
        Select WindowID
          Case #Window_Launch_VNC_Form1
            quitLaunch_VNC_Form1=1
        EndSelect
    EndSelect
    
    Select MenuID  
      Case #PB_Event_Menu                                           ;menu item Exit
        Case #MenuBar_Launch_VNC_Form1_Exit
          Select EventType()
            Case #PB_EventType_LeftClick
              QuitLaunch_VNC_Form1=1                
          EndSelect

        Case #MenuBar_Launch_VNC_Form1_About
          Select EventType()
            Case #PB_EventType_LeftClick
              LoadImage(0,"D:\basic\arcsver\About2.bmp",0)                                                  ;load "About" image
              OpenWindow(#Window2, 470, 300, 378, 237, "About Some Program", #PB_Window_SystemMenu)    ;open new "About" window
              ContainerGadget(#AboutContainer, 0, 0, 378, 237)                                              ;create container gadget
              SetBackgroundImage(#AboutContainer, 0)                                                        ;call procedure to show image in window
          EndSelect  
          
        Case #MenuBar_Launch_VNC_Form1_About
          Select EventType()
            Case #PB_Event_CloseWindow
              CloseWindow(#Window2)
          EndSelect    
    EndSelect     
       
    Select GadgetID 
        Case #PB_Event_Gadget
          Case #Gadget_Launch_VNC_Form1_Image_1
            Select EventType()
              Case #PB_EventType_LeftClick
              Default
            EndSelect
  ;
  ; a lot of (90) Button Gadget code is not shown here as it is not necessary for debugging 
  ;
 Until quitLaunch_VNC_Form1                                  ;end of repeat until
      CloseWindow(#Window_Launch_VNC_Form1) 
 
User avatar
mk-soft
Always Here
Always Here
Posts: 6202
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Window Menu Grief

Post by mk-soft »

The event was requested at the wrong point.
Since your code is not complete ...

Actually, you can get by without additional variables for the events. Just a tip.

Template

Code: Select all

;-TOP

#ProgramTitle = "Main Window"
#ProgramVersion = "v1.01.2"

Enumeration Windows
  #Main
  #FormAbout
EndEnumeration

Enumeration MenuBar
  #MainMenu
EndEnumeration

Enumeration MenuItems
  #MainMenuAbout
  #MainMenuExit
EndEnumeration

Enumeration Gadgets
  
EndEnumeration

Enumeration StatusBar
  #MainStatusBar
EndEnumeration

; ----

Procedure OpenFormAbout()
  If OpenWindow(#FormAbout, #PB_Ignore, #PB_Ignore, 300, 200, "About", #PB_Window_SystemMenu, WindowID(#Main))
    ;
  EndIf
EndProcedure

; ----

Procedure UpdateWindow()
  Protected dx, dy
  dx = WindowWidth(#Main)
  dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
  ; Resize gadgets
EndProcedure

Procedure Main()
  Protected dx, dy
  
  #MainStyle = #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_MaximizeGadget | #PB_Window_MinimizeGadget
  
  If OpenWindow(#Main, #PB_Ignore, #PB_Ignore, 800, 600, #ProgramTitle , #MainStyle)
    ; Menu
    CreateMenu(#MainMenu, WindowID(#Main))
    MenuTitle("&File")
    CompilerIf #PB_Compiler_OS = #PB_OS_MacOS
      MenuItem(#PB_Menu_About, "")
    CompilerElse
      MenuItem(#MainMenuAbout, "About")
    CompilerEndIf
    ; Menu File Items
    
    CompilerIf Not #PB_Compiler_OS = #PB_OS_MacOS
      MenuBar()
      MenuItem(#MainMenuExit, "E&xit")
    CompilerEndIf
    
    ; StatusBar
    CreateStatusBar(#MainStatusBar, WindowID(#Main))
    AddStatusBarField(#PB_Ignore)
    
    ; Gadgets
    dx = WindowWidth(#Main)
    dy = WindowHeight(#Main) - StatusBarHeight(#MainStatusBar) - MenuHeight()
    
    ; Bind Events
    BindEvent(#PB_Event_SizeWindow, @UpdateWindow(), #Main)
    
    ; Event Loop
    Repeat
      Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
          Select EventWindow()
            Case #Main
              Break
            Case #FormAbout
              CloseWindow(#FormAbout)
              
          EndSelect
          
        Case #PB_Event_Menu
          Select EventMenu()
            CompilerIf #PB_Compiler_OS = #PB_OS_MacOS   
              Case #PB_Menu_About
                PostEvent(#PB_Event_Menu, #Main, #MainMenuAbout)
                
              Case #PB_Menu_Preferences
                
              Case #PB_Menu_Quit
                PostEvent(#PB_Event_CloseWindow, #Main, #Null)
                
            CompilerEndIf
            
          Case #MainMenuAbout
            ;MessageRequester("About", #ProgramTitle + #LF$ + #ProgramVersion, #PB_MessageRequester_Info)
            OpenFormAbout()
            
          Case #MainMenuExit
            PostEvent(#PB_Event_CloseWindow, #Main, #Null)
            
          EndSelect
          
        Case #PB_Event_Gadget
          Select EventGadget()
              
          EndSelect
          
      EndSelect
    ForEver
    
  EndIf
  
EndProcedure : Main()

My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
calypso
User
User
Posts: 17
Joined: Sun Mar 26, 2023 7:23 am
Location: Vancouver BC Canada

Re: Window Menu Grief

Post by calypso »

@mk-soft

Thank you, I'll check it out this later evening (it's only 7:22pm here right now)
Post Reply