[C++] MessageBox Ja/Nein

scummy

Grünschnabel
Hey Leute!

Bin seit grade eben neu hier, habe gesehn, dass sich hier einige erfahrene Programmierer tummeln und da dacht ich mir, dass mir hier bestimmt geholfen werden kann :rolleyes:

Vorweg: Ich bin Anfänger und lerne gerade in der Schule zu "programmieren"

Also zu meinem Problem:

Ich habe ein Programm zum Erstellen und Auflisten von FussballTipps. Anzugeben und auszuwählen sind Vorname/Nachname ( in je 2 Edit-Fenstern ), Tipp Gastmannschaft und Tipp Heimmannschaft ( in je 2 Edit-Fenstern ) und die Paarung der Mannschaften ( in einer ComboBox ). Zusätzlich gibt es einen Button, den man zum Speichern des Tipps in einem StringGrid betätigen kann.

Nun habe ich schon weitesgehend alles fertig programmiert und wollte das Programm, da ich es morgen abgeben muss, ein wenig aufpolieren und ein paar kleine Details einbauen.
Dann habe ich mir überlegt eine MessageBox mit einer Ja/Nein Abfrage für den Button einzubauen, ob man sich wirklich sicher sei, den Tipp abgeben zu wollen!

Es wäre wirklich super, wenn mir jemand in irgendeiner Weise noch bis morgen erklärt kriegt wie ich solch eine Abfrage da zwischenschalte!

Um das Ganze ein wenig deutlicher zu machen hier ein Bild der graphischen Oberfläche und ein Auszug aus dem Quelltext des bisherigen Programms:




Bild:

my.php




Quelltext:

Code:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Fussball2.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
AnsiString VName, NName;
float TippH, TippG;
int j,i=1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
 StringGrid->Cells[0][0] = " Nr. ";
 StringGrid->Cells[1][0] = "       - Tipper - ";
 StringGrid->Cells[2][0] = "                                 - Paarung - ";
 StringGrid->Cells[3][0] = "     - Tipp - ";

 for ( j=1; j<=51; j++ )
     { StringGrid->Cells[0][j] = " "+FloatToStr(j)+".";
     }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::EditVNameChange(TObject *Sender)
{
VName = ( EditVName->Text );
}

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

void __fastcall TForm1::EditTippHChange(TObject *Sender)
{
 TippH = StrToFloat ( EditTippH->Text );
}
//---------------------------------------------------------------------------

void __fastcall TForm1::EditTippGChange(TObject *Sender)
{
TippG = StrToFloat ( EditTippG->Text );
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ButtonTippClick(TObject *Sender)
{

if ( ComboPaarung->Items->Strings[ComboPaarung->ItemIndex]=="Energie Cottbus - FC Schalke 04" )
   { StringGrid->Cells[1][i] =" "+(VName)+", "+AnsiString (NName);
     StringGrid->Cells[2][i] =" Energie Cottbus - FC Schalke 04 ";
     StringGrid->Cells[3][i] =" "+FloatToStr(TippH)+" : "+FloatToStr(TippG);
     i=i+1;
   }

if ( ComboPaarung->Items->Strings[ComboPaarung->ItemIndex]=="Werder Bremen - F.C. Hansa Rostock" )
   { StringGrid->Cells[1][i] =" "+(VName)+", "+AnsiString (NName);
     StringGrid->Cells[2][i] =" Werder Bremen - F.C. Hansa Rostock ";
     StringGrid->Cells[3][i] =" "+FloatToStr(TippH)+" : "+FloatToStr(TippG);
     i=i+1;
   }

if ( ComboPaarung->Items->Strings[ComboPaarung->ItemIndex]=="Bayern München - Eintracht Frankfurt" )
   { StringGrid->Cells[1][i] =" "+(VName)+", "+AnsiString (NName);
     StringGrid->Cells[2][i] =" Bayern München - Eintracht Frankfurt ";
     StringGrid->Cells[3][i] =" "+FloatToStr(TippH)+" : "+FloatToStr(TippG);
     i=i+1;
   }

if ( ComboPaarung->Items->Strings[ComboPaarung->ItemIndex]=="Bayer 04 Leverkusen - DSC Arminia Bielefeld" )
   { StringGrid->Cells[1][i] =" "+(VName)+", "+AnsiString (NName);
     StringGrid->Cells[2][i] =" Bayer 04 Leverkusen - DSC Arminia Bielefeld ";
     StringGrid->Cells[3][i] =" "+FloatToStr(TippH)+" : "+FloatToStr(TippG);
     i=i+1;
   }

if ( ComboPaarung->Items->Strings[ComboPaarung->ItemIndex]=="1.FC Nürnberg - VfB Stuttgart" )
   { StringGrid->Cells[1][i] =" "+(VName)+", "+AnsiString (NName);
     StringGrid->Cells[2][i] =" 1.FC Nürnberg - VfB Stuttgart ";
     StringGrid->Cells[3][i] =" "+FloatToStr(TippH)+" : "+FloatToStr(TippG);
     i=i+1;
   }

if ( ComboPaarung->Items->Strings[ComboPaarung->ItemIndex]=="Hamburg SV - Herta BSC Berlin" )
   { StringGrid->Cells[1][i] =" "+(VName)+", "+AnsiString (NName);
     StringGrid->Cells[2][i] =" Hamburg SV - Herta BSC Berlin ";
     StringGrid->Cells[3][i] =" "+FloatToStr(TippH)+" : "+FloatToStr(TippG);
     i=i+1;
   }


if ( ComboPaarung->Items->Strings[ComboPaarung->ItemIndex]=="Hannover 96 - Borussia Dortmund" )
   { StringGrid->Cells[1][i] =" "+(VName)+", "+AnsiString (NName);
     StringGrid->Cells[2][i] =" Hannover 96 - Borussia Dortmund ";
     StringGrid->Cells[3][i] =" "+FloatToStr(TippH)+" : "+FloatToStr(TippG);
     i=i+1;
   }

if ( ComboPaarung->Items->Strings[ComboPaarung->ItemIndex]=="VfL Bochum - VfL Wolfsburg" )
   { StringGrid->Cells[1][i] =" "+(VName)+", "+AnsiString (NName);
     StringGrid->Cells[2][i] =" VfL Bochum - VfL Wolfsburg ";
     StringGrid->Cells[3][i] =" "+FloatToStr(TippH)+" : "+FloatToStr(TippG);
     i=i+1;
   }

if ( ComboPaarung->Items->Strings[ComboPaarung->ItemIndex]=="Karlsruher SC - MSV Duisburg" )
   { StringGrid->Cells[1][i] =" "+(VName)+", "+AnsiString (NName);
     StringGrid->Cells[2][i] =" Karlsruher SC - MSV Duisburg ";
     StringGrid->Cells[3][i] =" "+FloatToStr(TippH)+" : "+FloatToStr(TippG);
     i=i+1;
   }
if ( ComboPaarung->Items->Strings[ComboPaarung->ItemIndex]=="" )
   {
     Application->MessageBox("Achtung!\nKeine Paarung gewählt!","Fehlermeldung:",16+32);
   }



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


void __fastcall TForm1::EditNNameChange(TObject *Sender)
{
NName = ( EditNName->Text );
}
//---------------------------------------------------------------------------

Und hier schliesslich noch das Programm in einem WinRaR Archiv zum Donwloaden:

http://www.1-filehost.midnightirc.info/index.php?t=dl&hash=hzNC13nbvtC63nG9OrfzxGj2rKdxujC0

Freuen mich über jede Hilfe! Bitte heute abend noch :)

Gruß scummy
 
Zuletzt bearbeitet:
vllt. bin ich ein bissl spät dran , sry ! Mit den Messageboxen hab ich mich jetzt nocht nicht beschäftigt ich hätte das prob wahrscheinlich mit einer neuen WindowsForm gelöst, welche 2 buttons enthält ja und nein . Meine variante !

MfG rueD...
 
Hy,

besser zu spät, als nie:
Code:
if(Application->MessageBox("Message Text","Titel",MB_YESNO) == IDYES)
{
   //wenn ja gedrückt
}
else
{
   //wenn nein gedrückt
}

Das sollte so ungefähr dass sein, was du brauchst...

mfg
 
Hallo,
hier noch ein Beitrag zum Auswerten der MessageBox Buttons . . .

int button;

button = MessageBox(0,"MessageText","Titel",MB_YESNO);

if(button == IDYES)
{
//tue dies (Ja wurde angeklickt)
}
else
{
// tue das (Nein wurde angeklickt)
}


funktioniert auch mit MB_OK, MB_YESNOCANCEL etc .
 
Zurück