Page 1 of 1

Create a software installer using PureBasic

Posted: Thu May 09, 2024 6:58 am
by hoangdiemtinh
English is not my main language, so I use Google to translate.

I would like to ask for advice and suggestions, on creating the Software Installer, in a strange and somewhat different way, using PureBasic.
In setup programs, I see they use each Page and Next button, so with PureBasic, what GadGet do we need to use,...

Thank you for your advice.

Re: Create a software installer using PureBasic

Posted: Thu May 09, 2024 10:36 am
by spikey
There's the PanelGadget. Or if you don't want tabs, I'd create a series of ContainerGadget and use HideGadget to show the selected and conceal the deselected ones when a button was pressed.

Re: Create a software installer using PureBasic

Posted: Thu May 09, 2024 11:06 am
by Bitblazer
If you want to do really special interactive buttons or elements, you often need to use the CanvasGadget.

Re: Create a software installer using PureBasic

Posted: Thu May 09, 2024 8:59 pm
by mestnyi
https://github.com/mestnyi33/widget
widget/examples/container's/panel/panel(hide-buttons).pb

Re: Create a software installer using PureBasic

Posted: Fri May 10, 2024 2:01 pm
by Axolotl
hoangdiemtinh wrote: Thu May 09, 2024 6:58 am ....
In setup programs, I see they use each Page and Next button, so with PureBasic, what GadGet do we need to use,...

Thank you for your advice.
I have a small collection of links to this .... (never used any of them so far)
Step Wizard
PB EasySetup - Setup maker for your program
https://www.purebasic.fr/english/viewto ... highlight=

And a simple template is easy ...
The heavy lifting is up to you :D

Code: Select all

; --- Simple Installer Template 

EnableExplicit

Enumeration EWindow 1 
  #WINDOW_Main 
EndEnumeration 

Enumeration EGadget 1 
  #GADGET_pnlMain     ; PanelGadget 
  #GADGET_btnPrev     ; 
  #GADGET_btnNext 
  #GADGET_btnInstall  ; 
  #GADGET_btnCancel   ; 
EndEnumeration 

Enumeration ETabSheet 
  #TABSHEET_0
  #TABSHEET_1
  #TABSHEET_2
  #TABSHEET_3
EndEnumeration 

  ; used instead of CountGadgetItems() 
  #TABSHEET_LastTab = #PB_Compiler_EnumerationValue - 1 ; equal 


#Caption$       = "Setup Template " 
#MainCaption$   = #Caption$ + #PB_Editor_BuildCount + "." + #PB_Editor_CompileCount 


Procedure Confirm(Message$) 
  If MessageRequester(#Caption$, Message$, #PB_MessageRequester_Info|#PB_MessageRequester_YesNo) = #PB_MessageRequester_Yes 
    ProcedureReturn #True 
  EndIf 
  ProcedureReturn #False 
EndProcedure 

; ---

Procedure UpdateGadgets(TabIndex) 
  ; 

  DisableGadget(#GADGET_btnPrev, Bool(TabIndex = 0)) 
  DisableGadget(#GADGET_btnNext, Bool(TabIndex = #TABSHEET_LastTab)) 

  Select TabIndex 
    Case #TABSHEET_0 
      DisableGadget(#GADGET_btnInstall, 1) 

    Case #TABSHEET_1
    
    Case #TABSHEET_2
    
    Case #TABSHEET_3
      DisableGadget(#GADGET_btnInstall, 0) 
    
  EndSelect 
  ProcedureReturn TabIndex  ; further use ?? 
EndProcedure 

; ---

Procedure OpenMainWindow(WndW = 600, WndH = 400)  ; return NON-ZERO (succeed) 
; Protected index 

  If OpenWindow(#WINDOW_Main, 0, 0, WndW, WndH, #MainCaption$, #PB_Window_SystemMenu|#PB_Window_ScreenCentered) 

    PanelGadget(#GADGET_pnlMain, 0, 0, WndW, WndH-32) 
      AddGadgetItem(#GADGET_pnlMain, -1, "TabSheet_" + #TABSHEET_0) 
      ; fill the sheet 

      AddGadgetItem(#GADGET_pnlMain, -1, "TabSheet_" + #TABSHEET_1) 
      ; fill the sheet 

      AddGadgetItem(#GADGET_pnlMain, -1, "TabSheet_" + #TABSHEET_2) 
      ; fill the sheet 

      AddGadgetItem(#GADGET_pnlMain, -1, "TabSheet_" + #TABSHEET_3) 
      ; fill the sheet 

    CloseGadgetList() 

CompilerIf #PB_Editor_CreateExecutable 
    ; Hide all Tabs in Runtime // keep them for development 
    ; 
    SendMessage_(GadgetID(#GADGET_pnlMain), #TCM_DELETEALLITEMS, 0, 0) 
CompilerEndIf

    ; Button Line 
    ButtonGadget(#GADGET_btnPrev, WndW-320, WndH-28, 76, 24, "Prev") 
    ButtonGadget(#GADGET_btnNext, WndW-240, WndH-28, 76, 24, "Next") 
    ButtonGadget(#GADGET_btnCancel,  WndW-160, WndH-28, 76, 24, "Cancel") 
    ButtonGadget(#GADGET_btnInstall, WndW-80, WndH-28, 76, 24, "Install") 

    ProcedureReturn #True 
  EndIf
  ProcedureReturn #False 
EndProcedure 

; --- 

Procedure main() 
  Protected tabindex 

  If OpenMainWindow() 
    ; init 

    UpdateGadgets(tabindex) 
    Repeat 
      Select WaitWindowEvent() 
        Case #PB_Event_CloseWindow 
          Break 

        Case #PB_Event_Gadget 
          Select EventGadget() 
            Case #GADGET_btnPrev 
              If tabindex > 0 : tabindex - 1 : EndIf 
              SetGadgetState(#GADGET_pnlMain, tabindex) 
              UpdateGadgets(tabindex) 
            Case #GADGET_btnNext 
              If tabindex < #TABSHEET_LastTab : tabindex + 1 : EndIf 
              SetGadgetState(#GADGET_pnlMain, tabindex) 
              UpdateGadgets(tabindex) 
            Case #GADGET_btnCancel 
              If Confirm("Are you sure to exit without installing this beautiful application?") 
                Break  
              EndIf 
              UpdateGadgets(tabindex) 

            Case #GADGET_btnInstall 
              UpdateGadgets(tabindex) 

          EndSelect 
      EndSelect 
    ForEver 

    ; clean up properly 
    
  EndIf 
  ProcedureReturn 0 
EndProcedure 

End main()