Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 22, 2011, 10:28 AM   #1
chunhohuen
macrumors newbie
 
Join Date: Apr 2011
C++ new hand problem 3 please help (about GUI Interface)

With the great help in the previous posts, I want to thank all of them!

This is quite a long post and I hope it does not bore you

After I write and the function in the previous posts, now I use them in the GUI Interface but I think GUI is my weakest part....

First,I create 2 forms.

Form 1 is let the user input the name and select whether create a new account or use the old account.




The header file of Form 1 is :
#pragma once
#include "Form2.h"
#include <fstream>

namespace login_GUI {

using namespace System;
.....
using namespace System::Runtime::InteropServices; //For the class Marshal

/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
void read();
void write();
void find();
void setuser();
}
...
...

private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
void read() {}
void write(){}
void find(){}
void setuser(){}
...
...

#pragma endregion

private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) // The create new user bottom

{
Form2 ^F2= gcnew Form2();
F2->ShowDialog();
}


private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) // The login as old botton

{
Form2 ^F2= gcnew Form2();
F2->ShowDialog();
}
};
}




Form 2 is show the user input and the buttom to close the form.




The header file of Form 2 is :
#pragma once

namespace login_GUI {

using namespace System;
...
...
...
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) // the close button
{
this->Close();
}
};


My problem is I have no idea to use my written function applied in the GUI.....
chunhohuen is offline   0 Reply With Quote
Old Apr 22, 2011, 10:31 AM   #2
chunhohuen
Thread Starter
macrumors newbie
 
Join Date: Apr 2011
I divide it to 2 posts in order to avoiding one too long post.


The details function are :

The code :

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

char inputusername[99];// let the user to input the user name

void find()

{
ifstream file;
file.open("file.txt");

string input=inputusername;
string input_line;
bool found = false;

while( file >> input_line ) {
if( input_line.compare(input) == 0 ) {
cout << "The name " << input_line << " was found in file.\n";
found = true;
break;
}
}

if( found == false ) {
ofstream fout ("file.txt",ios::app);
fout<<inputusername<<endl;
fout.close();
}

file.close();

}


void setuser() //function of set the username
{
cout<<"Enter the username: "<<endl;
cin>>inputusername;
int score=0;
}


void read() //read the file and show the details
{
cout<<endl;
ifstream fin("file.txt");
char ch;
while (fin.get(ch))
cout<<ch;
fin.close();
}


void write() //read the input to the file
{
ofstream fout ("file.txt",ios::app);
fout<<inputusername<<endl;
fout.close();
}
chunhohuen is offline   0 Reply With Quote
Old Apr 22, 2011, 06:06 PM   #3
jiminaus
macrumors 65816
 
Join Date: Dec 2010
Location: Sydney
Mate, let me pass on a few points about forum etiquette.

Surround your code in [code] ... [/code] tags. The mods are probably getting sick and tired of doing this for you. The easiest way to do is to highlight the code then click the # button in the message editor toolbar.

Be more appropriate with your subjects. The purpose of subject lines is so people can best guess what the threads about. Use specific terms. Don't put "please help" in a subject line, it won't get you anymore help then you would leave it out.

Tell what the problem is. Don't just post code and expect us to work it out. Be as specific as possible. Tell us what your're expecting to happening, what is happening, what's not happening. Copy and paste error messages. Tell us what you've already tried to do yourself to fix the problem. (I'm sounding like chown33! LOL).

Finally, take this to a Windows programming forum. This is a Mac programming forum. Coding in Windows on Mac hardware either via boot camp or virtualisation doesn't count as Mac programming.
jiminaus is offline   0 Reply With Quote
Old Apr 23, 2011, 01:18 AM   #4
chunhohuen
Thread Starter
macrumors newbie
 
Join Date: Apr 2011
Quote:
Originally Posted by jiminaus View Post
Mate, let me pass on a few points about forum etiquette.

Surround your code in [code] ... [/code] tags. The mods are probably getting sick and tired of doing this for you. The easiest way to do is to highlight the code then click the # button in the message editor toolbar.

Be more appropriate with your subjects. The purpose of subject lines is so people can best guess what the threads about. Use specific terms. Don't put "please help" in a subject line, it won't get you anymore help then you would leave it out.

Tell what the problem is. Don't just post code and expect us to work it out. Be as specific as possible. Tell us what your're expecting to happening, what is happening, what's not happening. Copy and paste error messages. Tell us what you've already tried to do yourself to fix the problem. (I'm sounding like chown33! LOL).

Finally, take this to a Windows programming forum. This is a Mac programming forum. Coding in Windows on Mac hardware either via boot camp or virtualisation doesn't count as Mac programming.
THX for the tips I will try to correct the question
chunhohuen is offline   0 Reply With Quote
Old Apr 23, 2011, 02:34 AM   #5
chunhohuen
Thread Starter
macrumors newbie
 
Join Date: Apr 2011
C++ new hand problem 3 please help (about GUI corrected)

Thanks for the tips that now I correct my question in this way.

I have rewritten my function become more simple.

The code is:

char inputusername[99];

void createnewaccount() //function of set the username
{
cout<<"Enter the username: "<<endl;
cin>>inputusername;
int score=0;
ofstream fout ("file.txt",ios::app);
fout<<inputusername<<endl;
fout.close();
}


void createnewaccount() //function of set the username

{
cout<<"Enter the username: "<<endl;
cin>>inputusername;
int score=0;
ofstream fout ("file.txt",ios::app);
fout<<inputusername<<endl;
fout.close();
}

But, there is a problem, I don not think there are any cin function in the GUI. Therefore, if I cannot use those function in GUI.

I know that the textbox of the GUI can let user input the data and label can display the user input.
How can transfer the cin to textbox and use the cout as label?

Last edited by chunhohuen; Apr 23, 2011 at 03:12 AM.
chunhohuen is offline   0 Reply With Quote
Old Apr 23, 2011, 12:52 PM   #6
wlh99
macrumors 6502
 
Join Date: Feb 2008
Quote:
Originally Posted by chunhohuen View Post
Thanks for the tips that now I correct my question in this way.

I have rewritten my function become more simple.

The code is:
As was pointed out, this is a Mac forum. You are asking a Windows specific question. Most likely few people here have Visual Studio, few know Visual c++, and no one will be able to help you.

You should look for a forum that offers Windows help.
__________________
Warren Holybee
wlh99 is offline   0 Reply With Quote
Old Apr 23, 2011, 06:00 PM   #7
balamw
Moderator
 
balamw's Avatar
 
Join Date: Aug 2005
Location: New England, USA
Quote:
Originally Posted by wlh99 View Post
Most likely few people here have Visual Studio, few know Visual c++, and no one will be able to help you.
Many of us do have and use VC++, but are hiding out here.

chunhohuen, what resources are you using to learn Visual C++/Windows Forms/.NET?

What you are asking for should be covered in any book on the subject. You should not expect to learn programming without a good reference resource.

I don't know of one myself, but this looks like it covers the basics. http://www.amazon.com/Ivor-Hortons-B.../dp/0470500883

B
__________________
MBA (13" 1.7 GHz 128GB), UMBP (15" SD 2.8 GHz), UMB (13" 2.4 GHz), iMac (17" Yonah), 32GB iPad 3 WiFi+LTE, 64 GB iPad WiFi, 32 GB iPhone 5, Airport Extreme
balamw is offline   0 Reply With Quote
Old Apr 23, 2011, 09:35 PM   #8
MattMcClinch
macrumors newbie
 
Join Date: Jan 2008
You have much to learn about object-oriented programming.

First, forget cin and cout. They are of no use to you.

Second, find out the names of your textbox and label objects. They are most likely something like textbox1 and label1. Once you locate them, please change them to something more descriptive.

Now it is just a matter of getting and setting the "Text" property of your textbox and label objects. Note: it might be called "text" or "label" or "string" or something else entirely. I am going to call it "Text".

Code:
label1.Text = "Enter the user name:";
Code:
inputusername = textbox1.Text;
At this point, you are going to get an error, because inputusername is a character array, and does not match the type of textbox1.Text.
MattMcClinch is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Problem with iPhone 3GS on 4.3. Please help apatel87 iPhone 6 Jun 30, 2011 07:24 PM
C++ new hand problem 2 please help (about library) chunhohuen Mac Programming 3 Apr 22, 2011 08:05 AM
C++ new hand problem please help chunhohuen Mac Programming 14 Apr 22, 2011 01:43 AM
Gophone sim on iPhone 3gs 3.1.3 please help Ahbba iPhone Tips, Help and Troubleshooting 23 Jul 5, 2010 09:33 PM
i got new iphone 1.1.3 please help !!!! dorliberty Jailbreaks and iOS Hacks 3 Feb 14, 2008 04:07 PM


All times are GMT -5. The time now is 12:04 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC