How 2 design a loading dailog

Just starting out? Need help? Post your questions and find answers here.
User avatar
ustuode
New User
New User
Posts: 6
Joined: Thu Dec 06, 2018 5:46 am

How 2 design a loading dailog

Post by ustuode »

A program that have many windows.
I want to design a noBoard loading window when the program is working something, while finish the event and next close the loading window.
In loading window show time , user could not do anything
:oops: :oops: :oops: tks
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: How 2 design a loading dailog

Post by mk-soft »

You can do it over Threads and PosteEvent to Main program...

Link to example: viewtopic.php?f=13&t=70645&p=521827
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
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: How 2 design a loading dailog

Post by Marc56us »

If you just want to display the elapsed time, just put a sticky and borderLess small window in the foreground and close it when done.

Code: Select all

Enumeration 
    #Win    
    #Timer_1_sec
    #Timer_5_sec
    #Btn_Quit
    #Win_Wait
    #Txt_Timer
EndEnumeration

OpenWindow(#Win, 0, 0, 640, 480, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(#Btn_Quit, WindowWidth(#Win) - 100, WindowHeight(#Win) - 40, 80, 25, "Quitter")
AddWindowTimer(#Win, #Timer_1_sec, 1000)
AddWindowTimer(#Win, #Timer_5_sec, 5000)

OpenWindow(#Win_Wait, 0, 0, 200, 100, "", #PB_Window_ScreenCentered | #PB_Window_BorderLess)
TextGadget(#Txt_Timer, 50, 50, 100, 15, "", #PB_Text_Center)
SetWindowColor(#Win_Wait, #Gray)
StickyWindow(#Win_Wait, #True)

Repeat
    Select WaitWindowEvent()
        Case #PB_Event_Timer
            Select EventTimer() 
                Case #Timer_1_sec
                    If IsWindow(#Win_Wait)
                        i + 1
                        SetGadgetText(#Txt_Timer, Str(i) + " Secs")
                    EndIf
                Case #Timer_5_sec
                    RemoveWindowTimer(#Win, #Timer_5_sec)
                    CloseWindow(#Win_Wait)
            EndSelect
            
        Case #PB_Event_CloseWindow
            Break
            
        Case #PB_Event_Gadget
            Select EventGadget()
                Case #Btn_Quit
                    Break   
            EndSelect
            
    EndSelect
ForEver
:wink:
User avatar
ustuode
New User
New User
Posts: 6
Joined: Thu Dec 06, 2018 5:46 am

Re: How 2 design a loading dailog

Post by ustuode »

yep :D StickyWindow is what I want 2 find. I just cant 2 describe the method
thks :lol:
User avatar
ustuode
New User
New User
Posts: 6
Joined: Thu Dec 06, 2018 5:46 am

Re: How 2 design a loading dailog

Post by ustuode »

there is a new question,
when I run StickyWindow(#Win_Wait, #True) to put the waitingwindow to the topest, I still can control the mainwindow under it, How can I reset the waitingwindow like a MessageRequester box, when it popup I couldnot touch my mainwindow :oops: :oops:
User avatar
ustuode
New User
New User
Posts: 6
Joined: Thu Dec 06, 2018 5:46 am

Re: How 2 design a loading dailog

Post by ustuode »

I have sloved all my problems , post my code after

Code: Select all

Procedure DoEvents()
  Protected Event.l
  Repeat
    Event = WindowEvent()
    If Event = 0
      Sleep_(0)
    EndIf
  Until Event = 0
EndProcedure

;waiting window
Procedure SetLoadingWin(opeOrClo)
  If opeOrClo
    OpenWindow_waiting()
    StickyWindow(Window_waiting, #True)
    SetActiveWindow(Window_waiting)
    DisableWindow(Window_main, #True)
    DoEvents()
  Else
    DisableWindow(Window_main, #False)
    If IsWindow(Window_waiting)
      CloseWindow(Window_waiting)
    EndIf  
  EndIf
EndProcedure
may be of help to others
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: How 2 design a loading dailog

Post by mk-soft »

Something's very important:
1. There should always be only one event loop in the program.
2. Never use a delay in the event loop.
3. Only use WindowEvent() in special cases, otherwise always WaitWindowEvent(...)
4. Use EnableExplicit to avoid typing errors of variables

Added
5. Use not Long (Event.l) for default variables. Use Integer (Event.i). Integer is 32bit on x86 and 64bit on x64 programs.

P.S
Small example...

Update

Code: Select all

;-TOP

EnableExplicit

; -----------------------------------------------------------------------------

Enumeration windows
  #Main
  #Dialog
EndEnumeration

Enumeration menus
  #MainMenu
EndEnumeration

Enumeration menuitems
  #MainMenuExit
  #MainMenuDialog
EndEnumeration

Enumeration gadgets
  #MainList
  #DialogString
  #DialogOk
EndEnumeration

; -----------------------------------------------------------------------------

Global ExitApplication

; -----------------------------------------------------------------------------

Procedure OpenDialogWindow()
  
  If OpenWindow(#Dialog, #PB_Ignore, #PB_Ignore, 300, 80, "Dialog Window", #PB_Window_SystemMenu, WindowID(#Main))
    StringGadget(#DialogString, 10, 10, 280, 25, "")
    ButtonGadget(#DialogOk, 150 - 30, 45, 60, 25 , "Ok")
  
    DisableWindow(#Main, 1)
    
  EndIf
  
EndProcedure

; -----------------------------------------------------------------------------

Procedure DoEventDialog()
  Select Event()
    Case #PB_Event_CloseWindow
      DisableWindow(#main, 0)
      CloseWindow(#Dialog)
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #DialogOk
          AddGadgetItem(#MainList, - 1, GetGadgetText(#DialogString))
          DisableWindow(#main, 0)
          CloseWindow(#Dialog)
      EndSelect
  EndSelect
EndProcedure

; -----------------------------------------------------------------------------

Procedure Main()
  Protected Event
  
  If OpenWindow(#main, #PB_Ignore, #PB_Ignore, 800, 600, "Main Window", #PB_Window_SystemMenu)
    
    CreateMenu(#MainMenu, WindowID(#Main))
    MenuTitle("&File")
    MenuItem(#MainMenuDialog, "&Open Dialog")
    MenuItem(#MainMenuExit, "E&xit")
    
    ListViewGadget(#MainList, 0, 0, WindowWidth(#Main), WindowHeight(#Main) - MenuHeight())
    
    ; Event Loop
    Repeat
      Event = WaitWindowEvent()
      Select Event
        Case #PB_Event_CloseWindow
          If EventWindow() = #Main
            ExitApplication = 1
          EndIf
          
        Case #PB_Event_Menu
          Select EventMenu()
            Case #MainMenuExit
              ExitApplication = 1
            Case #MainMenuDialog
              OpenDialogWindow()
          EndSelect
              
      EndSelect
      
      ; Do dialog events
      Select EventWindow()
        Case #Dialog
          DoEventDialog()
      EndSelect
      
    Until ExitApplication
  EndIf
  
EndProcedure : Main()

End

; -----------------------------------------------------------------------------
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
Post Reply