MultiWindow

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

MultiWindow

Post by BackupUser »

Code updated for 5.20+

Restored from previous forum. Originally posted by ricardo.

Im really pleased with PureBasic, im learning and finding easy ways to do what are much difficult in other languages.

In my IRC Client i was wondering how to do a multiwindows app and how to control it and even how to create windows on the fly.
Tonight i only take 5 minutes to find the answer, maybe a lot of you know it before, but its new for me.

Code: Select all

#WINDOW_PARAMETERS = #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_SizeGadget


Procedure Crea(num.l)
  
  OpenWindow(num,100,100, 100, 200, Str(num), #WINDOW_PARAMETERS)
  
  ButtonGadget(num, 50, 75, 40, 20, "Send" ,#PB_Button_Default)
  ButtonGadget(num + 1, 50, 175, 40, 20, "Send" ,#PB_Button_Default)
  
EndProcedure


If OpenWindow(0,100,100, 400, 300,"memory", #WINDOW_PARAMETERS )
  ButtonGadget(0, 50, 75, 40, 20, "Send" ,#PB_Button_Default)
  
  Repeat 
    
    EventID = WaitWindowEvent()
    
    If EventID = #PB_Event_Gadget
      
      Select EventGadget()
          
        Case 0
          Cont.l = Cont + 1
          Crea(Cont)
          
        Default
          If EventGadget() = EventWindow()
            CloseWindow(EventGadget())
          Else
            SetGadgetText(EventGadget(),Str(EventGadget()))
          EndIf
          
      EndSelect
      
      
    EndIf
    
    If EventID = #PB_Event_CloseWindow
      
      If EventWindow() = 0
        Final = 1
      EndIf
      CloseWindow(EventWindow())
    EndIf
    
    
  Until Final = 1  
EndIf
End
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fweil.

Allright Ricardo. It is somewhere a good way to show / explain it.

One thing I had some difficuties to understand at start was how to manage multiple windows with specific parameters for each, like the possibility to handle sizing with resizable gadgets.

I finally learned how to put parameters in tables having a pointer corresponding to a given window. The table may contain X and Y sizes, and some events too.

Then the way to do it easily is to code your window numbers carefully to have small tables that you can use.

If you do so, you will also have some possibility to catch external windows parameters that may interest your application. But external windows don't have 'numbers' linked to yours (the hWnd parameter you get is a 'high' value returned by the OS).

So you may have an non direct numbering method to have window numbers in a column and the hWnd corresponding value in a second column of your window management table.

There is no limit to possibilities it gives.

Combining PureBasic with API stuff makes it really interesting.

Enjoy PureBasic

Francois Weil
14, rue Douer
F64100 Bayonne
Post Reply