cplusplus.com cplusplus.com
cplusplus.com   C++ : Forums : Windows Programming : Forms in a Windows form Application
  Search:
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forums
Forums
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Articles
Lounge
Jobs

-

post  Forms in a Windows form Application

enduser000 (78)
Hey,
I started making a GUI tic-tac-toe game using windows forms in Visual Studios Express Edition 2008. I have made the board, it acts as expected, and added two new forms to the app. I have a method to check for wins but am running into trouble opening the new forms (X Wins! and O Wins!) once I find a win. How can I open the new form (inside the solution, owin.h or xwin.h) and quit the original one, restart (if they say play again), or quit if they say quit? In the main() method, it opens Form1 by doing this: Application::Run(gcnew Form1()); I've been around msdn's site and so far don't know what I'm doing. Thanks for taking a look,

enduser000
|
enduser000 (78)
Look I'm replying to myself, lol. I've been looking and working on it for awhile and think I've narrowed it down. I've changed the two dialog boxes to have 'true' set on the property IsMdiContainer... It's giving me a wierd error now, this is the syntax:
1
2
3
4
5
6
7
8
if(winCheck()){
	if(winCheck()==1){
		Form1.ShowDialog(xwin());
	}
	else if(winCheck()==2){
		Form1.ShowDialog(owin());
	}
}


And here's the error:

1>c:\users\owner\documents\visual studio 2008\projects\tictactoe\tictactoe\Form1.h(305) : error C2143: syntax error : missing ';' before '.'

the syntax looks fine to me, but here's the page on the error:

http://msdn.microsoft.com/en-us/library/0afb82ta.aspx

Any ideas?

enduser000
|
Faldrax (312)
Hi, I'm using VS 2005, but it should be the same for 2008.

Not sure of why you are getting your error (I'd need to see more code realy), but the way i am showing multiple forms is to create and show an instance of the form class in the method that is designed to trigger them.
So in my case where I want a simple editor form to pop up when a button is clicked, and I have

1
2
3
4
5
6
7
8
9
10
void MainForm::EditorButtonClick(System::Object^ sender, System::EventArgs^ a)
{
   //OptionsEditorForm is the class of the Editor Form, 
   //options is a variable declared in MainForm which holds the options I want to edit
   optionsEditor = gcnew OptionsEditorForm(options);
   //Instance Created
   optionsEditor->ShowDialog();
   //ShowDialog() so will be modal and only return when closed
   //Scope is just this handler, so gc will free up when we exit
}


This seems to work.
| Last edited on
helios (829)
I'd say is one of the following:
You didn't put a ; at the end of a class.
Form1 is not declared.
Your compiler doesn't like you.

Believe it or not, the third option is more likely than you think. I've sometimes had to compile the same (valid) code several time because the compiler kept hanging in the middle, for some still unknown reason.

Now, on a different subject...
System::Object^

LOL WUT?
|
Faldrax (312)
It's MS C++/CLI, hence gcnew, ^ in place of *, etc.

VC++ 2005 auto generates event handlers with the full System:: prefixes, and I tend to leave them there.

|
enduser000 (78)
Ok, so here's what I want to do: Write a form that opens on a win/lose/tie and prompts them to: play agan or quit. If they hit enter, it closes the main form and reopens, esc quits. I believe I hav the logic down for checking for wins/loses/ties, so how do I maniplate the forms to do what I want? here is the code for the main file, the main form was too big:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// tictactoe.cpp : main project file.

#include "stdafx.h"
#include "Form1.h"

using namespace tictactoe;

[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
	// Enabling Windows XP visual effects before any controls are created
	Application::EnableVisualStyles();
	Application::SetCompatibleTextRenderingDefault(false); 

	// Create the main window and run it
	Application::Run(gcnew Form1());

	return 0;
}


And here is a button (one to play the game) in the main for:

1
2
3
4
5
6
7
private: System::Void button7_MouseClick(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e) {
			 	 if(count%2) this->button7->Text = L"X";
				 else this->button7->Text = L"O";
				 this->button7->Enabled = false;
				 count++;
				 if(winCheck()){ if(winCheck()==1){ Form1.ShowDialog(xwin()); }else if(winCheck()==2){ Form1.ShowDialog(owin()); }}
		 }


And here's my winCheck() function, still need to add for ties:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
int winCheck(){
	/* Cover Across */
	if((this->button1->Text == L"X") && (this->button1->Text == this->button2->Text) && (this->button1->Text == this->button3->Text)){ CFX }
	if((this->button1->Text == L"O") && (this->button1->Text == this->button2->Text) && (this->button1->Text == this->button3->Text)){ CFO }

	if((this->button4->Text == L"X") && (this->button4->Text == this->button5->Text) && (this->button4->Text == this->button6->Text)){ CFX }
	if((this->button4->Text == L"O") && (this->button4->Text == this->button5->Text) && (this->button4->Text == this->button6->Text)){ CFO }

	if((this->button7->Text == L"X") && (this->button7->Text == this->button8->Text) && (this->button7->Text == this->button9->Text)){ CFX }
	if((this->button7->Text == L"O") && (this->button7->Text == this->button8->Text) && (this->button7->Text == this->button9->Text)){ CFO }

	/* Cover Down */
	if((this->button1->Text == L"X") && (this->button1->Text == this->button4->Text) && (this->button1->Text == this->button7->Text)){ CFX }
	if((this->button1->Text == L"O") && (this->button1->Text == this->button4->Text) && (this->button1->Text == this->button7->Text)){ CFO }

	if((this->button2->Text == L"X") && (this->button2->Text == this->button5->Text) && (this->button2->Text == this->button8->Text)){ CFX }
	if((this->button2->Text == L"O") && (this->button2->Text == this->button5->Text) && (this->button2->Text == this->button8->Text)){ CFO }

	if((this->button3->Text == L"X") && (this->button3->Text == this->button6->Text) && (this->button3->Text == this->button9->Text)){ CFX }
	if((this->button3->Text == L"O") && (this->button3->Text == this->button6->Text) && (this->button3->Text == this->button9->Text)){ CFO }

	/* Cover Diagional */
	if((this->button1->Text == L"X") && (this->button1->Text == this->button5->Text) && (this->button1->Text == this->button9->Text)){ CFX }
	if((this->button1->Text == L"O") && (this->button1->Text == this->button5->Text) && (this->button1->Text == this->button9->Text)){ CFO }

	if((this->button3->Text == L"X") && (this->button3->Text == this->button5->Text) && (this->button3->Text == this->button7->Text)){ CFX }
	if((this->button3->Text == L"O") && (this->button3->Text == this->button5->Text) && (this->button3->Text == this->button7->Text)){ CFO }

	/* Check for ties */
	if((this->button1->Text == L"X") || (this->button1->Text == L"O")){
		if((this->button2->Text == L"X") || (this->button2->Text == L"O"){
			if((this->button3->Text == L"X") || (this->button3->Text == L"O"){
				if((this->button4->Text == L"X") || (this->button4->Text == L"O"){
					if((this->button5->Text == L"X") || (this->button5->Text == L"O"){
						if((this->button6->Text == L"X") || (this->button6->Text == L"O"){
							if((this->button7->Text == L"X") || (this->button7->Text == L"O"){
								if((this->button8->Text == L"X") || (this->button8->Text == L"O"){
									if((this->button9->Text == L"X") || (this->button9->Text == L"O"){
										// it is a tie
										CFT
									}
								}
							}
						}
					}
				}
			}
		}
	}


CFX/CFO/CFT = Change for xwin/owin/tie, don't know how to call another form as of now

I think I'm going to try to call up those child forms from the wincheck function, which will be called on each move (button click).

Thanks for taking a look,

enduser000
| Last edited on
enduser000 (78)
Hey,
I got it done. Was a little confused about forms as dialog boxes. Thanks for trying to help with little explanation.

enduser000
|
TKelly (2)
So what did you figure out that solved your problem?
|

This topic is archived - New replies not allowed.
Home page | Privacy policy
© cplusplus.com, 2000-2008 - All rights reserved - v2.2
Spotted an error? contact us