Property Sheet control (API bloated+)

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

Property Sheet control (API bloated+)

Post by BackupUser »

Code updated for 5.20+

Restored from previous forum. Originally posted by Justin.

This example shows how to handle a property sheet control. i used my PBWindow editor to produce the dialog templates, it was easy for me but if you don't have it or you don't know how to create dialogs it will be useless.

it's for advanced users.

why use this instead of the PB Panel gadget?
- profesional look
- no redrawing
- etc..

it's a little big, i'll upload to Paul's site later.

Code: Select all

;Property Sheets in PB
;Window and Dialogs Templates visually designed with PB Window Editor 2.91
;email : [url]mailto:shinracop@yahoo.com">shinracop@yahoo.com
;Justin 02/03
;
;REF: >16

#SH1_Button0 = 0
#SH2_Button0 = 1
#Button4 = 2
#Button5 = 3

#Window1 = 0

#PSP_DLGINDIRECT = 1
#PSH_PROPSHEETPAGE = 8
#PSH_NOAPPLYNOW = 128

Structure PSHNOTIFY 
  hdr.NMHDR
  lParam.i
EndStructure

Structure PROPSHEETHEADER
  dwSize.l
  dwFlags.l
  hwndParent.l
  hInstance.l
 
  StructureUnion
    hIcon.l
    pszIcon.l
  EndStructureUnion
 
  *pszCaption
  nPages.l
 
  StructureUnion
    nStartPage.l
   *pStartPage
  EndStructureUnion
 
  StructureUnion
    ppsp.l
    phpage.l
  EndStructureUnion
 
  pfnCallback.l
EndStructure 

;page 1
Procedure sheet1proc(hdlg,msg,wparam,lparam)
  retval=0
  Select msg
      
    Case #BN_CLICKED
      Select wparam
          
        Case #SH1_Button0
          MessageRequester("","Page 1 Ok",0)
          
      EndSelect
      
      ;Case #WM_CLOSE
      ;DestroyWindow_(hdlg)
      
  EndSelect
  ProcedureReturn retval
EndProcedure

;page 2
Procedure sheet2proc(hdlg,msg,wparam,lparam)
  retval=0
  Select msg
      
    Case #WM_INITDIALOG
      *ppsp.PROPSHEETPAGE=lparam ;copy of the PROPSHEETPAGE struct for this page
      
    Case #WM_NOTIFY
      *pnmh.NMHDR=lparam
      Select *pnmh\code
        Case #PSN_KILLACTIVE
          
        Case #PSN_SETACTIVE
          
        Case #PSN_APPLY
          
        Case #PSN_RESET
          *lppsn.PSHNOTIFY
          
      EndSelect
      
    Case #WM_COMMAND
      Select wparam>>16
        Case #BN_CLICKED
          Select wparam
              
            Case #SH2_Button0
              MessageRequester("","Page 2 Ok",0)
              
          EndSelect
      EndSelect
      
      ;Case #WM_CLOSE
      ;DestroyWindow_(hdlg)
      
  EndSelect
  ProcedureReturn retval
EndProcedure


;-------------------------------------------------------
;CODE START
;-------------------------------------------------------
;main window
hmainwnd=OpenWindow(#Window1,182,105,448,253,"Main Window",#PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_TitleBar)

ButtonGadget(#Button4,10,24,90,24,"Prop Sheet")
ButtonGadget(#Button5,170,24,90,24,"Cancel")

;fill property sheet structures
;two pages
Dim psp.PROPSHEETPAGE(2)

;page 1
psp(0)\dwSize=SizeOf(PROPSHEETPAGE)
psp(0)\dwFlags=#PSP_DLGINDIRECT
;hInstance
psp(0)\pResource=?dlgtemplate1
;hIcon
;pszIcon
;pszTitle
psp(0)\pfnDlgProc=@sheet1proc()
psp(0)\lParam=0
;pfnCallback
;pcRefParent

;page 2
psp(1)\dwSize=SizeOf(PROPSHEETPAGE)
psp(1)\dwFlags=#PSP_DLGINDIRECT
;hInstance
psp(1)\pResource=?dlgtemplate2
;hIcon
;pszIcon
;pszTitle
psp(1)\pfnDlgProc=@sheet2proc()
psp(1)\lParam=0
;pfnCallback
;pcRefParent

;property sheet (modal)
psh.PROPSHEETHEADER\dwSize=SizeOf(PROPSHEETHEADER)
psh\dwFlags=#PSH_PROPSHEETPAGE|#PSH_NOAPPLYNOW
psh\hwndParent=hmainwnd
;hInstance
;hIcon
;pszIcon
psh\pszCaption=@"main title"
psh\nPages=2
psh\nStartPage=0
;pStartPage
psh\ppsp=@psp(0)
;phpage
;pfnCallback

;-----------------------------------------------------------------
;MAIN WINDOW EVENT LOOP
;-----------------------------------------------------------------
Repeat
  EventID = WaitWindowEvent()
  Select EventID
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #Button4
          ;show property sheet
          PropertySheet_(@psh)
          
        Case #Button5 ;exit
          End
          
      EndSelect
  EndSelect
Until EventID = #PB_Event_CloseWindow


;---------------------------------------------------------------
;DIALOG TEMPLATES (Modeless)
;---------------------------------------------------------------
;PAGE 1
DataSection
  dlgtemplate1:
  Data.b 65,0,192,20,  0,0,0,1,  3,0,  181,0,  83,0,  193,0,  82,0
  Data.b 0,0,  0,0,  83,0,104,0,101,0,101,0,116,0,49,0,0,0,  1,0,  77,0,83,0,32,0,83,0,97,0,110,0,115,0,32,0,83,0,101,0,114,0,105,0,102,0,0,0 ,0,0
  
  Data.b 0,0,1,80,  0,0,0,0,  100,0,  39,0,  60,0,  15,0,  0,0
  Data.b 66,0,117,0,116,0,116,0,111,0,110,0,0,0,  79,0,107,0,0,0 ,0,0
  
  Data.b 0,0,129,80,  0,0,0,0,  13,0,  39,0,  60,0,  15,0,  1,0
  Data.b 69,0,100,0,105,0,116,0,0,0,  115,0,116,0,114,0,49,0,0,0 ,0,0
  
  Data.b 0,0,0,80,  0,0,0,0,  13,0,  15,0,  60,0,  15,0,  2,0
  Data.b 83,0,116,0,97,0,116,0,105,0,99,0,0,0,  84,0,101,0,120,0,116,0,49,0,0,0 ,0,0 ,0,0
EndDataSection

;PAGE 2
DataSection
  dlgtemplate2:
  Data.b 65,0,192,20,  0,0,0,1,  3,0,  181,0,  83,0,  193,0,  82,0
  Data.b 0,0,  0,0,  83,0,104,0,101,0,101,0,116,0,50,0,0,0,  1,0,  77,0,83,0,32,0,83,0,97,0,110,0,115,0,32,0,83,0,101,0,114,0,105,0,102,0,0,0 ,0,0
  
  Data.b 0,0,1,80,  0,0,0,0,  100,0,  39,0,  60,0,  15,0,  0,0
  Data.b 66,0,117,0,116,0,116,0,111,0,110,0,0,0,  79,0,107,0,0,0 ,0,0
  
  Data.b 0,0,129,80,  0,0,0,0,  13,0,  39,0,  60,0,  15,0,  1,0
  Data.b 69,0,100,0,105,0,116,0,0,0,  115,0,116,0,114,0,50,0,0,0 ,0,0
  
  Data.b 0,0,0,80,  0,0,0,0,  13,0,  15,0,  60,0,  15,0,  2,0
  Data.b 83,0,116,0,97,0,116,0,105,0,99,0,0,0,  84,0,101,0,120,0,116,0,50,0,0,0 ,0,0 ,0,0
EndDataSection
;end code