Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GUI Question + One error 2

Status
Not open for further replies.

iranor

Programmer
Jun 17, 2004
174
CA
So here I have test.cpp:

#include <winsock2.h>
#include <stdio.h>
#include <windows.h>
#include <wininet.h>
#include <lm.h>

BOOL kthx = TRUE;

if (kthx)
{
uninstall();
WSACleanup();
exit(0);
}

void uninstall(void)
{
//something long
}

When I click build, I get the following errors:

error C2059: syntax error: 'if'
error C2059: syntax error: missing ';' before '{'
error C2059: '{': missing function header (old-style formal list?)

Question 2: I'm wondering how works the GUI (or graphc interface).

With visual basic, there's a nice window that pops out with buttons, form options, labels, etc. Where is the similar for C++?
 
your if statement is not in a function.
In order to use a gui in visual c++, look into using MFC. You can create a MFC project, and you will see the forms you are looking for.
 
is this all there is to your project? as wings said, you can't just do stuff in the body of a file without declaring a function- possibly the main method as well- (with the exception of preprocessor stuff).

i would suggest using MFC instead of just plain old win32 API (its a pain in the ***!)... but learning MFC is not a small thing! i don't know it very well myself, but here is a good link.. you have to register.. but the tutorial is good:


read atleast teh first 2 tutorials (if you're using visual c++).

here are a few more links:

 
I have also used VB in the past.. MFC is not quite as simple as that! but i hear it is much more powerful (i dont' knwo it very well!).

also, i heard that they have a new form based thingy for GUIs in MSVC++ .NET. if you are using that, you might want to look into it. can't offer much mroe help on that tho
 
Ok, thanks, I removed the if statement and replaced uninstall() with main(). It works!

For the GUI, here is my situation. I want a main window with a combo box, and 3 buttons: Close, About, Info.

The user pick something from the combo box, click Info and opens a new dialog box that shows info about the app using switch().

My current basic code is:

Code:
#using <mscorlib.dll>
#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;

__gc class DisplayForm : public Form
{
public:
	DisplayForm();	
private:
	ComboBox *appList;

	Button *btnClose;
	Button *btnAbout;
	Button *btnInfo;

	void CloseClick(Object *Sender, EventArgs *Args);
	void AboutClick(Object *Sender, EventArgs *Args);
	void InfoClick(Object *Sender, EventArgs *Args);
	void SelectionChanged(Object *Sender, EventArgs *Args);
};

DisplayForm::DisplayForm()
{

	this->Text = S"App Info";
	this->MinimizeBox = false;
	this->MaximizeBox = false;
	Size = Drawing::Size(420, 320);

	appList = new ComboBox;
	appList->Location = Point(16, 30);
	appList->Text = S"Test1";
	appList->Items->Add(S"Test2");
	appList->Items->Add(S"Test1");
	appList->add_SelectedIndexChanged(new EventHandler(this, SelectionChanged));
	this->Controls->Add(appList);
        //more code here
}

void DisplayForm::SelectionChanged(Object *Sender, EventArgs *Args)
{
	txtIntro->Text = appList->Text;
} //?? useless, i think

void DisplayForm::CloseClick(Object *Sender, EventArgs *Args)
{
	Close();
}

void DisplayForm::AboutClick(Object *Sender, EventArgs *Args)
{
	//Clicked aobut
}

void DisplayForm::InfoClick(Object *Sender, EventArgs *Args)
{
	//Clicked info (how to open new dialog and passing the appList->Text; var?
}

int __stdcall WinMain()
{
	DisplayForm *SF = new DisplayForm();
	Application::Run(SF);

	return 0;
}

Is it the right thing to use? Any suggestion on how I could make it better? (And pass the application name from the combo box to the new dialog ;))
 
you are now using managed c++ which is different from MFC. With a simple user interface like you are making, that should work just fine.

Good luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top