[C++] Lottozahlengenerator (GUI)

Ich habe einen Generator für Lottozahlen in C++ programmiert:

lotto

Es gibt folgende Elemente:
– Dynamisch generierte TLabels
– 2 Buttons
– 1 Scrollbar
– 1 Statusbar
– 1 Progressbar

Man kann auch die Transparenz des Fensters verändern. Das geschieht mit diesem Code:

void __fastcall TForm1::changetrans(TObject *Sender)
{
SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) | WS_EX_LAYERED);
SetLayeredWindowAttributes(Handle, 0, 255-ScrollBar1->Position , LWA_ALPHA);        
}

Die Transparenz hängt also von der Position der Scrollbar ab!

Download
Alles komplett (Code, exe, Projektdatei, Form, usw.): lotto_komplett.zip

Der Code des Generators ist folgender:

//---------------------------------------------------------------------------

#include 
#pragma hdrstop

#include "lotto.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
TForm1 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
TLabel *mylabel[49];
TLabel *statuslabel;
int zahlen[6];
TProgressBar *progress;

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  Button1->Visible = false;
  progress = new TProgressBar(this);
  progress->Parent = StatusBar1;
  progress->Height = 10;
  progress->Left = 150;
  progress->Top = 10;
  progress->Max = 49;

  statuslabel = new TLabel(this);
  statuslabel->Parent = StatusBar1;
  statuslabel->Left = 10;
  statuslabel->Top = 10;
  statuslabel->Caption = "Aufbauen des Feldes";

  int topnow = 30;
  int leftnow = 30;
  for(int i = 0; i < 49; i++)
  {
  mylabel[i]= new TLabel(this);
  mylabel[i]->Caption = IntToStr(i+1);
  mylabel[i]->Visible = true;
  mylabel[i]->Left = leftnow;
  mylabel[i]->Top = topnow;
  mylabel[i]->Name = "Label"+IntToStr(i);
  mylabel[i]->Parent = Form1;
  mylabel[i]->Width = 30;
  mylabel[i]->Font->Size = 15;
  mylabel[i]->Color = clGreen;
  Sleep(5);
  Application->ProcessMessages();
  progress->Position = i+1;

  if(leftnow > 200)
  {
    topnow = topnow + 30;
    leftnow = 0;
  }

  leftnow += 30;
  }

  Button2->Visible = true;
  statuslabel->Caption = "Fertig";
  Sleep(1000);
  progress->Position = 0;

}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)
{
  for(int i = 0; i < 49; i++)
  {
    mylabel[i]->Color = clGreen;
  }

  int zahl_now = 0;
  randomize();
  progress->Max = 5;
  for(int i = 0; i < 6; i++)
  {
     progress->Position = i;
     Application->ProcessMessages();
     statuslabel->Caption = "Generiere Zahl "+IntToStr(i+1);
     Sleep(250);
    zahl_now = random(49);
    while(zahl_now == zahlen[1] ||
          zahl_now == zahlen[2] ||
          zahl_now == zahlen[3] ||
          zahl_now == zahlen[4] ||
          zahl_now == zahlen[5] ||
          zahl_now == zahlen[6])
    {
        zahl_now = random(49);
    }
    zahlen[i] = zahl_now;

    mylabel[zahl_now]->Color = clRed;
  }
  statuslabel->Caption = "Fertig";
}
//---------------------------------------------------------------------------


void __fastcall TForm1::changetrans(TObject *Sender)
{
SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) | WS_EX_LAYERED);
SetLayeredWindowAttributes(Handle, 0, 255-ScrollBar1->Position , LWA_ALPHA);        
}
//---------------------------------------------------------------------------


1 Star2 Stars3 Stars4 Stars5 Stars (Wurde noch nicht bewertet)
Loading...


Ein Kommentar zu “[C++] Lottozahlengenerator (GUI)”

  1. […] [C++] Lottozahlengenerator (GUI) (38) […]

Hinterlasse einen Kommentar!

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.

»Informationen zum Artikel

Autor: Simon
Datum: 25.06.2008
Zeit: 18:22 Uhr
Kategorien: C/C++
Gelesen: 7533x heute: 2x

Kommentare: RSS 2.0.
Diesen Artikel kommentieren oder einen Trackback senden.

»Meta