Voici un petite fenêtre exemple, ou les macros peuvent être vraiment utiles
(Code édité le 08/09/2015 car erreur sur le calcul de la hauteur de la fenêtre)
Code : Tout sélectionner
LoadFont(0,"Arial",12,#PB_Font_HighQuality)
Enumeration
#MainForm
#Str1
#Str2
#Combo
#Spin
#Submit
#Chancel
EndEnumeration
Macro mOpenForm(IdWindows,CloseProcedure)
OpenWindow(IdWindows,XF,YF,WF,HF,title$,flag)
BindEvent(#PB_Event_CloseWindow,CloseProcedure,IdWindows)
EndMacro
Macro mString(Id,Label,value,EventProcedure)
temp=TextGadget(#PB_Any,X,Y,W,H,Label)
Y+H
StringGadget(Id,X,Y,W,H,value)
SetGadgetFont(temp,FontID(0))
SetGadgetFont(Id,FontID(0))
If EventProcedure<>-1
BindGadgetEvent(Id,EventProcedure)
EndIf
EndMacro
Macro mCombo(Id,Label,EventProcedure)
temp=TextGadget(#PB_Any,X,Y,W,H,Label)
Y+H
ComboBoxGadget(Id,X,Y,W,H)
SetGadgetFont(temp,FontID(0))
SetGadgetFont(Id,FontID(0))
If EventProcedure<>-1
BindGadgetEvent(Id,EventProcedure)
EndIf
EndMacro
Macro mAddItem(Id,Value,ItemData)
AddGadgetItem(Id,-1,Value)
SetGadgetItemData(Id,CountGadgetItems(Id)-1,ItemData)
EndMacro
Macro mGetData(Id)
GetGadgetItemData(Id,GetGadgetState(Id))
EndMacro
Macro mSpinValue(Id,value,Ext)
SetGadgetState(Id,value)
SetGadgetText(Id,Str(value)+Ext)
EndMacro
Macro mSpin(Id,Label,value,min,max,EventProcedure,Ext)
temp=TextGadget(#PB_Any,X,Y,W,H,Label)
Y+H
SpinGadget(Id,X,Y,W,H,min,max)
mSpinValue(Id,value,Ext)
SetGadgetFont(temp,FontID(0))
SetGadgetFont(Id,FontID(0))
If EventProcedure<>-1
BindGadgetEvent(Id,EventProcedure)
EndIf
EndMacro
Macro mBtForm(SubmitProcedure,ChancelProcedure)
ButtonGadget(#Submit,X,Y,(W/2)-M,H,"Valider")
ButtonGadget(#Chancel,X+(W/2)+M,Y,(W/2)-M,H,"Annuler")
BindGadgetEvent(#Submit,SubmitProcedure)
BindGadgetEvent(#Chancel,ChancelProcedure)
EndMacro
Procedure CloseMainForm()
End
EndProcedure
Procedure EventStr2()
Debug GetGadgetText(#Str2)
EndProcedure
Procedure EventCombo()
Debug "Le combo a la valeur "+Str(mGetData(#Combo))
EndProcedure
Procedure EventSpin()
mSpinValue(#Spin,GetGadgetState(#Spin)," %")
EndProcedure
Procedure Save()
Debug "Vous avez cliquer sur le bouton valider"
EndProcedure
Procedure OpenMainForm()
;On détermine ici le nombre de champs de la fenêtre (label inclus)
;On détermione la largeur, la hauteur ainsi que la marge
Protected NbChamp=4,W=180,H=30,M=10
Protected title$="Teste fenêtre"
Protected flag=#PB_Window_ScreenCentered|#PB_Window_SystemMenu
Protected WF=W+(M*2),HF=(NbChamp*((H*2)+M))+H+(M*2)
Protected X=M,Y=M,temp
mOpenForm(#MainForm,@CloseMainForm())
mString(#Str1,"String sans procedure","",-1)
Y+H+M
mString(#Str2,"String avec procedure","",@EventStr2())
Y+H+M
mCombo(#Combo,"Combo teste",@EventCombo())
mAddItem(#Combo,"Item 1",1)
mAddItem(#Combo,"Item 2",2)
mAddItem(#Combo,"Item 3",3)
SetGadgetState(#Combo,0)
Y+H+M
mSpin(#Spin,"Pourcentage",10,0,100,@EventSpin()," %")
Y+H+M
mBtForm(@Save(),@CloseMainForm())
EndProcedure
OpenMainForm()
Repeat:WaitWindowEvent():ForEver