Page 1 sur 1

Fichu fenêtre

Publié : jeu. 03/avr./2008 20:06
par Neosis
Salut à tous, j'ai un petit souci mineur à réglé :roll:
Voila le problème est très simple, j'ai mis l'option
#PB_Window_SizeGadget à une fenêtre pour pouvoir la redimensionner. Je voudrait savoir si il y avait quelques choses comme une fonction pour détecté le redimensionnement de la fenêtre.

Publié : jeu. 03/avr./2008 21:19
par Ulix
Salut Neosis !

Il y a l'évenement : #PB_Event_SizeWindow

Un exemple trouvé sur le forum.

Code : Tout sélectionner


Procedure sauve_taille_gadget(id_window,nb_max_gadget)
   
    Structure gadget
        id.l
        x.l
        y.l
        l.l
        h.l
    EndStructure
   
    Global Dim gadget.gadget(1)
    nb_gadget=0
    For num_gadget=0 To nb_max_gadget ; #PB_Compiler_EnumerationValue
        If IsGadget(num_gadget)
            Debug num_gadget
            nb_gadget=nb_gadget+1
            ReDim gadget.gadget(nb_gadget)
            gadget(nb_gadget)\id=num_gadget
            gadget(nb_gadget)\x=GadgetX(num_gadget)
            gadget(nb_gadget)\y=GadgetY(num_gadget)
            gadget(nb_gadget)\h=GadgetHeight(num_gadget)
            gadget(nb_gadget)\l=GadgetWidth(num_gadget)
        EndIf
       
    Next
    gadget(0)\id=nb_gadget
    gadget(0)\h=WindowHeight(id_window)
    gadget(0)\l=WindowWidth(id_window)
EndProcedure


Procedure resize_gadget(id_window)
    hw=gadget(0)\h
    lw=gadget(0)\l
    nhw=WindowHeight(id_window)
    nlw=WindowWidth(id_window)
    For num_gadget=1 To gadget(0)\id
        Debug num_gadget

        If IsGadget(gadget(num_gadget)\id)
            nx=gadget(num_gadget)\x*nlw/lw
            ny=gadget(num_gadget)\y*nhw/hw
            nh=gadget(num_gadget)\h*nhw/hw
            nl=gadget(num_gadget)\l*nlw/lw
           
            ResizeGadget(gadget(num_gadget)\id,nx,ny,nl,nh)
        EndIf
       
    Next
   
EndProcedure
ww=600
wh=500
OpenWindow(0,0,0,ww,wh,"test",#PB_Window_SizeGadget|#PB_Window_MaximizeGadget|#PB_Window_MinimizeGadget|#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
CreateStatusBar(0,WindowID(0))
CreateGadgetList(WindowID(0))
ContainerGadget(0,10,10,ww-20,320,#PB_Container_Flat)
TextGadget(1,0,0,ww-20,16,"LISTE",#PB_Text_Center)
ListIconGadget(2,10,26,ww-40,284,"Id.",80,#PB_ListIcon_GridLines|#PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_FullRowSelect)
AddGadgetColumn(2,1,"Description",185)
AddGadgetColumn(2,2,"Index",60)
ButtonGadget(3,ww-36,2,12,12,"-")
CloseGadgetList()
ContainerGadget(4,10,340,ww-20,80,#PB_Container_Flat)
TextGadget(5,0,0,ww-20,16,"PROPRIETES",#PB_Text_Center)
HyperLinkGadget(6, 10,25,80,21,"Identifiant :",$FFFF)
HyperLinkGadget(7,10,50,80,21,"Description :",$FFFF)
StringGadget(8,100,25,ww-130,21,"",#PB_String_UpperCase)
StringGadget(9,100,50,ww-130,21,"")
CloseGadgetList()
ButtonGadget(10,10,430,70,21,"Actualiser")
ButtonGadget(11,85,430,70,21,"Ajouter")
ButtonGadget(12,160,430,70,21,"Modifier")
ButtonGadget(13,235,430,70,21,"Effacer")
ButtonGadget(14,ww-80,430,70,21,"Quitter")
ButtonGadget(15,ww-80,450,70,21,"Quitter2")



sauve_taille_gadget(0,100) ;100 c'est le nombre de gadget max,
;comme dans mes programme l'énumeration des gadget à lieu avant j'utilise :#PB_Compiler_EnumerationValue
;
Repeat
    Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
            End
        Case #PB_Event_Gadget
        Case #PB_Event_SizeWindow 
            resize_gadget(0)
           
    EndSelect
ForEver

Un autre exemple avec une callback

Code : Tout sélectionner


Form1_W=312 ; Form's client width.
Form1_H=213 ; Form's client height.

Global Form1_hWnd,Form1_OrigW,Form1_OrigH

#Form1_Flags=#PB_Window_MaximizeGadget|#PB_Window_MinimizeGadget|#PB_Window_SizeGadget|#PB_Window_SystemMenu
Form1_hWnd=OpenWindow(0,200,200,Form1_W,Form1_H,"Form1",#Form1_Flags)
If Form1_hWnd=0 Or CreateGadgetList(Form1_hWnd)=0 : End : EndIf
SmartWindowRefresh(0,#True)

Form1_OrigW=WindowWidth(0)  ; Original non-client width.
Form1_OrigH=WindowHeight(0) ; Original non-client height.

#Form1_Command1=1 : Form1_Command1_hWnd=ButtonGadget(#Form1_Command1,8,8,81,33,"Command1")
#Form1_Command2=2 : Form1_Command2_hWnd=ButtonGadget(#Form1_Command2,224,8,81,33,"Command2")
#Form1_Command3=3 : Form1_Command3_hWnd=ButtonGadget(#Form1_Command3,120,88,81,33,"Command3")
#Form1_Command4=4 : Form1_Command4_hWnd=ButtonGadget(#Form1_Command4,8,176,81,33,"Command4")
#Form1_Command5=5 : Form1_Command5_hWnd=ButtonGadget(#Form1_Command5,224,176,81,33,"Command5")

Procedure resize_gadget(id_window)

			Form1_RatioW.f=WindowWidth(0)/Form1_OrigW ; Get horizontal difference.
      Form1_RatioH.f=WindowHeight(0)/Form1_OrigH ; Get vertical difference.
      ResizeGadget(#Form1_Command1,8*Form1_RatioW,8*Form1_RatioH,81*Form1_RatioW,33*Form1_RatioH)
      ResizeGadget(#Form1_Command2,224*Form1_RatioW,8*Form1_RatioH,81*Form1_RatioW,33*Form1_RatioH)
      ResizeGadget(#Form1_Command3,120*Form1_RatioW,88*Form1_RatioH,81*Form1_RatioW,33*Form1_RatioH)
      ResizeGadget(#Form1_Command4,8*Form1_RatioW,176*Form1_RatioH,81*Form1_RatioW,33*Form1_RatioH)
      ResizeGadget(#Form1_Command5,224*Form1_RatioW,176*Form1_RatioH,81*Form1_RatioW,33*Form1_RatioH)

EndProcedure



Procedure MyWindowCallback(WindowID, Message, wParam, lParam)
  Result=#PB_ProcessPureBasicEvents
  Select Message
    Case #WM_SIZE ; Form's size has changed.
      Form1_RatioW.f=WindowWidth(0)/Form1_OrigW ; Get horizontal difference.
      Form1_RatioH.f=WindowHeight(0)/Form1_OrigH ; Get vertical difference.
      ResizeGadget(#Form1_Command1,8*Form1_RatioW,8*Form1_RatioH,81*Form1_RatioW,33*Form1_RatioH)
      ResizeGadget(#Form1_Command2,224*Form1_RatioW,8*Form1_RatioH,81*Form1_RatioW,33*Form1_RatioH)
      ResizeGadget(#Form1_Command3,120*Form1_RatioW,88*Form1_RatioH,81*Form1_RatioW,33*Form1_RatioH)
      ResizeGadget(#Form1_Command4,8*Form1_RatioW,176*Form1_RatioH,81*Form1_RatioW,33*Form1_RatioH)
      ResizeGadget(#Form1_Command5,224*Form1_RatioW,176*Form1_RatioH,81*Form1_RatioW,33*Form1_RatioH)
  EndSelect
  ProcedureReturn Result
EndProcedure

SetWindowCallback(@MyWindowCallback())
Repeat
    Select WaitWindowEvent()
        Case #PB_Event_CloseWindow
            End
        Case #PB_Event_Gadget
        Case #PB_Event_SizeWindow 
            resize_gadget(0)
           
    EndSelect
ForEver
Voila j'espéres que cela te sera utile !
A + :P

Publié : ven. 04/avr./2008 6:11
par Neosis
Merci Ulix :) ça résout mon problème, je vais étudier ces code d'un peu plus prés :wink: