Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
prog:lazarus:classes:tcontrols:dimensions [28/08/2024 15:41] thierry [Parent.AddHandlerOnResize] |
prog:lazarus:classes:tcontrols:dimensions [02/09/2024 18:58] (Version actuelle) thierry [TControl.BoundsRect] |
||
---|---|---|---|
Ligne 68: | Ligne 68: | ||
</code> | </code> | ||
+ | ==== TControl.BoundsRect ==== | ||
+ | <code pascal> | ||
+ | function TControl.GetBoundsRect: TRect; | ||
+ | begin | ||
+ | Result.Left := FLeft; | ||
+ | Result.Top := FTop; | ||
+ | Result.Right := FLeft+FWidth; | ||
+ | Result.Bottom := FTop+FHeight; | ||
+ | end; | ||
+ | |||
+ | </code> | ||
+ | ==== TControl.ClientToScreen ==== | ||
+ | |||
+ | <code pascal> | ||
+ | {------------------------------------------------------------------------------ | ||
+ | function TControl.ClientToScreen(const APoint: TPoint): TPoint; | ||
+ | ------------------------------------------------------------------------------} | ||
+ | function TControl.ClientToScreen(const APoint: TPoint): TPoint; | ||
+ | var | ||
+ | P : TPoint; | ||
+ | begin | ||
+ | P := ClientOrigin; | ||
+ | Result.X := APoint.X + P.X; | ||
+ | Result.Y := APoint.Y + P.Y; | ||
+ | end; | ||
+ | |||
+ | function TControl.ClientToScreen(const ARect: TRect): TRect; | ||
+ | var | ||
+ | P : TPoint; | ||
+ | begin | ||
+ | P := ClientToScreen(Point(0, 0)); | ||
+ | Result := ARect; | ||
+ | Result.Offset(P); | ||
+ | end; | ||
+ | |||
+ | </code> | ||
+ | |||
+ | |||
Ligne 142: | Ligne 180: | ||
end; | end; | ||
</code> | </code> | ||
+ | === Avec interception du message WM_SIZE === | ||
+ | <code pascal> | ||
+ | protected | ||
+ | procedure WndProc(var TheMessage: TLMessage); override; | ||
+ | ... | ||
+ | |||
+ | procedure TMyControl.WndProc(var TheMessage: TLMessage); | ||
+ | var | ||
+ | vWMSize: TWMSize; | ||
+ | begin | ||
+ | inherited WndProc(TheMessage); | ||
+ | if TheMessage.Msg = WM_SIZE then | ||
+ | begin | ||
+ | vWMSize := TWMSize(TheMessage); | ||
+ | |||
+ | DebugLn('%s.WndProc : Le parent a été redimensionné, SizeType[%d] H[%d] W[%d]', | ||
+ | [Name, vWMSize.SizeType, vWMSize.Height, vWMSize.Width]); | ||
+ | // Le parent a été redimensionné | ||
+ | // Implémenter ici la logique de redimensionnement du contrôle | ||
+ | end; | ||
+ | end; | ||
+ | |||
+ | </code> | ||
+ | == TWMSize.SizeType == | ||
+ | le paramétre SizeType peut avoir les valeurs suivantes : | ||
+ | <code pascal unit Windows (\fpc\3.2.2\source\rtl\win\wininc\defines.inc)> | ||
+ | { WM_SIZE message } | ||
+ | SIZE_MAXHIDE = 4; | ||
+ | SIZE_MAXIMIZED = 2; | ||
+ | SIZE_MAXSHOW = 3; | ||
+ | SIZE_MINIMIZED = 1; | ||
+ | SIZE_RESTORED = 0; | ||
+ | </code> | ||
+ | Il peut arriver que les valeurs soit : | ||
+ | * SizeType = 6 : Force le realignement (voir ci-dessous) | ||
+ | * SizeType = 128 : JE NE SAIS PAS ??? | ||
+ | |||
+ | **SizeType = 6** | ||
+ | <code pascal unit Controls (\lcl\include\wincontrol.inc)> | ||
+ | procedure TWinControl.SendMoveSizeMessages(SizeChanged, PosChanged: boolean); | ||
+ | begin | ||
+ | ... | ||
+ | with SizeMsg do | ||
+ | begin | ||
+ | Msg := LM_SIZE; | ||
+ | SizeType := 6; // force realign | ||
+ | ... | ||
+ | Width := FWidth; | ||
+ | Height := FHeight; | ||
+ | ... | ||
+ | WindowProc(TLMessage(SizeMsg)); | ||
+ | end; | ||
+ | </code> | ||
+ | |||
+ | |||
+ | |||