1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
|
//------------------------------------------------------------------------------
(* SoLuTions is an Versatile Library for Delphi -
* -
* Version alternative publiée sur "www.developpez.net" -
* Post : "ajuster la taille de l'image avec de la form" -
* Post Number : 3956247 -
* Post URL = "http://www.developpez.net/forums/d676162/environnements-developpement/delphi/debutant/ajuster-taille-l-image-form/#post3956247"
* -
* Version alternative publiée sur "www.developpez.net" -
* Post : "Changement de résolution" -
* Post Number : 3024532 -
* Post URL = "http://www.developpez.net/forums/d503018/environnements-developpement/delphi/composants-vcl/changement-resolution/#post3024532"
* -
* Copyright ou © ou Copr. "SLT Solutions", (2006) -
* contributeur : ShaiLeTroll (2012) - Gestion des Styles sous C++BuilderXE2 -
* contributeur : ShaiLeTroll (2012) - Documentation Insight -
* contributeur : ShaiLeTroll (2014) - Traduction du code C++Builder vers DelphiXE2
* -
* ShaiLeTroll@gmail.com -
* -
* Ce logiciel est un programme informatique servant à aider les développeurs -
* Delphi avec une bibliothèque polyvalente, adaptable et fragmentable. -
* -
* Ce logiciel est régi par la licence CeCILL-C soumise au droit français et -
* respectant les principes de diffusion des logiciels libres. Vous pouvez -
* utiliser, modifier et/ou redistribuer ce programme sous les conditions -
* de la licence CeCILL-C telle que diffusée par le CEA, le CNRS et l'INRIA -
* sur le site "http://www.cecill.info". -
* -
* En contrepartie de l'accessibilité au code source et des droits de copie, -
* de modification et de redistribution accordés par cette licence, il n'est -
* offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons, -
* seule une responsabilité restreinte pèse sur l'auteur du programme, le -
* titulaire des droits patrimoniaux et les concédants successifs. -
* -
* A cet égard l'attention de l'utilisateur est attirée sur les risques -
* associés au chargement, à l'utilisation, à la modification et/ou au -
* développement et à la reproduction du logiciel par l'utilisateur étant -
* donné sa spécificité de logiciel libre, qui peut le rendre complexe à -
* manipuler et qui le réserve donc à des développeurs et des professionnels -
* avertis possédant des connaissances informatiques approfondies. Les -
* utilisateurs sont donc invités à charger et tester l'adéquation du -
* logiciel à leurs besoins dans des conditions permettant d'assurer la -
* sécurité de leurs systèmes et ou de leurs données et, plus généralement, -
* à l'utiliser et l'exploiter dans les mêmes conditions de sécurité. -
* -
* Le fait que vous puissiez accéder à cet en-tête signifie que vous avez -
* pris connaissance de la licence CeCILL-C, et que vous en avez accepté les -
* termes. -
* -
*----------------------------------------------------------------------------*)
unit SLT.Controls.VCL.FormsEx;
interface
uses Winapi.Windows, Winapi.Messages,
System.Classes, System.SysUtils,
Vcl.Forms, Vcl.Themes, Vcl.Graphics, Vcl.GraphUtil, Vcl.Menus;
type
/// <summary>Style alternatif pour les TCustomForm affichant une image de fond</summary>
/// <remarks>Le TSLTBackgroundFormStyleHook et TSLTBackgroundWindowHook sont totalement incompatible, les deux ne doivent pas cohabiter dans le même programme à cause du détournement sauvage de la WndProc
/// <para>Le TSLTBackgroundFormStyleHook fourni un fond uniquement sur les thèmes VCL personnalisés mais par sur le thème système</para></remarks>
/// <seealso href="https://theroadtodelphi.wordpress.com/2012/03/26/vcl-styles-adding-background-images-and-colors-to-delphi-forms">Variante plus récente par Rodrigo sur The Road to Delphi </seealso>
/// <remarks><para>Le TSLTBackgroundFormStyleHook utilise le TSLTBackgroundFormDrawer datant de delphi 5 sans prise en compte des Styles VCL,
/// il serait intéressant d'étudier le TFormStyleHookBackround de Rodrigo qui offre plus de fonctionnalité et respecte mieux la différence entre PaintNC et PaintBackground
/// ce que je ne respecte pas pour l'ancien Hook TSLTBackgroundWindowHook et son option BackgroundOnTitle</para></remarks>
TSLTBackgroundFormStyleHook = class(TFormStyleHook)
private class var
FBackground: TBitmap;
FTransparent: Boolean;
FTransparentOnDarkStyle: Boolean;
FMainFormOnly: Boolean;
private
class procedure SetBackground(const Value: TBitmap); static;
protected
procedure PaintBackground(Canvas: TCanvas); override;
public
class constructor Create();
class destructor Destroy();
class property Background: TBitmap read FBackground write SetBackground;
class property Transparent: Boolean read FTransparent write FTransparent;
class property TransparentOnDarkStyle: Boolean read FTransparentOnDarkStyle write FTransparentOnDarkStyle;
class property MainFormOnly: Boolean read FMainFormOnly write FMainFormOnly;
end;
/// <summary>STSLTBackgroundWindowHook affiche une image de fond</summary>
/// <remarks>Le STSLTBackgroundWindowHook n'est pas un class helper car lors de sa création en 2002 sous Delphi 5, le code était procédural,
/// lors de la refonte en classe en 2007, la version utilisée était Delphi 7, en s'inspirant du concept des Assistances de classes (Class Helper) du Delphi.NET</remarks>
/// <remarks>Le TSLTBackgroundFormStyleHook et TSLTBackgroundWindowHook sont totalement incompatible, les deux ne doivent surtout pas cohabiter dans le même programme.
/// <para>Le STSLTBackgroundWindowHook fourni un fond uniquement sur le thème système et NE supporte PAS que l'on change de style en cours de route</para></remarks>
TSLTBackgroundWindowHook = class(TObject)
private
FForm: TForm;
FBackground: TBitmap;
FBackgroundOnTitle: Boolean;
FNewWndProc : TFarProc; // Pointer ça serait pareil, c'est juste plus lisible
FOldWndProc : TFarProc;
private
procedure FormWndProc(var Message: TMessage);
public
constructor Create(AForm: TForm);
destructor Destroy(); override;
procedure LoadBackgroundByResName(const ABackgroundResName: string);
property Form: TForm read FForm;
property BackgroundOnTitle: Boolean read FBackgroundOnTitle write FBackgroundOnTitle;
end;
TSLTBackgroundFormDrawer = class(TObject)
private
FBackground: TBitmap;
FhDestDC: HDC;
FDestWidth: Integer;
FDestHeight: Integer;
FSourceWidth: Integer;
FSourceHeight: Integer;
FTransparent: Boolean;
FTransparentOnDarkStyle: Boolean;
FStartOffSet: TPoint;
private
procedure BackGroungBlt();
procedure TransparentBackGroungBlt();
public
constructor Create(ABackground: TBitmap; AFormSize: TSize; ACanvas: TCanvas);
function EraseBackGround(): Boolean;
property Transparent: Boolean read FTransparent write FTransparent;
property TransparentOnDarkStyle: Boolean read FTransparentOnDarkStyle write FTransparentOnDarkStyle;
property StartOffSet: TPoint read FStartOffSet write FStartOffSet;
end;
/// <summary>Assistance de la classe TForm, en particulier la Méthode ScaleBy</summary>
/// <remarks>Le TFormScaleSLTAssistant n'est pas un class helper car lors de sa création la version utilisée était Delphi7 puis C++Builder2007
/// Traduction C++Builder vers Delphi en concervant ce concept des Assistances de classes (Class Helper) du Delphi.NET</remarks>
TFormScaleSLTAssistant = class(TObject)
private
class var FReferenceZoom: Integer;
class var FCurrentZoom: Integer;
public
class constructor Create();
/// <summary>BuildChangeZoomMenu ajoute comme menus enfants dans un TMenuItem listant plusieurs niveau de Zoom</summary>
/// <param name="AMenuZoom">Menu dans lequel seront insérés comme sous-menu chaque niveau de zoom géré par l'application</param>
/// <param name="AOnClick">Gestionnaire d'évèmenent commun à chaque sous-menu, le Tag permet de trouver le style concerné, il recommandé d'utiliser ZoomClickDefaultEventHandler</param>
/// <param name="ADefaultZoom">Zoom fixé à l'origine</param>
/// <returns>Zoom actuel</returns>
class function BuildChangeZoomMenu(AMenuZoom: TMenuItem; AOnClick: TNotifyEvent; ADefaultZoom: Integer = -1): Integer;
class procedure ZoomClickDefaultEventHandler(Sender: TObject);
class procedure ZoomAllForms(AZoom: Integer);
class procedure ApplyCurrentZoom(AForm: TForm);
class procedure CancelZoom(AForm: TForm);
class property CurrentZoom: Integer read FCurrentZoom;
class property ReferenceZoom: Integer read FReferenceZoom;
end;
implementation
uses System.Math,
SLT.Controls.VCL.GraphicsEx;
{ TSLTBackgroundFormStyleHook }
//------------------------------------------------------------------------------
class constructor TSLTBackgroundFormStyleHook.Create();
begin
FBackground := TBitmap.Create();
end;
//------------------------------------------------------------------------------
class destructor TSLTBackgroundFormStyleHook.Destroy();
begin
FreeAndNil(FBackground);
end;
//------------------------------------------------------------------------------
procedure TSLTBackgroundFormStyleHook.PaintBackground(Canvas: TCanvas);
begin
inherited PaintBackground(Canvas);
if not FBackground.Empty and (not FMainFormOnly or (Form = Application.MainForm)) then
begin
with TSLTBackgroundFormDrawer.Create(FBackground, TSize.Create(Form.ClientWidth, Form.ClientHeight), Canvas) do
try
Transparent := Self.Transparent;
TransparentOnDarkStyle := Self.TransparentOnDarkStyle;
EraseBackGround();
finally
Free();
end;
end;
end;
//------------------------------------------------------------------------------
class procedure TSLTBackgroundFormStyleHook.SetBackground(const Value: TBitmap);
begin
FBackground.Assign(Value);
end;
{ TSLTBackgroundWindowHook }
//------------------------------------------------------------------------------
constructor TSLTBackgroundWindowHook.Create(AForm: TForm);
begin
inherited Create();
FForm := AForm;
end;
//------------------------------------------------------------------------------
destructor TSLTBackgroundWindowHook.Destroy();
begin
if Assigned(FOldWndProc) and Assigned(FForm) and not (csDestroying in FForm.ComponentState) then
SetWindowLong(FForm.Handle, GWL_WNDPROC, NativeInt(FOldWndProc));
System.Classes.FreeObjectInstance(FNewWndProc);
FNewWndProc := nil;
FreeAndNil(FBackground);
inherited Destroy();
end;
//------------------------------------------------------------------------------
procedure TSLTBackgroundWindowHook.FormWndProc(var Message: TMessage);
var
HasHandled: Boolean;
procedure EraseBackGround();
var
Canvas: TCanvas;
CanvasSize: TSize;
CanvasOffset: TPoint;
CaptionWidth: Integer;
begin
if FBackgroundOnTitle then
Message.Result := CallWindowProc(FOldWndProc, FForm.Handle, Message.Msg, Message.WParam, Message.LParam);
if not FBackground.Empty then
begin
if FBackgroundOnTitle then
begin
Canvas := TCanvas.Create();
Canvas.Handle := GetWindowDC(FForm.Handle); // récupère le Handle de la zone de dessin
CaptionWidth := TFontSLTToolHelp.GetTextWidth(Form.Caption, Screen.CaptionFont) + TFontSLTToolHelp.GetTextWidth(' ', Screen.CaptionFont) * 3;
CanvasOffset := TPoint.Create(GetSystemMetrics(SM_CYFIXEDFRAME) + GetSystemMetrics(SM_CXSMSIZE) + CaptionWidth, 0);
if CheckWin32Version(6, 0) and StyleServices.Enabled then
CanvasSize := TSize.Create(Form.Width - (CanvasOffset.X + GetSystemMetrics(SM_CXMIN) - GetSystemMetrics(SM_CXSMICON)), FBackground.Height)
else
CanvasSize := TSize.Create(Form.Width - (CanvasOffset.X + GetSystemMetrics(SM_CXMIN) - GetSystemMetrics(SM_CXSMICON)), GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CYFIXEDFRAME));
end
else
begin
Canvas := FForm.Canvas;
CanvasSize := TSize.Create(Form.ClientWidth, Form.ClientHeight);
CanvasOffset := TPoint.Create(0, 0);
end;
try
with TSLTBackgroundFormDrawer.Create(FBackground, CanvasSize, Canvas) do
try
StartOffSet := CanvasOffset;
Transparent := FBackgroundOnTitle;
HasHandled := EraseBackGround();
finally
Free();
end;
finally
if FBackgroundOnTitle then
begin
ReleaseDC(FForm.Handle, Canvas.Handle); // relache le Handle de la zone de dessin
Canvas.Free();
end;
end;
end;
Message.Result := 0;// renvoie un message nul pour pas que l'ancienne WindowProc "intervienne"
end;
procedure QueryNewPalette();
var
LocalHDC: HDC;
begin
if FBackgroundOnTitle then
LocalHDC := GetWindowDC(FForm.Handle)
else
LocalHDC := GetDC(FForm.Handle); // récupère le Handle de la zone de dessin
try
SelectPalette(LocalHDC, FBackground.Palette, True);
// récupère la palette de l'image que l'on a choisi pour fond
RealizePalette(LocalHDC);// applique la palette
InvalidateRect(FForm.Handle, nil, true); // provoque le raffraichissement de la zone de dessin
finally
ReleaseDC(FForm.Handle, LocalHDC); // relache le Handle de la zone de dessin
end;
Message.Result := 0; // renvoie un message nul pour pas que l'ancienne WindowProc "intervienne"
end;
procedure PaletteChanged();
var
LocalHDC: HDC;
begin
// si le Handle transmis par le message est différent du Handle de la fenêtre
if (Message.WParam <> FForm.Handle) then
begin
if FBackgroundOnTitle then
LocalHDC := GetWindowDC(FForm.Handle)
else
LocalHDC := GetDC(FForm.Handle); // récupère le Handle de la zone de dessin
try
SelectPalette(LocalHDC, FBackground.Palette, True);
// récupère la palette de l'image que l'on a choisi pour fond
RealizePalette(LocalHDC); // applique la palette
UpdateColors(LocalHDC); // raffraichit les couleurs
finally
ReleaseDC(FForm.Handle, LocalHDC); // relache le Handle de la zone de dessin
end;
end;
Message.Result := 0; // renvoie un message nul pour pas que l'ancienne WindowProc "intervienne"
end;
begin
case Message.Msg of
WM_ERASEBKGND: EraseBackGround();
WM_QUERYNEWPALETTE: QueryNewPalette();
WM_PALETTECHANGED: PaletteChanged();
else
case Message.Msg of
WM_HSCROLL, WM_VSCROLL, WM_SIZE : InvalidateRect(FForm.Handle, nil, True);
end;
Message.Result := CallWindowProc(FOldWndProc, FForm.Handle, Message.Msg, Message.WParam, Message.LParam);
end;
end;
//------------------------------------------------------------------------------
procedure TSLTBackgroundWindowHook.LoadBackgroundByResName(const ABackgroundResName: string);
begin
if not StyleServices.Enabled or StyleServices.IsSystemStyle then
begin
if ABackgroundResName <> '' then
begin
if not Assigned(FBackground) then
FBackground := TBitmap.Create();
if not Assigned(FNewWndProc) then
FNewWndProc := System.Classes.MakeObjectInstance(FormWndProc);
try
FBackground.LoadFromResourceName(HInstance, ABackgroundResName);
FOldWndProc := TFarProc(SetWindowLong(FForm.Handle, GWL_WNDPROC, NativeInt(FNewWndProc)));
except
if Assigned(FOldWndProc) then
SetWindowLong(FForm.Handle, GWL_WNDPROC, NativeInt(FOldWndProc));
FreeAndNil(FBackground);
end;
end
else
begin
if Assigned(FOldWndProc) then
SetWindowLong(FForm.Handle, GWL_WNDPROC, NativeInt(FOldWndProc));
System.Classes.FreeObjectInstance(FNewWndProc);
FNewWndProc := nil;
FreeAndNil(FBackground);
end;
end;
end;
{ TSLTBackgroundFormDrawer }
//------------------------------------------------------------------------------
constructor TSLTBackgroundFormDrawer.Create(ABackground: TBitmap; AFormSize: TSize; ACanvas: TCanvas);
begin
inherited Create();
FBackground := ABackground; // Utilise la référence directement !
FhDestDC := ACanvas.Handle;
FDestWidth := AFormSize.Width;
FDestHeight := AFormSize.Height;
FSourceWidth := ABackground.Width;
FSourceHeight := ABackground.Height;
end;
//------------------------------------------------------------------------------
procedure TSLTBackgroundFormDrawer.BackGroungBlt();
var
hSourceDC: HDC;
X, Y, RX, RY, W, H: Integer;
begin
hSourceDC := FBackground.Canvas.Handle;
X := FStartOffSet.X;
RX := FDestWidth;
while RX > 0 do
begin
W := FSourceWidth;
if RX < FSourceWidth then
W := RX;
Y := FStartOffSet.Y;
RY := FDestHeight;
while RY > 0 do
begin
H := FSourceHeight;
if RY < FSourceHeight then
H := RY;
BitBlt(FhDestDC, X, Y, W, H, hSourceDC, 0, 0, SRCCOPY); // Copie l'image sur le "fond" de la zone client
Inc(Y, FSourceHeight);
Dec(RY, FSourceHeight);
end;
Inc(X, FSourceWidth);
Dec(RX, FSourceWidth);
end;
end;
//------------------------------------------------------------------------------
procedure TSLTBackgroundFormDrawer.TransparentBackGroungBlt();
var
hSourceDC: HDC;
X, Y, RX, RY, W, H: Integer;
TransparentColor: TColor;
begin
hSourceDC := FBackground.Canvas.Handle;
TransparentColor := FBackground.TransparentColor;
X := FStartOffSet.X;
RX := FDestWidth;
while RX > 0 do
begin
W := FSourceWidth;
if RX < FSourceWidth then
W := RX;
Y := FStartOffSet.Y;
RY := FDestHeight;
while RY > 0 do
begin
H := FSourceHeight;
if RY < FSourceHeight then
H := RY;
TransparentBlt(FhDestDC, X, Y, W, H, hSourceDC, 0, 0, W, H, TransparentColor); // Copie l'image sur le "fond" de la zone client
Inc(Y, FSourceHeight);
Dec(RY, FSourceHeight);
end;
Inc(X, FSourceWidth);
Dec(RX, FSourceWidth);
end;
end;
//------------------------------------------------------------------------------
function TSLTBackgroundFormDrawer.EraseBackGround(): Boolean;
var
TransparentMode: Boolean;
StyleColor: TColor;
H, S, L, L2: Word;
begin
Result := False;
if (FhDestDC <> 0) and (FDestWidth > 0) and (FDestHeight > 0) then
begin
SelectPalette(FhDestDC, FBackground.Palette, True);
// récupère la palette de l'image que l'on a choisi pour fond
RealizePalette(FhDestDC); // applique la palette
// appelle la fonction "Affichage de l'image"
TransparentMode := FTransparent;
if not TransparentMode and FTransparentOnDarkStyle then
begin
StyleColor := StyleServices.GetStyleColor(scWindow); // semble la même couleur que scGenericBackground
ColorRGBToHLS(ColorToRGB(StyleColor), H, L, S);
ColorRGBToHLS(ColorToRGB(FBackground.TransparentColor), H, L2, S);
TransparentMode := L + 24 < L2;
end;
if TransparentMode then
TransparentBackGroungBlt()
else
BackGroungBlt();
Result := True;
end;
end;
{ TFormScaleSLTAssistant }
//------------------------------------------------------------------------------
class procedure TFormScaleSLTAssistant.CancelZoom(AForm: TForm);
begin
if FCurrentZoom <> FReferenceZoom then
AForm.ScaleBy(FReferenceZoom, FCurrentZoom);
end;
//------------------------------------------------------------------------------
class constructor TFormScaleSLTAssistant.Create();
begin
FReferenceZoom := 100;
end;
//------------------------------------------------------------------------------
class procedure TFormScaleSLTAssistant.ApplyCurrentZoom(AForm: TForm);
begin
if FCurrentZoom <> FReferenceZoom then
begin
AForm.ScaleBy(FCurrentZoom, FReferenceZoom);
if AForm.Width > Screen.WorkAreaWidth then
AForm.Width := Screen.WorkAreaWidth;
if AForm.Height > Screen.WorkAreaHeight then
AForm.Height := Screen.WorkAreaHeight;
if AForm.Top + AForm.Height > Screen.WorkAreaHeight then
AForm.Top := Max(Screen.WorkAreaHeight - AForm.Height, 0);
if AForm.Left + AForm.Width > Screen.WorkAreaWidth then
AForm.Left := Max(Screen.WorkAreaWidth - AForm.Width, 0);
end;
end;
//------------------------------------------------------------------------------
class function TFormScaleSLTAssistant.BuildChangeZoomMenu(AMenuZoom: TMenuItem; AOnClick: TNotifyEvent; ADefaultZoom: Integer = -1): Integer;
var
I: Integer;
DPI, Pourcent: Integer;
Sub: TMenuItem;
begin
AMenuZoom.AutoHotkeys := maManual;
AMenuZoom.Clear();
for I := 0 to 4 do
begin
DPI := 96 + I * 24;
Pourcent := 100 + I * 25;
Sub := TMenuItem.Create(AMenuZoom);
AMenuZoom.Add(Sub);
Sub.Tag := Pourcent;
Sub.RadioItem := True;
Sub.GroupIndex := 1;
Sub.AutoHotkeys := maManual;
Sub.Caption := IntToStr(Pourcent) + ' %';
if CheckWin32Version(6, 0) and (Screen.PixelsPerInch = DPI) then
FReferenceZoom := Pourcent;
if ADefaultZoom in [100..200] then
begin
if ADefaultZoom = Pourcent then
begin
FCurrentZoom := Pourcent;
Sub.Checked := True;
end;
end
else
begin
if CheckWin32Version(6, 0) and (Screen.PixelsPerInch = DPI) then
begin
FCurrentZoom := Pourcent;
Sub.Checked := True;
end
else
begin
if Pourcent = 100 then
begin
FCurrentZoom := Pourcent;
Sub.Checked := True;
end;
end;
end;
Sub.OnClick := AOnClick;
end;
if AMenuZoom.Owner is TForm then
ApplyCurrentZoom(TForm(AMenuZoom.Owner));
Result := FCurrentZoom;
end;
//------------------------------------------------------------------------------
class procedure TFormScaleSLTAssistant.ZoomAllForms(AZoom: Integer);
var
I, M, D: Integer;
begin
if AZoom in [100..200] then
begin
M := AZoom;
D := FCurrentZoom;
FCurrentZoom := M;
for I := 0 to Screen.FormCount - 1 do
Screen.Forms[I].ScaleBy(M, D);
Application.BringToFront();
end;
end;
//------------------------------------------------------------------------------
class procedure TFormScaleSLTAssistant.ZoomClickDefaultEventHandler(Sender: TObject);
begin
if Sender is TMenuItem then
begin
TMenuItem(Sender).Checked := True;
ZoomAllForms(TMenuItem(Sender).Tag);
end;
end;
end. |
Partager