This code makes sense to me, I'm just having trouble trying to understand why it doesn't work correctly. This is a GUI APP. When the Play button is Clicked, the play_Click(System::Object * sender, System::EventArgs * e) function is called, it is suppose to make the Play button dissapear and the Pause Button Appear as soon as the Play button is clicked. I don't know why it calls the keystrokes function then goes through the while loop continuously without ever displaying the Pause Button, instead of making the Play dissapear and the Pause appear then goto the keystrokes function which will finally go through the while loop. I also had conditions where it would go through the file once, then stop, then display the Pause Button.
My objective is to Play, Pause whenever the user wants. When Play is clicked, the Play button should dissapear and the Pause Button should appear. When the Pause button is clicked, the pause button should dissapear and the Play button should appear. That way the user can Play and Pause the file iteration at ANY point in time.
-
-
private: System::Void keystrokes(System::Object * sender, System::EventArgs * e)//, char *array)
-
{//actual key presses depending on the characters read
-
-
char array[255];
-
-
ifstream in;
-
-
in.open("c:\\write.txt", ios::in);
-
-
-
if(!in)
-
{
-
richTextBox1->AppendText("\nCannot open input file.\n");
-
return;
-
}
-
-
while(in) //&& keystrokeFlag == true)
-
{
-
if(playFlag == false)
-
{
-
richTextBox1->AppendText("\nBreak\n");
-
break;
-
}
-
-
richTextBox1->AppendText("\nGetline\n");
-
in.getline(array, 4); //delim defaults to '\n'
-
-
richTextBox1->AppendText("\nPush Keystrokes\n");
-
pushKeystrokes(sender, e, array);
-
-
richTextBox1->AppendText("\nCheck Status\n");
-
checkStatus(sender, e);
-
-
richTextBox1->AppendText("\nSleep Timer\n");
-
System::Threading::Thread::Sleep(100);
-
-
if(in.eof())
-
{
-
richTextBox1->AppendText("\nEND OF FILE\n");
-
in.clear(); //clear the flags (in.seekg() will not work properly without this function call)
-
in.seekg(0, ios::beg); //infinite loop work on this tomorrow
-
}
-
-
}
-
in.close(); //close document
-
}
-
-
private: System::Void checkStatus(System::Object * sender, System::EventArgs * e)
-
{
-
richTextBox1->SelectionColor = Color::LimeGreen; //color indication testing purposes
-
if(play->Visible == true)
-
{
-
richTextBox1->AppendText("FALSE\n");
-
playFlag = false;
-
}
-
if(play->Visible == false)
-
{
-
richTextBox1->AppendText("TRUE\n");
-
playFlag = true;
-
}
-
}
-
-
private: System::Void play_Click(System::Object * sender, System::EventArgs * e)
-
{
-
play->Visible = false;
-
pause->Visible = true;
-
-
keystrokes(sender, e);
-
}
-
-
private: System::Void pause_Click(System::Object * sender, System::EventArgs * e)
-
{
-
pause->Visible = false;
-
play->Visible = true;
-
-
keystrokes(sender, e);
-
}
-
-