 |
Club Builder Foro de C++Builder en español
|
| Ver tema anterior :: Ver tema siguiente |
| Autor |
Mensaje |
Angel Master


Registrado: 15 Abr 2003Mensajes: 2311Ubicación: Toledo (España)
|
Publicado: Lun 02 Nov, 2009 11:44 am Asunto: Duda con "Una Nueva Barra de Progeso" |
|
|
No sé si es que estoy espeso o muy torpe; probablemente ambas cosas
Estaba viendo este hilo de César Una Nueva Barra de Progeso para probarlo y al copiar el código en un proyecto nuevo y me da un error al tratar de salvarlo:
| Cita: | | Error in module Unit1. Declaration of class THBarra is missing or incorrect |
El código del hilo, ¿hay que copiarlo tal cual o hay quie hacer algo? No acabo de entender que está mal. En la ayuda de Builder pone esto:
| Cita: | Declaration of class class is missing or incorrect
C++Builder is unable to locate the form's class declaration in the header file of the unit. This is probably because the type declaration containing the class has been deleted, commented out, or incorrectly modified. This error occurs if C++Builder cannot locate a class declaration equivalent to the following:
...
class TForm1: public TForm
... |
Sin embargo, en el código de César el archivo de cabecera pone:
| Código: | class THBarra : public TThread |
¿No debería ser public THBarra? _________________ Un saludo
Necesitamos tu ayuda: Envía AI al 27595 (Coste 1,20 euros + IVA) |
|
| Volver arriba |
|
 |
Cesar C. Salazar Gonzalez Master


Registrado: 01 Oct 2002Mensajes: 2155Ubicación: San Cristóbal de Las Casas, Chiapas
|
Publicado: Lun 02 Nov, 2009 7:52 pm Asunto: |
|
|
Angel creo que se te ha ido el TThread.
Como es una barra "independiente" de la aplicación esta corre por medio de un Thread que es un archivo aparte.
Si regresas al Post, veras los archivos de cabecera, de la siguiente manera.
"UBarra.h"
"UBarra.cpp"
"UBarra.dfm"
| César C. Salazar González escribió: |
esto es el codigo del Form donde se dibuja la barra
TLabel *Label1; // mostrar un msg
TPanel *Panel1; // donde dibujamos la barra
TBevel *Bevel1; // una linea
TLabel *Label2; // otro label para poner otro msg.
Archivo .cpp del Form que dibuja la Barra,
Código:
| Código: |
//---------------------------------------------------------------------------
#include <vcl>
#pragma hdrstop
#include "UBarra.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TFBarra *FBarra;
//---------------------------------------------------------------------------
__fastcall TFBarra::TFBarra(TComponent* Owner)
: TForm(Owner)
{
pBarra = new THBarra(this->Panel1->Handle,this->Panel1->Width,false);;
}
//---------------------------------------------------------------------------
void __fastcall TFBarra::FormDestroy(TObject *Sender)
{
pBarra->Terminate();
}
//---------------------------------------------------------------------------
|
Lo de Arriba pertenece a un Form que tiene los elementos para dibujar la barra
Dentro del .h del Form que dibuja la barra
| Código: |
//---------------------------------------------------------------------------
Código:
#ifndef UBarraH
#define UBarraH
//---------------------------------------------------------------------------
#include <Classes>
#include <Controls>
#include <StdCtrls>
#include <Forms>
#include <ExtCtrls>
#include "THBarra.h" // encabezado del Thread
//---------------------------------------------------------------------------
class TFBarra : public TForm
{
__published: // IDE-managed Components
TLabel *Label1;
TPanel *Panel1;
TBevel *Bevel1;
TLabel *Label2;
void __fastcall FormDestroy(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TFBarra(TComponent* Owner);
THBarra *pBarra; // Declaracion del Thread
};
//---------------------------------------------------------------------------
extern PACKAGE TFBarra *FBarra;
//---------------------------------------------------------------------------
#endif
|
|
ahora bien Lo siguiente es el código para "crear" el Thread, que la barra necesita para ejecutarse fuera de la aplicación, lo que sería un archivo de cabecera con su correspondiente .ccp
THBarra.h
THBarra.cpp
| César C. Salazar González. escribió: |
y ahora si el codigo del Thread, para que funcione correctamente.
dentro del Cpp del Thread
| Código: |
//---------------------------------------------------------------------------
#include <vcl>
#pragma hdrstop
#include "THBarra.h" //unidad del Thread
#include "UBarra.h" // unidad del Form donde se dibuja la barra
#pragma package(smart_init)
//---------------------------------------------------------------------------
__fastcall THBarra::THBarra(HWND hWnd,int AnchoComponente,bool CreateSuspended)
: TThread(CreateSuspended)
{
Priority = tpNormal;
FreeOnTerminate = false;
this->hwndPanel = hWnd;
this->Ancho_Barra = 45;
this->Limite = AnchoComponente-this->Ancho_Barra;
this->PosBarra=1;
this->terminar = false;
this->Sentido = true;
this->ACanvas= new TCanvas;
this->Barra = new Graphics::TBitmap;
this->ACanvas->Handle = GetDC(this->hwndPanel);
this->Fuerte = (TColor) 0x005AAD4B ; // color del Tumb
this->Debil = clWhite;//(TColor) 0x00DDC8CB;
}
//---------------------------------------------------------------------------
void __fastcall THBarra::Execute()
{
//---- Place thread code here ----
while(!Terminated)
{
if(this->PosBarra>=this->Limite)
{
this->Incremento=-15;
this->Sentido = false;
}
if(this->PosBarra<1>Incremento=15;
this->Sentido = true;
}
this->PosBarra+=this->Incremento;
//this->Synchronize(MoverBarra);
try
{
MoverBarra();
}catch(...)
{}
Sleep(150);
}
}
//---------------------------------------------------------------------------
void __fastcall THBarra::MoverBarra(void)
{
::GetClientRect(this->hwndPanel, &this->rectClient);
// segun esto lo limpiamos
this->ACanvas->Brush->Color = clWhite;
this->ACanvas->Pen->Color = clBlack;
this->ACanvas->FillRect(this->rectClient);
this->ACanvas->Brush->Color = clBlack;
this->ACanvas->FrameRect(this->ACanvas->ClipRect);
// creamos la region para la barra
this->Barra->Width = this->Ancho_Barra;
this->Barra->Height = this->rectClient.bottom-3;
this->RectTmp = this->Barra->Canvas->ClipRect;
//*************************
// pintar el degradado
// LADO DERECHO
if (Sentido)
{
this->c2 = this->Fuerte;
this->c1 = this->Debil;
}
else
{
this->c1 = this->Fuerte;
this->c2 = this->Debil;
}
this->Rf = GetRValue(this->c1);
this->Gf = GetGValue(this->c1);
this->Bf = GetBValue(this->c1);
this->Rd = GetRValue(this->c2)-this->Rf;
this->Gd = GetGValue(this->c2)-this->Gf;
this->Bd = GetBValue(this->c2)-this->Bf;
this->nTonos = 700;
this->incremento = (float) this->nTonos / this->RectTmp.Width();
for (this->i=this->RectTmp.left; this->i<this>RectTmp.Width(); ++this->i)
{
this->cR = this->Rf + MulDiv(this->incremento*i, this->Rd, this->nTonos);
this->cG = this->Gf + MulDiv(this->incremento*i, this->Gd, this->nTonos);
this->cB = this->Bf + MulDiv(this->incremento*i, this->Bd, this->nTonos);
this->Barra->Canvas->Brush->Color = (TColor) RGB(this->cR, this->cG, this->cB);
this->Barra->Canvas->Pen->Color = (TColor) RGB(this->cR, this->cG, this->cB);
this->Barra->Canvas->MoveTo(this->RectTmp.left+this->i, this->RectTmp.top);
this->Barra->Canvas->LineTo(this->RectTmp.left+this->i, this->RectTmp.Bottom);
}
//*************************
this->ACanvas->TryLock();
this->ACanvas->Draw(this->PosBarra,1,this->Barra);
this->ACanvas->Unlock();
}
|
y Dentro del .H del Thread
Código:
| Código: |
//---------------------------------------------------------------------------
#ifndef THBarraH
#define THBarraH
//---------------------------------------------------------------------------
#include <Classes>
//---------------------------------------------------------------------------
class THBarra : public TThread
{
private:
protected:
void __fastcall Execute();
void __fastcall MoverBarra(void);
HWND hwndPanel;
public:
__fastcall THBarra(HWND hWnd,int AnchoComponente,bool CreateSuspended);
int Ancho_Barra;
int Limite,Incremento;
int PosBarra;
bool terminar,Sentido;
TCanvas *ACanvas;
Graphics::TBitmap *Barra;
// variables************************
TColor c1,c2;
TColor Fuerte; // color del Tumb
TColor Debil;//(TColor) 0x00DDC8CB;
int Rf,Gf,Bf;
//-------------------------
int Rd,Gd,Bd;
int cR, cG, cB;
float nTonos;
float incremento ;
//-------------------
int i, X1, X2;
RECT rectClient; // Area Cliente
TRect RectTmp;
//********************************************
};
//---------------------------------------------------------------------------
#endif
|
|
En relativa son 2 cosas un formulario que contien los elementos para dibujar la barra UBarra.(h, cpp, dfm) y un Thread generado en archivo de cabecera llamado THBarra.h y THBarra.cpp, respectivamente.
Saludos. _________________
 |
|
| Volver arriba |
|
 |
Angel Master


Registrado: 15 Abr 2003Mensajes: 2311Ubicación: Toledo (España)
|
|
| Volver arriba |
|
 |
|
|
No puedes publicar temas nuevos en este foro No puedes responder a temas en este foro No puedes editar tus mensajes en este foro No puedes borrar tus mensajes en este foro No puedes votar en las encuestas de este foro
|
© 2002–2026 Club Builder · Funciona con phpBB.
|