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

C++Builder Discussion :

Texte style surligné (stabilo) [IDE]


Sujet :

C++Builder

  1. #1
    Membre du Club
    Homme Profil pro
    Inscrit en
    Mars 2009
    Messages
    55
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Gard (Languedoc Roussillon)

    Informations forums :
    Inscription : Mars 2009
    Messages : 55
    Points : 42
    Points
    42
    Par défaut Texte style surligné (stabilo)
    Bonjour,

    J'utilise C++builder et:
    J'aimerai surligner (style Stabilo) des parties de textes dans un RichEdit.

    J'avais cela dans Delphi mais pas moyen de le transformer pour c++builder,
    car Fillchar SizeOf etc... n'existe pas dans cbuilder.

    Quelqu'un aurait-il une piste ?
    Merci d'avance...

    Le code pour delphi était:
    ------------------------
    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
    unit Unit1;
    interface
    uses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, RichEdit;
    type
      TForm1 = class(TForm)
        RichEdit1: TRichEdit;
        Button1: TButton;
        Button2: TButton;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
      private
        { Déclarations privées }
      public
        procedure Surligne(const RE: TRichEdit; const Color: TColor);
        procedure SupprSurligne(const RE: TRichEdit);
      end;
    var
      Form1: TForm1;          
    implementation
    {$R *.dfm}
    procedure TForm1.SupprSurligne(const RE: TRichEdit);
    var
      Format : CHARFORMAT2;
    begin
      FillChar(Format, SizeOf(CHARFORMAT2), 0);  
      memset(Format.cbSize := SizeOf(CHARFORMAT2);
      SendMessage(RE.Handle, EM_GETCHARFORMAT, WPARAM(True), LPARAM(@Format));
      Format.dwMask := CFM_BACKCOLOR;
      Format.dwEffects := CFE_AUTOBACKCOLOR;
      SendMessage(RE.Handle, EM_SETCHARFORMAT, SCF_SELECTION, LPARAM(@Format))
    end;
    procedure TForm1.Surligne(const RE: TRichEdit; const Color: TColor);
    var
      Format : CHARFORMAT2;
    begin
      FillChar(Format, SizeOf(CHARFORMAT2), 0);
      Format.cbSize := SizeOf(CHARFORMAT2);
      SendMessage(RE.Handle, EM_GETCHARFORMAT, WPARAM(True), LPARAM(@Format));
      Format.dwMask := CFM_BACKCOLOR;
      Format.crBackColor := ColorToRGB(Color);
      Format.dwEffects := 0; // CFE_AUTOBACKCOLOR
      SendMessage(RE.Handle, EM_SETCHARFORMAT, SCF_SELECTION, LPARAM(@Format))
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      Surligne(RichEdit1, clRed);
    end;
    procedure TForm1.Button2Click(Sender: TObject);
    begin
      SupprSurligne(RichEdit1);
    end;
    end.

  2. #2
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Salut luiso
    Voici un exemple, attention il conserve en memoire la derniere selection faite soit, pour surligner soit, pour effacer le surlignage
    Sur la Form deux TButton un TRichEdit
    Le code
    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
     
    //---------------------------------------------------------------------------
    #include <vcl.h>
    #pragma hdrstop
    #include "Unit1.h"
    //---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm1 *Form1;
    //---------------------------------------------------------------------------
    __fastcall TForm1::TForm1(TComponent* Owner)
            : TForm(Owner)
    {
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
    // Surligne
      Richedit::CHARFORMAT2 Format; //format du texte d'un richedit
      ZeroMemory(&Format, sizeof(Richedit::CHARFORMAT2));
      Format.cbSize = sizeof(Richedit::CHARFORMAT2);
      SendMessage(RichEdit1->Handle, EM_GETCHARFORMAT, WPARAM(True), LPARAM(&Format));
      Format.dwMask = CFM_BACKCOLOR;
      Format.crBackColor = ColorToRGB(clRed); // coleur du surlignage
      Format.dwEffects = 0; // CFE_AUTOBACKCOLOR
      SendMessage(RichEdit1->Handle, EM_SETCHARFORMAT, SCF_SELECTION, LPARAM(&Format));
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Button2Click(TObject *Sender)
    {
    // Efface le surlignage
      Richedit::CHARFORMAT2 Format; //format du texte d'un richedit
      ZeroMemory(&Format, sizeof(Richedit::CHARFORMAT2));
      Format.cbSize = sizeof(Richedit::CHARFORMAT2);
      SendMessage(RichEdit1->Handle, EM_GETCHARFORMAT, WPARAM(True), LPARAM(&Format));
      Format.dwMask = CFM_BACKCOLOR;
      Format.dwEffects = CFE_AUTOBACKCOLOR; // CFE_AUTOBACKCOLOR
      SendMessage(RichEdit1->Handle, EM_SETCHARFORMAT, SCF_SELECTION, LPARAM(&Format));
    }
    //---------------------------------------------------------------------------
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  3. #3
    Membre du Club
    Homme Profil pro
    Inscrit en
    Mars 2009
    Messages
    55
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Gard (Languedoc Roussillon)

    Informations forums :
    Inscription : Mars 2009
    Messages : 55
    Points : 42
    Points
    42
    Par défaut
    Bonsoir Blondelle,

    D'une part:
    Je vois que nous sommes voisin Uzes-Nimes.
    Réponse ultra-rapide, même un dimanche, bravo.

    D'autre part:
    Je te remercie pour ta réponse nickel,
    hormis un petit détail que j'ai bien vite corrigé..
    Il faut retirer les " Richedit:: ", sinon... des erreurs.

    Bonne fin de soirée, @ bientôt. cool:

    Luiso:

  4. #4
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    Chez moi ils etaient obligatoire sinon j'avais une d'ambiguite, l'essentiel c'est que cela fonctionne
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

  5. #5
    Membre du Club
    Homme Profil pro
    Inscrit en
    Mars 2009
    Messages
    55
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Gard (Languedoc Roussillon)

    Informations forums :
    Inscription : Mars 2009
    Messages : 55
    Points : 42
    Points
    42
    Par défaut
    Je pense savoir pourquoi, je suis sous Rad studio XE.
    Il y a pas mal de choses qui ont changés...

  6. #6
    Rédacteur
    Avatar de blondelle
    Homme Profil pro
    Inscrit en
    Mars 2006
    Messages
    2 738
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 2 738
    Points : 3 766
    Points
    3 766
    Par défaut
    J'utilise le bon vieux BCB6
    --
    Plutot que d'essayer de réinventer la roue, apprenons à nous en servir

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Lien image+texte style différent
    Par MasterChief78 dans le forum Mise en page CSS
    Réponses: 5
    Dernier message: 27/08/2009, 20h46
  2. Réponses: 9
    Dernier message: 12/07/2009, 16h00
  3. Contrôle Texte style RTF
    Par nazzguhl dans le forum ASP.NET
    Réponses: 4
    Dernier message: 31/08/2008, 11h54
  4. Encadrer un text style Ovalbox avec un titre
    Par shaiton dans le forum Mise en forme
    Réponses: 10
    Dernier message: 20/05/2007, 19h14
  5. affichage texte style splash screen
    Par scorbo dans le forum MFC
    Réponses: 4
    Dernier message: 13/06/2004, 12h03

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