por Kleber » 08 Mai 2007 00:54
Consegui fazer isto, não ficou lá grandes coisas, mas atendeu parcialmente a necessidade. O problema é que quando o programa está rodando e coloca-se o trackbar em 0 (position), nem apertando o botão liga a aplicação volta a funcionar.
Segue o código que elaborei, este sem variável boleana.
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//Declaração dos ponteiros para função.
typedef short _stdcall (*PtrInp)(short EndPorta);
typedef void _stdcall (*PtrOut)(short EndPorta, short datum);
HINSTANCE hLib; //Instância para a DLL inpout32.dll.
PtrInp inportB; //Instância para a função Imp32().
PtrOut outportB; //Instância para a função Out32().
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
// If the current color is red
if( Shape1->Brush->Color == clRed )
{
// Change the color to green
Timer1->Interval = TrackBar1->Position;
Shape1->Brush->Color = clGreen;
outportB (0x378,0);
}
// But if the color is green
else if( Shape1->Brush->Color == clGreen )
{
// Change the color to Red
Timer1->Interval = TrackBar1->Position;
Shape1->Brush->Color = clRed;
outportB (0x378,255);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Timer1->Enabled = false;
//Carrega a DLL na memória.
hLib = LoadLibrary("inpout32.dll");
if(hLib == NULL)
{
ShowMessage("Erro. O arquivo inpout32.DLL não foi encontrado.");
Application->Terminate();
}
//Obtém o endereço da função Inp32 contida na DLL.
inportB = (PtrInp) GetProcAddress(hLib, "Inp32");
if(inportB == NULL)
{
ShowMessage("Erro. Erro ao endereçar a função Inp32.");
Application->Terminate();
}
//Obtém o endereço da função Out32 contida na DLL.
outportB = (PtrOut) GetProcAddress(hLib, "Out32");
if(outportB == NULL)
{
ShowMessage("Erro. Erro ao endereçar a função Out32.");
Application->Terminate();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Shape1->Brush->Color = clGreen;
Timer1->Enabled = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Application->Terminate();
}
//-----------------------------------------------------------------------
Kleber