IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Delphi Discussion :

Griser une fenêtre en arrière plan


Sujet :

Delphi

  1. #1
    Membre habitué
    Inscrit en
    Octobre 2002
    Messages
    343
    Détails du profil
    Informations forums :
    Inscription : Octobre 2002
    Messages : 343
    Points : 152
    Points
    152
    Par défaut Griser une fenêtre en arrière plan
    Bonjour,

    Quelqu'un à déjà essayer de griser les fenêtres en arrière plan ? J'aimerai assombrir les fenêtres qui sont en arrière plan afin de ne pas surcharger mon application avec des fenêtres superposé.


    Merchiche

  2. #2
    Membre émérite
    Avatar de Thierry Laborde
    Homme Profil pro
    N/A
    Inscrit en
    Avril 2002
    Messages
    1 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : N/A

    Informations forums :
    Inscription : Avril 2002
    Messages : 1 391
    Points : 2 529
    Points
    2 529
    Par défaut
    Salut,

    J'avais prévu de faire paraitre sur les sources de developpez.com une unité avec des fonctions qui permettent justement de griser une fenêtre. Je profite donc de ce message pour diffuser les sources ici, et je pense qu'il serait bien que les modos diffuse ça dans la partie sources Delphi du site.
    J'en profite également pour remercier sub0 qui m'a permis grace à ces différentes réponses dans des posts à m'aider a réaliser cette fonction (Rendont à césar ce qui est à césar, une grande partie du mérite de cette fonction lui revient ).

    voici donc le source de l'unité :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    {*------------------------------------------------------------------------------
     Unité permettant de griser une form lorsqu'elle appelle un showmodal pour
     en afficher une autre
     
     @Author    tiki06
     @Version   02-août-2006 Version initiale
    -------------------------------------------------------------------------------}
    Unit UGriserForm;
     
    Interface
     
    Uses Windows, Forms, Types, Graphics;
     
     
    const
      PIXELCOUNTMAX = 32768;
      WS_EX_LAYERED = $80000;
     
     
    type
      pRGBArray  = ^TRGBArray;
      TRGBArray   = ARRAY[0..PIXELCOUNTMAX-1] OF TRGBTriple;
     
     
     
    Procedure FusionerImage(FusionForm: TForm; BmpGrise: TBitmap);
    Function  CustomShowModal(Fenetre: TForm):integer;
     
     
    implementation
     
     
    {*------------------------------------------------------------------------------
      Fonction pour fusioner la form et l'image grisé
     
      @param    FusionForm       Form a fusioner
      @param    BmpGrise         Bitmap de l'image grisé
    -------------------------------------------------------------------------------}
    Procedure FusionerImage(FusionForm: TForm; BmpGrise: TBitmap);
    Var
      Size                : PSIZE;
      TopLeft, BmpTopLeft : TPoint;
      Blend               : TBlendFunction;
    Begin
      With FusionForm Do
      Begin
        SetWindowLong(Handle, GWL_EXSTYLE,
          GetWindowLong(Handle, GWL_EXSTYLE) Or WS_EX_LAYERED);
        New(Size);
        Size.cx := Width;
        Size.cy := Height;
        TopLeft := BoundsRect.TopLeft;
        BmpTopLeft := Point(0, 0);
        With Blend Do Begin
          BlendOp := 0;
          BlendFlags := 0;
          SourceConstantAlpha := 255;
          AlphaFormat := 0;
        End;
        BmpGrise.PixelFormat := pf32bit;
        UpdateLayeredWindow(Handle, GetDC(0), @TopLeft, Size,
          BmpGrise.Canvas.handle, @BmpTopLeft, 0, @Blend, 2);
      End;
    End;
     
    {*----------------------------------------------------------------------------
      Fonction pour afficher une fenêtre en showmodal et griser celle qui est
      active pendant l'appel du showmodal
     
      @param    Fenetre        Form a afficher en Showmodal
    -----------------------------------------------------------------------------}
    Function CustomShowModal(Fenetre: TForm):integer;
    var
      WindowHandle    : THandle;
      deviceContext   : HDC;
      BitmapForm      : Tbitmap;
      icolor          : integer;
      r,g,b:byte;
      iheight,iwidth  : integer;
      RowOriginal     : pRGBArray;
      FormGrise       : TForm;
    begin
      WindowHandle:= Screen.ActiveForm.Handle;
      deviceContext:= GetWindowDC(WindowHandle);
      try
        BitmapForm             := Tbitmap.Create;
        BitmapForm.PixelFormat := pf24bit;
        BitmapForm.Width       := Screen.ActiveForm.Width;
        BitmapForm.Height      := Screen.ActiveForm.Height;
     
        BitBlt(BitmapForm.Canvas.Handle, 0, 0, BitmapForm.Width, BitmapForm.Height,
          deviceContext, 0, 0, SRCCOPY);
     
      finally
        ReleaseDC(WindowHandle, deviceContext);
      end;
     
      for iHeight := 0 to BitmapForm.height-1 do
      begin
        RowOriginal  := pRGBArray(BitmapForm.Scanline[iHeight]);
        for iWidth := 0 to BitmapForm.width-1 do
        begin
          r:=RowOriginal[iWidth].rgbtRed;
          g:=RowOriginal[iWidth].rgbtGreen;
          b:=RowOriginal[iWidth].rgbtBlue;
          icolor:=(r+g+b) div 3;
          RowOriginal[iWidth].rgbtRed   := icolor;
          RowOriginal[iWidth].rgbtGreen := icolor;
          RowOriginal[iWidth].rgbtBlue  := icolor;
        end;
      end;
     
      FormGrise                := Tform.Create(Screen.ActiveForm);
      FormGrise.Name           := 'GrayscaleForm';
      FormGrise.Left           := Screen.ActiveForm.Left;
      FormGrise.Top            := Screen.ActiveForm.Top;
      FormGrise.Width          := Screen.ActiveForm.Width;
      FormGrise.Height         := Screen.ActiveForm.Height;
      FormGrise.DoubleBuffered := True;
      FormGrise.BorderIcons    := Screen.ActiveForm.BorderIcons;
      FormGrise.BorderStyle    := Screen.ActiveForm.BorderStyle;
      FormGrise.Show;
     
      FusionerImage(FormGrise,BitmapForm);
      FormGrise.BringToFront;
     
      BitmapForm.Free;
     
      Result:=Fenetre.ShowModal;
      if FormGrise<>nil then FormGrise.Release;
    end;
     
     
    End.
    en fait, au lieu d'appeller un showmodal d'une autre fenêtre il suffit d'appeller la fonction CustomShowModal en lui passant en paramètre la fenêtre que vous souhaitez afficher en showmodal. Et automatiquement la fonction grisera la fenêtre active (Donc celle qui appelle le showmodal) et affichera l'autre fenêtre. il est clair qu'en terme d'ergonomie c'est bien plus pratique pour l'utilisateur.

    Si vous avez des questions n'hésitez pas.

  3. #3
    Membre habitué
    Inscrit en
    Octobre 2002
    Messages
    343
    Détails du profil
    Informations forums :
    Inscription : Octobre 2002
    Messages : 343
    Points : 152
    Points
    152
    Par défaut C++
    Chouette, j'ai bien fait de poser la question dans le forum DELPHI. Le petit hic, est que je développe en C++ Builder, et je n'ai jamais fait de pascal. Bon, je vais essayer de transposer tout ça. Quand c'est oki, je fais signe, et je diffuserai le source sur le forum de c++ sans oublier les remerciments à césar... je suis impatient de tester tout ça.
    ... Ca ne va pas être facile..........

  4. #4
    Modérateur
    Avatar de Rayek
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2005
    Messages
    5 235
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 50
    Localisation : France, Haute Savoie (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2005
    Messages : 5 235
    Points : 8 504
    Points
    8 504
    Par défaut
    Citation Envoyé par kurkaine
    Le petit hic, est que je développe en C++ Builder, et je n'ai jamais fait de pascal.
    Alors pourquoi poster sur le forum Delphi
    Modérateur Delphi

    Le guide du bon forumeur :
    __________
    Rayek World : Youtube Facebook

  5. #5
    Membre expert
    Avatar de aityahia
    Homme Profil pro
    CIEPTAL CARS SPA
    Inscrit en
    Mars 2006
    Messages
    1 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Algérie

    Informations professionnelles :
    Activité : CIEPTAL CARS SPA
    Secteur : Transports

    Informations forums :
    Inscription : Mars 2006
    Messages : 1 938
    Points : 3 329
    Points
    3 329
    Par défaut
    j'ai bien tester ton code sa marche tres bien j uste que y a le caption de la form en arriere plan qui change le temps d'une fraction de second (assez long pour etre remarquer essai de voir si en peut pas améliorer sa)

  6. #6
    Membre expert
    Avatar de aityahia
    Homme Profil pro
    CIEPTAL CARS SPA
    Inscrit en
    Mars 2006
    Messages
    1 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Algérie

    Informations professionnelles :
    Activité : CIEPTAL CARS SPA
    Secteur : Transports

    Informations forums :
    Inscription : Mars 2006
    Messages : 1 938
    Points : 3 329
    Points
    3 329
    Par défaut
    j'ai fait une petit modification.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    {*------------------------------------------------------------------------------
     Unité permettant de griser une form lorsqu'elle appelle un showmodal pour
     en afficher une autre
     
     @Author    tiki06
     @Version   02-août-2006 Version initiale
    -------------------------------------------------------------------------------}
    Unit UGriserForm;
     
    Interface
     
    Uses Windows, Forms, Types, Graphics;
     
     
    const
      PIXELCOUNTMAX = 32768;
      WS_EX_LAYERED = $80000;
     
     
    type
      pRGBArray  = ^TRGBArray;
      TRGBArray   = ARRAY[0..PIXELCOUNTMAX-1] OF TRGBTriple;
     
     
     
    Procedure FusionerImage(FusionForm: TForm; BmpGrise: TBitmap);
    Function  CustomShowModal(Fenetre: TForm):integer;
     
     
    implementation
     
     
    {*------------------------------------------------------------------------------
      Fonction pour fusioner la form et l'image grisé
     
      @param    FusionForm       Form a fusioner
      @param    BmpGrise         Bitmap de l'image grisé
    -------------------------------------------------------------------------------}
    Procedure FusionerImage(FusionForm: TForm; BmpGrise: TBitmap);
    Var
      Size                : PSIZE;
      TopLeft, BmpTopLeft : TPoint;
      Blend               : TBlendFunction;
    Begin
      With FusionForm Do
      Begin
        SetWindowLong(Handle, GWL_EXSTYLE,
          GetWindowLong(Handle, GWL_EXSTYLE) Or WS_EX_LAYERED);
        New(Size);
        Size.cx := Width;
        Size.cy := Height;
        TopLeft := BoundsRect.TopLeft;
        BmpTopLeft := Point(0, 0);
        With Blend Do Begin
          BlendOp := 0;
          BlendFlags := 0;
          SourceConstantAlpha := 255;
          AlphaFormat := 0;
        End;
        BmpGrise.PixelFormat := pf32bit;
        UpdateLayeredWindow(Handle, GetDC(0), @TopLeft, Size,
          BmpGrise.Canvas.handle, @BmpTopLeft, 0, @Blend, 2);
      End;
    End;
     
    {*----------------------------------------------------------------------------
      Fonction pour afficher une fenêtre en showmodal et griser celle qui est
      active pendant l'appel du showmodal
     
      @param    Fenetre        Form a afficher en Showmodal
    -----------------------------------------------------------------------------}
    Function CustomShowModal(Fenetre: TForm):integer;
    var
      WindowHandle    : THandle;
      deviceContext   : HDC;
      BitmapForm      : Tbitmap;
      icolor          : integer;
      r,g,b:byte;
      iheight,iwidth  : integer;
      RowOriginal     : pRGBArray;
      FormGrise       : TForm;
    begin
      WindowHandle:= Screen.ActiveForm.Handle;
      deviceContext:= GetWindowDC(WindowHandle);
      try
        BitmapForm             := Tbitmap.Create;
        BitmapForm.PixelFormat := pf24bit;
        BitmapForm.Width       := Screen.ActiveForm.Width;
        BitmapForm.Height      := Screen.ActiveForm.Height;
     
        BitBlt(BitmapForm.Canvas.Handle, 0, 0, BitmapForm.Width, BitmapForm.Height,
          deviceContext, 0, 0, SRCCOPY);
     
      finally
        ReleaseDC(WindowHandle, deviceContext);
      end;
     
      for iHeight := 0 to BitmapForm.height-1 do
      begin
        RowOriginal  := pRGBArray(BitmapForm.Scanline[iHeight]);
        for iWidth := 0 to BitmapForm.width-1 do
        begin
          r:=RowOriginal[iWidth].rgbtRed;
          g:=RowOriginal[iWidth].rgbtGreen;
          b:=RowOriginal[iWidth].rgbtBlue;
          icolor:=(r+g+b) div 3;
          RowOriginal[iWidth].rgbtRed   := icolor;
          RowOriginal[iWidth].rgbtGreen := icolor;
          RowOriginal[iWidth].rgbtBlue  := icolor;
        end;
      end;
     
      FormGrise                := Tform.Create(Screen.ActiveForm);
      FormGrise.Name           := Screen.ActiveForm.Caption;  <-  j'ai rajouter sa **********
      FormGrise.Left           := Screen.ActiveForm.Left;
      FormGrise.Top            := Screen.ActiveForm.Top;
      FormGrise.Width          := Screen.ActiveForm.Width;
      FormGrise.Height         := Screen.ActiveForm.Height;
      FormGrise.DoubleBuffered := True;
      FormGrise.BorderIcons    := Screen.ActiveForm.BorderIcons;
      FormGrise.BorderStyle    := Screen.ActiveForm.BorderStyle;
      FormGrise.Show;
     
      FusionerImage(FormGrise,BitmapForm);
      FormGrise.BringToFront;
     
      BitmapForm.Free;
     
      Result:=Fenetre.ShowModal;
      if FormGrise<>nil then FormGrise.Release;
    end;
     
     
    End.

  7. #7
    Membre émérite
    Avatar de Thierry Laborde
    Homme Profil pro
    N/A
    Inscrit en
    Avril 2002
    Messages
    1 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : N/A

    Informations forums :
    Inscription : Avril 2002
    Messages : 1 391
    Points : 2 529
    Points
    2 529
    Par défaut
    Salut,

    Bien vu aityahia et merci pour la modif. je n'avais en effet pas remarqué ce point là.

  8. #8
    Membre habitué
    Inscrit en
    Octobre 2002
    Messages
    343
    Détails du profil
    Informations forums :
    Inscription : Octobre 2002
    Messages : 343
    Points : 152
    Points
    152
    Par défaut

    kurkaine a écrit :
    Le petit hic, est que je développe en C++ Builder, et je n'ai jamais fait de pascal.

    Alors pourquoi poster sur le forum Delphi
    Parceque personne n'a pu me répondre sur le forum C++ Builder, hélas. Vu que c'est la même API, je me suis dit que ça peut valoir le coup. Mais je t'avoue que je galère pas mal. En tout cas, c'est mieux que rien.

  9. #9
    Membre émérite
    Avatar de Thierry Laborde
    Homme Profil pro
    N/A
    Inscrit en
    Avril 2002
    Messages
    1 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : N/A

    Informations forums :
    Inscription : Avril 2002
    Messages : 1 391
    Points : 2 529
    Points
    2 529
    Par défaut
    En fait je fais encore une petite modif :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    {*------------------------------------------------------------------------------
     Unité permettant de griser une form lorsqu'elle appelle un showmodal pour
     en afficher une autre
     
     @Author    tiki06 (Avec l'aide de Sub0)
     @Version   02-août-2006 Version initiale
    -------------------------------------------------------------------------------}
    Unit UGriserForm;
     
    Interface
     
    Uses Windows, Forms, Types, Graphics;
     
     
    const
      PIXELCOUNTMAX = 32768;
      WS_EX_LAYERED = $80000;
     
     
    type
      pRGBArray  = ^TRGBArray;
      TRGBArray   = ARRAY[0..PIXELCOUNTMAX-1] OF TRGBTriple;
     
     
     
    Procedure FusionerImage(FusionForm: TForm; BmpGrise: TBitmap);
    Function  CustomShowModal(Fenetre: TForm):integer;
     
     
    implementation
     
     
    {*------------------------------------------------------------------------------
      Fonction pour fusioner la form et l'image grisé
     
      @param    FusionForm       Form a fusioner
      @param    BmpGrise         Bitmap de l'image grisé
    -------------------------------------------------------------------------------}
    Procedure FusionerImage(FusionForm: TForm; BmpGrise: TBitmap);
    Var
      Size                : PSIZE;
      TopLeft, BmpTopLeft : TPoint;
      Blend               : TBlendFunction;
    Begin
      With FusionForm Do
      Begin
        SetWindowLong(Handle, GWL_EXSTYLE,
          GetWindowLong(Handle, GWL_EXSTYLE) Or WS_EX_LAYERED);
        New(Size);
        Size.cx := Width;
        Size.cy := Height;
        TopLeft := BoundsRect.TopLeft;
        BmpTopLeft := Point(0, 0);
        With Blend Do Begin
          BlendOp := 0;
          BlendFlags := 0;
          SourceConstantAlpha := 255;
          AlphaFormat := 0;
        End;
        BmpGrise.PixelFormat := pf32bit;
        UpdateLayeredWindow(Handle, GetDC(0), @TopLeft, Size,
          BmpGrise.Canvas.handle, @BmpTopLeft, 0, @Blend, 2);
      End;
    End;
     
    {*----------------------------------------------------------------------------
      Fonction pour afficher une fenêtre en showmodal et griser celle qui est
      active pendant l'appel du showmodal
     
      @param    Fenetre        Form a afficher en Showmodal
    -----------------------------------------------------------------------------}
    Function CustomShowModal(Fenetre: TForm):integer;
    var
      WindowHandle    : THandle;
      deviceContext   : HDC;
      BitmapForm      : Tbitmap;
      icolor          : integer;
      r,g,b:byte;
      iheight,iwidth  : integer;
      RowOriginal     : pRGBArray;
      FormGrise       : TForm;
    begin
      WindowHandle:= Screen.ActiveForm.Handle;
      deviceContext:= GetWindowDC(WindowHandle);
      try
        BitmapForm             := Tbitmap.Create;
        BitmapForm.PixelFormat := pf24bit;
        BitmapForm.Width       := Screen.ActiveForm.Width;
        BitmapForm.Height      := Screen.ActiveForm.Height;
     
        BitBlt(BitmapForm.Canvas.Handle, 0, 0, BitmapForm.Width, BitmapForm.Height,
          deviceContext, 0, 0, SRCCOPY);
     
      finally
        ReleaseDC(WindowHandle, deviceContext);
      end;
     
      for iHeight := 0 to BitmapForm.height-1 do
      begin
        RowOriginal  := pRGBArray(BitmapForm.Scanline[iHeight]);
        for iWidth := 0 to BitmapForm.width-1 do
        begin
          r:=RowOriginal[iWidth].rgbtRed;
          g:=RowOriginal[iWidth].rgbtGreen;
          b:=RowOriginal[iWidth].rgbtBlue;
          icolor:=(r+g+b) div 3;
          RowOriginal[iWidth].rgbtRed   := icolor;
          RowOriginal[iWidth].rgbtGreen := icolor;
          RowOriginal[iWidth].rgbtBlue  := icolor;
        end;
      end;
     
      FormGrise                := Tform.Create(Screen.ActiveForm);
      FormGrise.Name           := 'GrayscaleForm';            <- J'ai remis cette ligne comme avant *****
      FormGrise.Caption        := Screen.ActiveForm.Caption;  <-  j'ai rajouté cette ligne *****
      FormGrise.Left           := Screen.ActiveForm.Left;
      FormGrise.Top            := Screen.ActiveForm.Top;
      FormGrise.Width          := Screen.ActiveForm.Width;
      FormGrise.Height         := Screen.ActiveForm.Height;
      FormGrise.DoubleBuffered := True;
      FormGrise.BorderIcons    := Screen.ActiveForm.BorderIcons;
      FormGrise.BorderStyle    := Screen.ActiveForm.BorderStyle;
      FormGrise.Show;
     
      FusionerImage(FormGrise,BitmapForm);
      FormGrise.BringToFront;
     
      BitmapForm.Free;
     
      Result:=Fenetre.ShowModal;
      if FormGrise<>nil then FormGrise.Release;
    end;
     
     
    End.
    En effet la solution de aityahia posait un problème si on avait un caption avec un espace. Par exemple 'Form de test'. car il essayait de donner ce texte la comme nom à la form, ce qui n'est pas possible.

  10. #10
    Membre expert
    Avatar de aityahia
    Homme Profil pro
    CIEPTAL CARS SPA
    Inscrit en
    Mars 2006
    Messages
    1 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Algérie

    Informations professionnelles :
    Activité : CIEPTAL CARS SPA
    Secteur : Transports

    Informations forums :
    Inscription : Mars 2006
    Messages : 1 938
    Points : 3 329
    Points
    3 329
    Par défaut
    c 'est plus judicieux, comme sa on aura pas la contrainte du nom et du caption qu’il soit identique.

    sa serai bien de faire un composant avec l'unitée.

  11. #11
    Membre émérite
    Avatar de Thierry Laborde
    Homme Profil pro
    N/A
    Inscrit en
    Avril 2002
    Messages
    1 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : N/A

    Informations forums :
    Inscription : Avril 2002
    Messages : 1 391
    Points : 2 529
    Points
    2 529
    Par défaut
    sa serai bien de faire un composant avec l'unitée.
    Je suis en train de m'en occuper. Ensuite je posterai ça aux modérateurs pour que ça soit mis dans la rubrique Sources delphi du site. Je mettrais le composant et l'unité, comme ça chacuns prendra ce qu'il préfère.

  12. #12
    Membre expert
    Avatar de aityahia
    Homme Profil pro
    CIEPTAL CARS SPA
    Inscrit en
    Mars 2006
    Messages
    1 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Algérie

    Informations professionnelles :
    Activité : CIEPTAL CARS SPA
    Secteur : Transports

    Informations forums :
    Inscription : Mars 2006
    Messages : 1 938
    Points : 3 329
    Points
    3 329
    Par défaut
    salut

    j'ai rajouté un test pour gérer le cas ou la fenetre active est une MDIChild elle n'a pas le meme parent


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     if Screen.ActiveForm.FormStyle = FsMdiChild then
       begin
      FormGrise.Top            := Screen.ActiveForm.ClientOrigin.Y-(Screen.ActiveForm.Height-Screen.ActiveForm.ClientHeight)+4;
      FormGrise.Left           := Screen.ActiveForm.Left+2;
        end
        else
       Begin
        FormGrise.Top            := Screen.ActiveForm.Top;
        FormGrise.Left           := Screen.ActiveForm.Left;
       end;
    on peut améliorer sa j'ai pas pu récupérer le BorderWidth de la fenetre parent.

  13. #13
    Membre habitué
    Inscrit en
    Octobre 2002
    Messages
    343
    Détails du profil
    Informations forums :
    Inscription : Octobre 2002
    Messages : 343
    Points : 152
    Points
    152
    Par défaut Transcription en c++
    Je précise encore une fois, que j'ai posté dans un forum delphi car personne n'a pu me répondre dans celui de c++ builder. Donc j'essaie d'adapter le code en c++.

    Est-ce que je pourrais avoir une précision car j'ai des erreurs de compilations sur
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Result:=Fenetre.ShowModal;
    Quel est le type de Result, et ou est déclaré cet attribut.

    Et
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    RowOriginal  := pRGBArray(BitmapForm.Scanline[iHeight]);
    Je ne comprends pas quel est le sens de cette ligne ? Qq'un pourrait détaillé en algorithmie qu'est ce qu'on effecture sur cette ligne ?

    Enfin
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
      pRGBArray  = ^TRGBArray;
      TRGBArray   = ARRAY[0..PIXELCOUNTMAX-1] OF TRGBTriple;
    Si j'ai bien compris TRGBArrayt est un tableau de type TRGBTriple. Et pRGBArray est pointeur d'une instance de TRGBArray ??

    Merci de m'aider. Encore une fois désolé de m'éloiger du sujet...

  14. #14
    Membre expert
    Avatar de aityahia
    Homme Profil pro
    CIEPTAL CARS SPA
    Inscrit en
    Mars 2006
    Messages
    1 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Algérie

    Informations professionnelles :
    Activité : CIEPTAL CARS SPA
    Secteur : Transports

    Informations forums :
    Inscription : Mars 2006
    Messages : 1 938
    Points : 3 329
    Points
    3 329
    Par défaut
    le type de résult est un entier (Int) c'est le resultat de la fonction.
    Result n'est pas déclarer c un mot clé c le type de la fonction

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Function  CustomShowModal(Fenetre: TForm):integer;
    est equivalent a


  15. #15
    Membre émérite
    Avatar de Thierry Laborde
    Homme Profil pro
    N/A
    Inscrit en
    Avril 2002
    Messages
    1 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : N/A

    Informations forums :
    Inscription : Avril 2002
    Messages : 1 391
    Points : 2 529
    Points
    2 529
    Par défaut
    J'ai donc modifié pour les fenêtre MDI en partant de ce que tu avais fait aityahia. Voila la fonction CustomShowModal modifiée :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    Function CustomShowModal(Fenetre: TForm):integer;
    var
      WindowHandle          : THandle;
      deviceContext         : HDC;
      BitmapForm            : Tbitmap;
      icolor                : integer;
      r,g,b                 : byte;
      iheight,iwidth        : integer;
      RowOriginal           : pRGBArray;
      FormGrise             : TForm;
      PosLeft,PosTop,Delta  : Integer;
    begin
      WindowHandle:= Screen.ActiveForm.Handle;
      deviceContext:= GetWindowDC(WindowHandle);
      try
        BitmapForm             := Tbitmap.Create;
        BitmapForm.PixelFormat := pf24bit;
        BitmapForm.Width       := Screen.ActiveForm.Width;
        BitmapForm.Height      := Screen.ActiveForm.Height;
     
        BitBlt(BitmapForm.Canvas.Handle, 0, 0, BitmapForm.Width, BitmapForm.Height,
          deviceContext, 0, 0, SRCCOPY);
     
      finally
        ReleaseDC(WindowHandle, deviceContext);
      end;
     
      for iHeight := 0 to BitmapForm.height-1 do
      begin
        RowOriginal  := pRGBArray(BitmapForm.Scanline[iHeight]);
        for iWidth := 0 to BitmapForm.width-1 do
        begin
          r:=RowOriginal[iWidth].rgbtRed;
          g:=RowOriginal[iWidth].rgbtGreen;
          b:=RowOriginal[iWidth].rgbtBlue;
          icolor:=(r+g+b) div 3;
          RowOriginal[iWidth].rgbtRed   := icolor;
          RowOriginal[iWidth].rgbtGreen := icolor;
          RowOriginal[iWidth].rgbtBlue  := icolor;
        end;
      end;
     
      FormGrise                := Tform.Create(Screen.ActiveForm);
      FormGrise.Name           := 'GrayscaleForm';
      FormGrise.Caption        := Screen.ActiveForm.Caption;
     
      if Screen.ActiveForm.FormStyle = FsMdiChild then
      begin
        PosTop                 := Screen.ActiveForm.ClientOrigin.Y-(Screen.ActiveForm.Height-Screen.ActiveForm.ClientHeight);
        PosLeft                := Screen.ActiveForm.ClientOrigin.X-(Screen.ActiveForm.Width-Screen.ActiveForm.ClientWidth);
        Delta                  := round((Application.mainform.Width-Application.MainForm.ClientWidth)/2);
        FormGrise.Top          := PosTop+Delta;
        FormGrise.left         := PosLeft+Delta;
      end
      else
      Begin
        FormGrise.Top          := Screen.ActiveForm.Top;
        FormGrise.Left         := Screen.ActiveForm.Left;
      end;
      FormGrise.Width          := Screen.ActiveForm.Width;
      FormGrise.Height         := Screen.ActiveForm.Height;
      FormGrise.DoubleBuffered := True;
      FormGrise.BorderIcons    := Screen.ActiveForm.BorderIcons;
      FormGrise.BorderStyle    := Screen.ActiveForm.BorderStyle;
      FormGrise.Show;
     
      FusionerImage(FormGrise,BitmapForm);
      FormGrise.BringToFront;
     
      BitmapForm.Free;
     
      Result:=Fenetre.ShowModal;
      if FormGrise<>nil then FormGrise.Release;
    end;

  16. #16
    Membre émérite
    Avatar de Thierry Laborde
    Homme Profil pro
    N/A
    Inscrit en
    Avril 2002
    Messages
    1 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : N/A

    Informations forums :
    Inscription : Avril 2002
    Messages : 1 391
    Points : 2 529
    Points
    2 529
    Par défaut
    Pour kurkaine, voici quelques explications en plus en espérant t'aider.


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
      for iHeight := 0 to BitmapForm.height-1 do
      begin
        RowOriginal  := pRGBArray(BitmapForm.Scanline[iHeight]);
        for iWidth := 0 to BitmapForm.width-1 do
        begin
          r:=RowOriginal[iWidth].rgbtRed;
          g:=RowOriginal[iWidth].rgbtGreen;
          b:=RowOriginal[iWidth].rgbtBlue;
          icolor:=(r+g+b) div 3;
          RowOriginal[iWidth].rgbtRed   := icolor;
          RowOriginal[iWidth].rgbtGreen := icolor;
          RowOriginal[iWidth].rgbtBlue  := icolor;
        end;
      end;
    Je parcours toutes les lignes de mon bitmap, je stocke dans Roworiginal chaque ligne (En fait je stocke un tableau des couleurs de chaque pixel de ma ligne). Ensuite sur chaque ligne je parcours tous les pixels récupère la couleur et la modifie pour griser l'ensemble.

    Malheureusement je ne pourrais pas t'aider pour transcrire ça en C++.

    En espérant avoir put t'aider.

  17. #17
    Membre expert
    Avatar de aityahia
    Homme Profil pro
    CIEPTAL CARS SPA
    Inscrit en
    Mars 2006
    Messages
    1 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Algérie

    Informations professionnelles :
    Activité : CIEPTAL CARS SPA
    Secteur : Transports

    Informations forums :
    Inscription : Mars 2006
    Messages : 1 938
    Points : 3 329
    Points
    3 329
    Par défaut
    y a toujour un petit décalage

    comme ça c'est mieux
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     Delta := round((Application.mainform.Width-Application.MainForm.ClientWidth)/2)-1;

  18. #18
    Membre émérite
    Avatar de Thierry Laborde
    Homme Profil pro
    N/A
    Inscrit en
    Avril 2002
    Messages
    1 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : N/A

    Informations forums :
    Inscription : Avril 2002
    Messages : 1 391
    Points : 2 529
    Points
    2 529
    Par défaut
    Citation Envoyé par aityahia
    y a toujour un petit décalage

    comme ça c'est mieux
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     Delta := round((Application.mainform.Width-Application.MainForm.ClientWidth)/2)-1;
    Pourtant moi je n'avais pas de décalage. Par contre avec ta modif j'ai un décalage. Quelle est la config (propriétés) de tes fenêtres et ton environement ?

  19. #19
    Membre expert
    Avatar de aityahia
    Homme Profil pro
    CIEPTAL CARS SPA
    Inscrit en
    Mars 2006
    Messages
    1 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Algérie

    Informations professionnelles :
    Activité : CIEPTAL CARS SPA
    Secteur : Transports

    Informations forums :
    Inscription : Mars 2006
    Messages : 1 938
    Points : 3 329
    Points
    3 329
    Par défaut
    Border style BsSingle

    possible que c'est du a ça je fait le test sinon en rajoute les test.

  20. #20
    Membre émérite
    Avatar de Thierry Laborde
    Homme Profil pro
    N/A
    Inscrit en
    Avril 2002
    Messages
    1 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : N/A

    Informations forums :
    Inscription : Avril 2002
    Messages : 1 391
    Points : 2 529
    Points
    2 529
    Par défaut
    c'est bien ça le problème. moi j'avais un borderstyle à BsSizeable. Apparement ça fait la même chose avec BsToolWindow. c'est nul je pensais que de faire justement la différence entre Width et clientWidth te donnerai la bonne valeur quel que soit le border que l'on a. Je vas faire d'autres tests du coup (en changeant Borderwidth...etc).

Discussions similaires

  1. Capturer l'image d'une fenêtre en arrière plan
    Par Etanne dans le forum Général Dotnet
    Réponses: 3
    Dernier message: 09/06/2013, 01h29
  2. Bouger la souris sur une fenêtre en arrière plan
    Par youtpout978 dans le forum C#
    Réponses: 4
    Dernier message: 26/06/2011, 13h13
  3. comment lancer une fenètre en arrièr plan
    Par moon93 dans le forum wxPython
    Réponses: 2
    Dernier message: 16/07/2007, 09h25
  4. Griser une fenêtre en arrière plan
    Par kurkaine dans le forum C++Builder
    Réponses: 8
    Dernier message: 04/08/2006, 14h28

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo