begin process at 2012 05 28 19:13:47
  Trouver un code source :
 
dans
 
Accueil > Forum > 

Archive C/C++

 > 

Archives

 > 

Au secours

 > 

les composants en c++ builder


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

les composants en c++ builder

mardi 10 août 2004 à 18:27:58 | les composants en c++ builder

kiki007

bonjour à tous,
j'aimerais avoir une aide pour c++ builder car je suis nul de nul et il me faut arriver à créer un composant.
Si quelqu'un savait m'aider grâce à un pas à pas, merci d'avance
marco
mardi 10 août 2004 à 20:12:47 | Re : les composants en c++ builder

fredcl

Bonjour,

c'est quoi comme type de composant? Visuel? Non-visuel?
Il faudrais un tout petit peu plus d'info, et je pourrais t'aider sans problème.

A+

Fred
jeudi 12 août 2004 à 15:36:17 | Re : les composants en c++ builder

kiki007

Merci pour ta réponse, en fait c'est les deux. Mais je n'y comprend rien.
Non visuel car on doit pouvoir verifier si il est bien installé rien quand compilant le programme. Visuel car on doit pouvoir créer un petit programme (ex : avec un bouton pour verifier si il fonctionne)
Mais je n'y comprends absolument rien

Merci d'avance pour ton aide
marco
vendredi 13 août 2004 à 14:45:18 | Re : les composants en c++ builder

fredcl

Bonjour,
Voici le fichier coordsav.h
//---------------------------------------------------------------------------
#ifndef CoordSavH
#define CoordSavH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Controls.hpp>
#include <Classes.hpp>
#include <Forms.hpp>
//---------------------------------------------------------------------------
typedef
void __fastcall (__closure *TOnDefaultEvent)(System::TObject* Sender, int& iLeft, int& iTop, int& iWidth, int& iHeight);
//---------------------------------------------------------------------------
class PACKAGE TCoordSaver : public TComponent
{
private:

AnsiString FRegisKey;
bool FSaveMinimized;
bool FActive;
int FDefaultLeft;
int FDefaultTop;
int FDefaultWidth;
int FDefaultHeight;
TForm* FOwnForm;
TOnDefaultEvent FOnDefaultEvent;

void __fastcall SetRegisKey(AnsiString Value);

AnsiString __fastcall AddSlash(AnsiString S1, AnsiString S2);

protected:

virtual void __fastcall Loaded(void);
virtual void __fastcall BeforeDestruction();

void __fastcall SaveCoords(TForm* Aform);
void __fastcall RestoreCoords(TForm* Aform);

public:

__fastcall TCoordSaver(TComponent* Owner);

void __fastcall SaveNow();
void __fastcall RestoreNow();

__published:

__property AnsiString RegisKey = {read=FRegisKey, write=SetRegisKey};
__property bool SaveMinimized = {read=FSaveMinimized, write=FSaveMinimized};
__property bool Active = {read=FActive, write=FActive};
__property int DefaultLeft = {read=FDefaultLeft, write=FDefaultLeft, default=-1};
__property int DefaultTop = {read=FDefaultTop, write=FDefaultTop, default=-1};
__property int DefaultWidth = {read=FDefaultWidth, write=FDefaultWidth, default=-1};
__property int DefaultHeight = {read=FDefaultHeight, write=FDefaultHeight, default=-1};

__property TOnDefaultEvent OnDefaultEvent = {read=FOnDefaultEvent, write=FOnDefaultEvent};

};
//---------------------------------------------------------------------------
#endif

vendredi 13 août 2004 à 14:46:23 | Re : les composants en c++ builder

fredcl

Bonjour,
voici le fichier coordsav.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "CoordSav.h"
#pragma package(smart_init)
#pragma resource "*.res"
#include <registry.hpp>
#include <stdlib.h>
//---------------------------------------------------------------------------
// ValidCtrCheck est utilisé pour être sûr que les composants créés ne
// contiennent aucune fonction virtuelle pure.
//
static inline void ValidCtrCheck(TCoordSaver *){new TCoordSaver(NULL);}
//---------------------------------------------------------------------------
__fastcall TCoordSaver::TCoordSaver(TComponent* Owner) : TComponent(Owner)
{
FRegisKey = "\\software\\CoordSaver\\Windows";
FSaveMinimized = false;
FActive = true;
FDefaultLeft = FDefaultTop = FDefaultWidth = FDefaultHeight = -1;
FOnDefaultEvent = 0;
}
//---------------------------------------------------------------------------
void __fastcall TCoordSaver::SaveNow()
{
TForm* AForm = dynamic_cast<TForm*>(Owner);
bool bl = FActive;
FActive = true;
SaveCoords(AForm);
FActive = bl;
}
//---------------------------------------------------------------------------
void __fastcall TCoordSaver::RestoreNow()
{
TForm* AForm = dynamic_cast<TForm*>(Owner);
bool bl = FActive;
FActive = true;
RestoreCoords(AForm);
FActive = bl;
}
//---------------------------------------------------------------------------
void __fastcall TCoordSaver::BeforeDestruction()
{
FOwnForm = dynamic_cast<TForm*>(FOwnForm);
SaveCoords(FOwnForm);
}
//---------------------------------------------------------------------------
void __fastcall TCoordSaver::Loaded(void)
{
TComponent::Loaded();
FOwnForm = dynamic_cast<TForm*>(Owner);
RestoreCoords(FOwnForm);
}
//---------------------------------------------------------------------------
void __fastcall TCoordSaver::SaveCoords(TForm* Aform)
{
if (!Aform) return;
if (FActive && !Aform->ComponentState.Contains(csDesigning))
{
TRegistry* Registry = 0;
try
{
Registry = new TRegistry();
Registry->RootKey = HKEY_LOCAL_MACHINE;
if (Registry->OpenKey(AddSlash(FRegisKey, Aform->Name), true))
{
if ((Aform->WindowState != wsMinimized)||FSaveMinimized)
Registry->WriteInteger("WindowState", Aform->WindowState);
else
Registry->WriteInteger("WindowState", wsNormal);
Registry->WriteInteger("Left", Aform->Left);
Registry->WriteInteger("Top", Aform->Top);
Registry->WriteInteger("Width", Aform->Width);
Registry->WriteInteger("Height", Aform->Height);
Registry->CloseKey();
}
delete Registry;
}
catch(Exception& e)
{
Application->ShowException(&e);
if (Registry) delete Registry;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TCoordSaver::RestoreCoords(TForm* Aform)
{
if (!Aform) return;
if (FActive && !Aform->ComponentState.Contains(csDesigning))
{
TRegistry* Registry = 0;

try
{
int wLeft, wTop, wWidth, wHeight;
bool ReadingOk = false;

Registry = new TRegistry();
Registry->RootKey = HKEY_LOCAL_MACHINE;
if (Registry->OpenKey(AddSlash(FRegisKey, Aform->Name), false))
{
TWindowState wSate;
try
{
wSate = (TWindowState)Registry->ReadInteger("WindowState");
wLeft = Registry->ReadInteger("Left");
wTop = Registry->ReadInteger("Top");
wWidth = Registry->ReadInteger("Width");
wHeight = Registry->ReadInteger("Height");
ReadingOk = true;
}
catch(...){}
Registry->CloseKey();
if (ReadingOk)
{
if (wSate == wsMaximized)
Aform->WindowState = wsMaximized;
else
{
Aform->Left = min(wLeft, Screen->Width - 10);
Aform->Top = min(wTop, Screen->Height - 10);
Aform->Width = min(wWidth, Screen->Width);
Aform->Height = min(wHeight, Screen->Height);
if (FSaveMinimized &&(wSate == wsMinimized))
Aform->WindowState = wsMinimized;
else
Aform->WindowState = wsNormal;
}
}
}
delete Registry;
if (!ReadingOk)
{
wLeft = wTop = wWidth = wHeight = -1;

wLeft = FDefaultLeft;
wTop = FDefaultTop;
if (FDefaultWidth == 0)
wWidth = Screen->Width;
else
wWidth = FDefaultWidth;
if (FDefaultHeight == 0)
wHeight = Screen->Height;
else
wHeight = FDefaultHeight;
// Effectuer un appel a procédure si existante
if (FOnDefaultEvent)
FOnDefaultEvent(this, wLeft, wTop, wWidth, wHeight);
if (wLeft >= 0) Aform->Left = min(wLeft, Screen->Width - 10);
if (wTop >= 0) Aform->Top = min(wTop, Screen->Height - 10);
if (wWidth > 0) Aform->Width = min(wWidth, Screen->Width);
if (wHeight > 0) Aform->Height = min(wHeight, Screen->Height);
}
}
catch(Exception& e)
{
Application->ShowException(&e);
if (Registry) delete Registry;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TCoordSaver::SetRegisKey(AnsiString Value)
{
if (Value != "")
FRegisKey = Value;
else
throw Exception("Le nom de la clé de registre ne peut être nul.");
}
//---------------------------------------------------------------------------
AnsiString __fastcall TCoordSaver::AddSlash(AnsiString S1, AnsiString S2)
{
AnsiString retStr;

if (*AnsiLastChar(S1) != '\\')
retStr = S1 + '\\' + S2;
else
retStr = S1 + S2;
return retStr;
}
//---------------------------------------------------------------------------
/*
namespace Coordsav
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TCoordSaver)};
RegisterComponents("Fred", classes, 0);
}
}
*/
//---------------------------------------------------------------------------
vendredi 13 août 2004 à 14:51:25 | Re : les composants en c++ builder

fredcl

Les deux fichiers ci-dessus permettent de créer un composant non visuel.
La partie interressante est la fin du fichier cpp avec la fonction register.
Un bon tuto semble t'il à cette adresse (il n'est pas de moi, mais semble bien fait)
http://chgi.developpez.com/compo/
Ci-dessous deux autre fichiers hyperlink.h et hyperlink.cpp
c'est un composant visuel cette fois.

Ces deux composants était fait pour CPP Builder 5 mais je pense pas qu'il y ai de problème avec la version 6
vendredi 13 août 2004 à 14:51:58 | Re : les composants en c++ builder

fredcl

Fichier hypermink.h
//---------------------------------------------------------------------------
#ifndef HyperLinkH
#define HyperLinkH
//---------------------------------------------------------------------------
#include <SysUtils.hpp>
#include <Controls.hpp>
#include <Classes.hpp>
#include <Forms.hpp>
#include <StdCtrls.hpp>
//---------------------------------------------------------------------------
enum TLinkType {ltEmail, ltFile, ltGopher, ltHttp, ltNews, ltWais, ltTelnet, ltCustom};
//---------------------------------------------------------------------------
typedef void __fastcall (__closure *TBeforeExecuteEvent)(System::TObject* Sender, bool &ExecuteIt);
typedef void __fastcall (__closure *TAfterExecuteEvent)(System::TObject* Sender, long Result);
//---------------------------------------------------------------------------
class PACKAGE THyperLink : public TCustomLabel
{
typedef TCustomLabel inherited;

private:

AnsiString FAlias;
AnsiString FCustomHint;
TLinkType FLinkType;
TColor FLinkColor;
bool FVisited;
TColor FVisitedColor;
TBeforeExecuteEvent FOnBeforeExecuted;
TAfterExecuteEvent FOnAfterExecuted;

protected:

void __fastcall setLinkType(TLinkType Value);
void __fastcall setLinkColor(TColor Value);
void __fastcall setVisitedColor(TColor Value);
void __fastcall setVisited(bool Value);
void __fastcall setCustomPrefix(AnsiString Value);
void __fastcall setAlias(AnsiString Value);
AnsiString __fastcall getCustomPrefix(void);
DYNAMIC void __fastcall Click(void);
virtual void __fastcall Paint(void);
void __fastcall SetCaption(AnsiString Value);

public:

__fastcall THyperLink(TComponent* Owner);

AnsiString __fastcall GetUrl();

__published:

__property AutoSize;
__property TLinkType LinkType={read=FLinkType,write=setLinkType,default=ltEmail,stored=true};
__property TColor LinkColor={read=FLinkColor,write=setLinkColor,default=clBlue,stored=true};
__property TColor VisitedColor={read=FVisitedColor,write=setVisitedColor,default=clPurple,stored=true};
__property bool Visited={read=FVisited,write=setVisited,default=false,stored=true};
__property TBeforeExecuteEvent OnBeforeExecuted={read=FOnBeforeExecuted,write=FOnBeforeExecuted};
__property TAfterExecuteEvent OnAfterExecuted={read=FOnAfterExecuted,write=FOnAfterExecuted};
__property AnsiString CustomPrefix={read=getCustomPrefix,write=setCustomPrefix,nodefault,stored=true};
__property AnsiString Alias={read=FAlias,write=setAlias,nodefault,stored=true};
__property DragCursor;
__property DragMode;
__property Enabled;
__property Align;
__property PopupMenu;
__property OnDblClick;
__property OnDragDrop;
__property OnDragOver;
__property OnEndDrag;
__property OnMouseDown;
__property OnMouseMove;
__property OnMouseUp;
__property OnStartDrag;
__property ShowHint={default=true};
__property ParentShowHint;
__property ParentColor;
__property ParentFont;
__property Font;
__property Visible;
__property Color;
__property Cursor;
__property Caption;
};
//---------------------------------------------------------------------------
#endif
vendredi 13 août 2004 à 14:52:26 | Re : les composants en c++ builder

fredcl

Fichier hyperlink.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "HyperLink.h"
#pragma package(smart_init)
#pragma resource "*.res"
#include <shellapi.h>
//---------------------------------------------------------------------------
// ValidCtrCheck est utilisé pour être sûr que les composants créés ne
// contiennent aucune fonction virtuelle pure.
//
static inline void ValidCtrCheck(THyperLink *){new THyperLink(NULL);}
//---------------------------------------------------------------------------
static char UrlTypes[8][256] = {"mailto:", "file://", "gopher://", "http://",
"news:", "wais:", "telnet:", ""};
//---------------------------------------------------------------------------
__fastcall THyperLink::THyperLink(TComponent* Owner) : TCustomLabel(Owner)
{
Width = 100;
Height = 13;
Transparent = true;
FLinkType = ltEmail;
FVisited = false;
FLinkColor = clBlue;
FVisitedColor = clPurple;
ShowHint = true;
FCustomHint = "";
Cursor = crHandPoint;
}
//---------------------------------------------------------------------------
void __fastcall THyperLink::setLinkType(TLinkType Value)
{
if (FLinkType != Value)
{
FLinkType = Value;
if (ComponentState.Contains(csLoading)) return;
FVisited=false;
Invalidate();
}
}
//---------------------------------------------------------------------------
void __fastcall THyperLink::setLinkColor(TColor Value)
{
if (FLinkColor != Value)
{
FLinkColor = Value;
if (ComponentState.Contains(csLoading)) return;
if (!(FVisited)) Invalidate();
}
}
//---------------------------------------------------------------------------
void __fastcall THyperLink::setVisitedColor(TColor Value)
{
if (FVisitedColor != Value)
{
FVisitedColor=Value;
if (ComponentState.Contains(csLoading)) return;
if (FVisited) Invalidate();
}
}
//---------------------------------------------------------------------------
void __fastcall THyperLink::setVisited(bool Value)
{
if (FVisited != Value)
{
FVisited = Value;
if (ComponentState.Contains(csLoading)) return;
Invalidate();
}
}
//---------------------------------------------------------------------------
void __fastcall THyperLink::setCustomPrefix(AnsiString Value)
{
if (AnsiString(UrlTypes[(int)ltCustom]) != Value)
{
strncpy(UrlTypes[(int)ltCustom], Value.c_str(), 256);
UrlTypes[(int)ltCustom][(Value.Length()<255 ? Value.Length() : 255)] = 0;
if (ComponentState.Contains(csLoading)) return;
if (FLinkType == ltCustom)
{
FVisited = false;
Invalidate();
}
}
}
//---------------------------------------------------------------------------
void __fastcall THyperLink::setAlias(AnsiString Value)
{
if (FAlias != Value)
{
FAlias = Value;
if (ComponentState.Contains(csLoading)) return;
if (ComponentState.Contains(csDesigning))
{
if (Caption == Name)
Caption = FAlias;
if (Hint == "")
Hint = GetUrl();
}
FVisited = false;
Invalidate();
}
}
//---------------------------------------------------------------------------
AnsiString __fastcall THyperLink::getCustomPrefix(void)
{
AnsiString as = UrlTypes[(int)ltCustom];
return as;
}
//---------------------------------------------------------------------------
void __fastcall THyperLink::Click(void)
{
bool doexec = true;
if (ComponentState.Contains(csLoading)) return;
if (ComponentState.Contains(csDesigning)) return;
if (FOnBeforeExecuted) FOnBeforeExecuted(this, doexec);
if (doexec)
{
AnsiString exec = GetUrl();
int result = (int)ShellExecute(Application->Handle, "open", exec.c_str(),
NULL, ".", SW_SHOWNORMAL);
if (result > 32)
{
Visited=true;
Invalidate();
}
if (FOnAfterExecuted) FOnAfterExecuted(this, (long)result);
}
}
//---------------------------------------------------------------------------
void __fastcall THyperLink::Paint(void)
{
if (ComponentState.Contains(csLoading)) return;
if (!ComponentState.Contains(csDesigning))
{
if (FVisited)
Font->Color = FVisitedColor;
else
Font->Color = FLinkColor;
}
TCustomLabel::Paint();
}
//---------------------------------------------------------------------------
AnsiString __fastcall THyperLink::GetUrl()
{
AnsiString tmp = UrlTypes[(int)FLinkType] + FAlias;
return tmp;
}
//---------------------------------------------------------------------------
namespace Hyperlink
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(THyperLink)};
RegisterComponents("Fred", classes, 0);
}
}
//---------------------------------------------------------------------------
vendredi 13 août 2004 à 14:54:37 | Re : les composants en c++ builder

fredcl

Voilà comme tu le remarque c'est pas beaucoup commenté, mais je n'ai pas trop le temps en ce moment de rajouter les commentaires.

Etudis ces fichiers, lis le tutoriel et si tu as des questions plus précises j'y répondrais.

Bon courage

A+

Fred


Cette discussion est classée dans : builder, composants, nul


Répondre à ce message

Sujets en rapport avec ce message

C++ Builder X [ par otofraise ] Bonjour a tous,Je travail actuellement avec C++ Builder 6.J'ai developpe quelques appli avec, ainsi qu'une serie de composants visuels.J'aimerais savo composant dans c++ builder6 [ par sidalilo ] bonjour je veux adapter des composants de delphi 7 avec c++ builder 6,j'ai des composants de devexpress de delphi7 et je veux les installer ou les co Programme sur les sockets en c++ builder 6 [ par fahdmustapha ] salut, j'aimerai avoir le code source de deux programmes en c++ builder 6 (serveur et client). le client:contien trois composants TClientSocket, TButt DCMTK [ par Mercusyo ] Bonjour, Je ne sais pas si mon post est bien mis au bon endroit. Voilà, je souhaiterais incorporer l'ensemble des librairies de DCMTK (pour DICOM Too Borland C++ Builder Standard base de données Access [ par albert232 ] Bonjour, J'ai une application VB5 de calcul qui utilise une base de données Access. Elle fonctionne très bien. Je m'initie au logiciel Borland C++ TComPort [ par shdtlc ] Bonjour a tous, J'aurais voulu savoir comment avec Borland c++ builder 6, Je dois créer un programme qui récupère les trames envoyé par un PABX ALCATE N° de série de disque dur [ par sidalilo ] bonjour je travail sur c++ builder 6 et je veux obtenir le n° de mon disque dur en c++ builder 6 merci bien de vous me faire un cou de main pour ca Problème lecture video sous builder [ par sf4 ] Pour lire la vidéo j'utilise un TMediaPlayer et mon problème est que selon la vidéo soit elle est lue normalement, soit en accéléré, soit pas du tout. graphe avec c++ builder [ par badra18 ] Bjr, je veux créer un graphe avec c++ builder, avec le graphisme, j'ai l'idé qu'il faut faire avec des matrice mai comment le dessiner pour voir le gr string gride en builder c++ [ par nanoetudiante ] salut tous monde mon probleme est comment prendre les donnees de string grid et faire une operation avec float sachant queje convert donnees de string


Nos sponsors


Sondage...

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 1,373 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales