Code source
Code source

  Présentation
  Unités exemple gratuites
  Unités commercialisées
  Conditions d'utilisation
  Comment acheter
  Vendez vos codes
Unités commercialisées

  LRJ_DosDevice
  LRJ_FileMapped
  LRJ_ModifDateTime
  LRJ_ShellUtils
  LRJ_TokenAPI
  LRJ_WinACL
  LRJ_WinBrowseDialog
  LRJ_WinCreateProcess
  LRJ_WinDesktop
  LRJ_WinDirectories
  LRJ_WinDocRecents
  LRJ_WinDrives
  LRJ_WinFavorisWeb
  LRJ_WinFiles
  LRJ_WinIconNotifArea
  LRJ_WinInternetShortcut
  LRJ_WinMenuFolder
  LRJ_WinModule
  LRJ_WinNetApi
  LRJ_WinNetLocalGroups
  LRJ_WinNetUsers
  LRJ_WinPrivileges
  LRJ_WinProcess
  LRJ_WinRecycleBin
  LRJ_WinRegion
  LRJ_WinRegAppPath
  LRJ_WinShellLink
  LRJ_WinShellUI
  LRJ_WinSID
  LRJ_WinStation
  LRJ_WinTokenGroups
  LRJ_WinTrackChangeDir
  LRJ_WinVolumes
  LRJ_WinWorkingSet

   Accueil | GlobalDesk | Code source Delphi | Développements | Votre compte | Contact   

Code source : unité LRJ_WinRegion




      
Description : cette unité contient les objets LRJ_TWinRegion, LRJ_TControlRegion et LRJ_TFormCtrlsRegion. LRJ_TWinRegion encapsule une région Windows et contient toutes les fonctionnalités liées aux régions Windows. LRJ_TFormCtrlsRegion dérive de TForm et permet de rendre une TForm transparente ne laissant apparaître à l'écran que les TControls contenus dans la TForm. LRJ_TControlRegion encapsule un TControl pour le transformer en région. LRJ_TControlRegion permet en outre de transformer une image transparente en région ce qui peut permettre de donner n'importe quelle forme à n'importe quelle fenêtre.

Pour rendre une TForm transparente, il suffit de remplacer manuellement le TForm de la déclaration de la fiche par LRJ_TFormCtrlsRegion (voir le code de l'application de démonstration à la fin de cette page).

L'unité est livrée avec une application de démonstration ( voir description plus loin ) qui illustre comment transformer une fenêtre en fenêtre transparente.

L'unité LRJ_WinRegion met en oeuvre les fonctions de Windows suivantes :
             CombineRgn
CreateEllipticRgn
CreateEllipticRgnIndirect
CreatePolygonRgn
CreatePolyPolygonRgn
CreateRectRgn
CreateRectRgnIndirect
CreateRoundRectRgn
EqualRgn
ExtCreateRegion
FillRgn
FrameRgn
GetRegionData
GetRgnBox
GetWindowRgn
InvertRgn
OffsetRgn
PaintRgn
RectInRegion
SetRectRgn
SetWindowRgn

Déclarations publiques de l'unité  I  Télécharger l'application de démonstration  I  Exemples d'utilisations

Utilise les unités : Windows, Messages, Classes, Controls, ExtCtrls, Graphics et Forms

Version : 1.1 du 16.05.2009
Auteur : Laurent Hède
Copyright : LorenJo

Nombre de lignes : 670

Réalisée sous : Delphi 6

Systèmes compatibles : NT4, 2000, XP, Vista, serveurs

Prix : 160.00 € H.T.

Déclarations publiques de l'unité :

unit LRJ_WinRegion;

interface

                     Uses
                     Windows,
                     messages,
                     classes,
                     controls,
                     ExtCtrls,
                     Graphics,
                     forms;

type
TWR_Points = array of TPoint;
TWR_PolyCount = array of integer;

    // Encapsule une region
    // PolyFillMode :
    // ALTERNATE Selects alternate mode (fills area between odd-numbered and even-numbered polygon sides on each scan line).
    // WINDING Selects winding mode (fills any region with a nonzero winding value).
    //------------OBJET----------------------------
LRJ_TWinRegion = class(TObject)
   ..............
   procedure DeleteRegion;
   function GetRegionData: PRgnData;
   function IfRegionCreated: boolean;
   function IfPointInRegion(const X, Y : integer): boolean; // Left, top
   function IfRectInRegion(const ARect: TRect): boolean;
   function MoveRegion(const XMove, YMove : integer): boolean; // Left, top
   function IfEgal(const ARegion: LRJ_TWinRegion): boolean;
   function SetPosition(const ALeft, ATop, ARight, ABottom: integer): boolean;
   function GetPosition(var ALeft, ATop, ARight, ABottom: integer): boolean;
   function GetRectPosition: TRect;
   function CreateByPoint(const ALeft, ATop, ARight, ABottom: integer): boolean;
   function CreateByRect(const ARect: TRect): boolean;
   function CreateRoundRect(const ALeft, ATop, ARight, ABottom, AWidthEllipse, AHeightEllipse: integer): boolean;
   function CreateElliptic(const ALeftRect, ATopRect, ARightRect, ABottomRect: integer): boolean;
   function CreateEllipticByRect(const ARect: TRect): boolean;
   function ExtCreate(const AXForm: PXForm; const ARgnDataSize: DWORD; const ARegData: PRgnData): boolean;
   function CreatePolygon(const AArrayOfPoint: TWR_Points; const AQuantPoints: integer;
                                        const PolyFillMode: integer =ALTERNATE): boolean;
   function CreatePolyPolygon(const AArrayOfPoint: TWR_Points; const AArrayOfInteger: TWR_PolyCount;
                                       const AQuantPolyCount: integer; const PolyFillMode: integer =ALTERNATE): boolean;
           //AddRegion : Value Description de CombineFlag
           //RGN_AND Creates the intersection of the two combined regions.
           //RGN_COPY Creates a copy of the region identified by hrgnSrc1.
           //RGN_DIFF Combines the parts of hrgnSrc1 that are not part of hrgnSrc2.
           //RGN_OR Creates the union of two combined regions.
           //RGN_XOR Creates the union of two combined regions except for any overlapping areas
   function AddRegion(const ARegion: LRJ_TWinRegion; const CombineFlag: integer = RGN_OR): boolean;
   function AssignWindowRegion(const AHWND: THandle): boolean; // charge une région à partir d'un HWND de fenetre
      // méthodes nécessitants un HDC
   function FillRegion(const AHDC: HDC; const ABrush: HBRUSH): boolean;
   function FrameRegion(const AHDC: HDC; const ABrush: HBRUSH; const AWidthBord, AHeightBord: integer): boolean;
   function InverseRegion(const AHDC: HDC): boolean;
   function PaintRegion(const AHDC: HDC): boolean;
   function SetWindowRegion(AHandle: HWND; const IfRepaint: boolean = true): boolean;
   //propriétés
   property Region: HRGN read MORegion;
   property PolyFillMode: Integer read MOPolyFillMode;
   end;//-----------FIN--------------------------


   // LRJ_TControlRegion encapsule un TControl et le transforme en une region
    //------------OBJET----------------------------
LRJ_TControlRegion = class(LRJ_TWinRegion)
   ..............
   procedure SetControlParent(const AControl: TControl);
   property TransparentColor: TColor read MOTransparentColor write MOTransparentColor;
   end;//-----------FIN--------------------------


  // TFormRegion est fait pour gérer la création d'une fiche transparente mais pour laquelle tous les controles
  // visuels seront transfomés en régions. 
//------------OBJET----------------------------
LRJ_TFormCtrlsRegion = class(TForm)
   ..............
   procedure ShowRegions; // mettre dans onCreate ou activer lorsque la fiche est visible. Ne pas utiliser dans onShow
   procedure HideRegions;
   property RegionVisible: boolean read MORegionVisible;
   property TransparentColor: TColor read MOTransparentColor write MOTransparentColor;
   property AlwaysInBottom: boolean read MOAlwaysInBottom write SetAlwaysInBottom; // si on entre true, la fiche reste en
                                                                   // arriere plan de toutes les autres fiches. Néanmoins,
                                                                   // elle reste au-dessus des icones
   end;//-----------FIN--------------------------


Application de démonstration
   
Quelle que soit la configuration, le bouton "déplacement" ainsi que l'image permettent de déplacer la fenêtre de la même manière que la barre de menu dans le haut de la fenêtre.
Le bouton "Rendre invisible - Rendre visible" rend la fiche visible ou non (effet transparent). Les autres composants restent visibles mais le fond de la fiche disparaît ou non selon le cas.
Le bouton "Rester en arrière plan/Pas en arrière plan" permet à la fiche soit d'avoir un comportement normal, soit d'être systématiquement en arrière-plan bien que réagissant aux activations de l'utilisateur (la fenêtre peut toujours être déplacée en cliquant sur "déplacement" ou l'image).
Le champ de saisie sert d'exemple et le bouton "Fermer" sert à sortir de l'application.


Exemples d'utilisations

Codes de l'application de démonstration

unit U_InvisibleForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls,

                     LRJ_WinRegion ;

type
  TBackGroundForm = class(LRJ_TFormCtrlsRegion) // modifier TForm en  TFormCtrlsRegion
    Button1: TButton;
    Edit1: TEdit;
    Label1: TLabel;
    Panel1: TPanel;
    Button2: TButton;
    Button3: TButton;
    Image1: TImage;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure GenericMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
  private
  Procedure Int_ChargeBtonFocus; 
  public
  end;

var
  BackGroundForm: TBackGroundForm;

implementation

{$R *.dfm}

{--------------------------------------------------------------}
procedure TBackGroundForm.Int_ChargeBtonFocus;
begin
if not AlwaysInBottom then
  Button3.Caption := 'Rester en arrière plan'
else
  Button3.Caption := 'Pas en arrière plan';
end;
{--------------------------------------------------------------}
procedure TBackGroundForm.Button1Click(Sender: TObject);
begin
Close;
end;
{--------------------------------------------------------------}
procedure TBackGroundForm.FormCreate(Sender: TObject);
begin
Int_ChargeBtonFocus;
end;
{--------------------------------------------------------------}
procedure TBackGroundForm.GenericMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
releasecapture;
BackGroundForm.perform(WM_SYSCOMMAND, 61458, 0 );
end;
{--------------------------------------------------------------}
procedure TBackGroundForm.Button2Click(Sender: TObject);
begin
if Not RegionVisible then
  begin
  TransparentColor := Image1.Canvas.Pixels[0,0];
  Button2.Caption := 'Rendre visible';
  ShowRegions;
  end
else
  begin
  Button2.Caption := 'Rendre invisible';
  HideRegions;
  end;
end;
{--------------------------------------------------------------}
procedure TBackGroundForm.Button3Click(Sender: TObject);
begin
AlwaysInBottom := Not AlwaysInBottom;
Int_ChargeBtonFocus;
end;
{--------------------------------------------------------------}
end.


Vous n'avez pas trouvé d'exemple répondant à votre problématique ?
Cliquez sur ce lien.


 Accueil | GlobalDesk | Code source Delphi | Développements | Votre compte | Contact 
Copyright © LorenJo 2000-2009    Notice légale