Dimension d'une fenêtre

Partagez votre expérience de PureBasic avec les autres utilisateurs.
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

Dimension d'une fenêtre

Message par Le Soldat Inconnu »

Ce code permet d'obtenir la taille d'une fenêtre au total (bordure comprise) et la taille des bordure.

Code : Tout sélectionner

;- GetWindoSize

Structure WinSize
  Height.l
  Width.l
  Title.l
  Edge.l
EndStructure

Global WindowSize.WinSize

Procedure GetWindowSize(Window.l)
  GetWindowRect_(WindowID(Window), @Taille_Fenetre.rect)
  WindowSize\Width = Taille_Fenetre\Right - Taille_Fenetre\Left ; largeur de la fenêtre
  WindowSize\Height = Taille_Fenetre\Bottom - Taille_Fenetre\top ; hauteur de la fenêtre
  WindowSize\Edge = (WindowSize\Width - WindowWidth()) / 2 ; largeur de la bordure droite, gauche ou basse d'une fenêtre
  WindowSize\Title = WindowSize\Height - WindowHeight() - WindowSize\Edge ; hauteur de la bordure de titre d'une fenêtre
EndProcedure






;- Exemple

If OpenWindow(0, 0, 0, 300, 200, #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget, "GetWindowSize")
  
  GetWindowSize(0) ; On récupère la taille de la fenêtre
  
  If CreateGadgetList(WindowID())
    TextGadget(0, 5, 5, 290, 15, "Largeur : WindowSize\Width = " + Str(WindowSize\Width))
    TextGadget(1, 5, 25, 290, 15, "Hauteur : WindowSize\Height = " + Str(WindowSize\Height))
    TextGadget(2, 5, 45, 290, 15, "Bordure : WindowSize\Edge = " + Str(WindowSize\Edge))
    TextGadget(3, 5, 65, 290, 15, "Titre : WindowSize\Title = " + Str(WindowSize\Title))
  EndIf
  
  Repeat
    Event = WaitWindowEvent()
    
    If Event = #WM_SIZE
      GetWindowSize(0)
      SetGadgetText(0, "Largeur : WindowSize\Width = " + Str(WindowSize\Width))
      SetGadgetText(1, "Hauteur : WindowSize\Height = " + Str(WindowSize\Height))
      SetGadgetText(2, "Bordure : WindowSize\Edge = " + Str(WindowSize\Edge))
      SetGadgetText(3, "Titre : WindowSize\Title = " + Str(WindowSize\Title))
    EndIf
    
  Until Event = #WM_CLOSE
  
EndIf
Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]