'Shell': identifier not found - c++-cli

I get this when trying to execute this C++ program. Why?
The code is:
private:
System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Shell("maplestory.exe")

You either need System.Shell.execute from the .NET library or you need to call the Windows API ShellExecute.

Related

(C++ / CLI) Set contents of textbox to content of a .txt

I am looking to set the contents of a textbox to that of a .txt file,
however I cannot get it to work. I have a button which would "refresh" the
content of the textbox to that of the .txt file, here is the code I am using:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
std::ifstream dat1("DataStore.txt");
String^ textHolder;
if (dat1.is_open())
{
while ( getline(dat1, line) )
{
textHolder += line.c_str;
}
textBox1->Text = textHolder;
dat1.close();
}
else textBox1->Text = "Unable to open file";
}
I get these 2 errors when compiling the program:
error C3867: 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::c_str': function call missing argument list; use '&std::basic_string<char,std::char_traits<char>,std::allocator<char>>::c_str' to create a pointer to member
error C2297: '+=' : illegal, right operand has type 'const char *(__thiscall std::basic_string<char,std::char_traits<char>,std::allocator<char>>::* )(void) throw() const'
How do I make this work?
NOTE: I am trying to display the whole .txt file's contents in the textbox
If you are going to use C++/CLI you may as well take advantage of .net. You can use the File class to read the file for you:
System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
textBox1->Text = System::IO::File::ReadAllText("DataStore.txt");
}
You'll need to hope that the process working directory contains that file. In a GUI app you are better served by specifying full paths to files, since the working directory is typically ill-defined.
If you are trying to learn C++, then perhaps a .net C++/CLI WinForms application is not the place to start.
You forgot to end method c_str, change it to c_str()

C++ will change it last input

I don't know if anyone had the same problem.
I use Microsoft visual C++ 2010 I am new to it but I know a lot of Java program but for me trying to go from one program to another is confusing.
Anyway I will make a basic program "Hello World" and run it it works fine but when I go and try to type something else or add something to the text it remains the same code when I run it. It does not happen all the time but it will do it a lot and it seam like it is becoming more common.
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
label1 -> Text = "hello world";
}
This is what I put.
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
label1 -> Text = "This is a test";
}
when I run the first code it works, but when I change to the code and put in the 2nd code it will remain the first code when I run it, but I change what the code say so it should change as well but it does not.
There is a setting that controls whether Visual Studio forces a build before you run, likely you set it to false.
Here is a similar question
Tools + Options, Projects and Solutions, Build and Run. "On Run, when projects are out of date" = Always build.

How to delete KeyValue in Visual studio 2012 c++ richTextBox

How i can delete the key which presente "Enter"?? I want the programme show "Plase enter Espace or Tab" when the user tape Enter and then delete this Enter Key. Thank you!
private: System::Void richTextBoxCommentaire_KeyDown(System::Object^ sender, System::Windows::Forms::KeyEventArgs^ e) {
if (e->KeyValue == (char)13)
{
MessageBox::Show ("Please enter Espace or Tab");
//To delete this Key??
}
}
sorry, using the previewKeyDown should have worked but try the next method :
Use the KeyDown event to filter the desired keys by setting the suppressKeyPress to true as you can see in the example below (the example is in C# for readability but conversion to C++ CLI should be trivial :) :
private void richTextBox1_KeyDown(object sender, KeyEventArgs e)
{
e.SuppressKeyPress = e.KeyCode == Keys.Enter;
}

Get information from different hidden Form C++/clr

I have a Windows Form application I am creating in C++/CLR Visual Studio 2012.
The goal is to have the user input values into the form named Home Page. Then once all the info is filled in they click a button and the Home Page form is hidden and then second form called Setup Info is shown.
The part I need help with is the info from Home Page needs to be accessible in Setup Info. To get an idea of how my files are setup this is the youtube video I followed to create my C++ Windows Form Application Click Here.
In my HomePage.h
// Button that will hide the Home Page Form and then show the SetupInfo Form.
private: System::Void Start_Click(System::Object^ sender, System::EventArgs^ e) {
this->Hide();
SetupInfo^ SetupInfo = gcnew ExcelToPPT::SeuUpInfo();
SetupInfo->Show();
}
In my Setup Info.H
// When Setup Info is loaded button1 will have the text of textbox1 from Home Page Form.
private: System::Void SetupInfo_Load(System::Object^ sender, System::EventArgs^ e) {
button1->Text = HomePage->Textbox1->Text;
}
This is the general idea but it doesn't work. How do I get this to work?
Let me know if you need any more information.
[EDIT]
I am able to do this through extern global variables, but is there another way to directly access the text text boxes?
Also wen I exit out of my Setup Information it doesn't seem to kill my program how do I solve this problem?
The simplest thing would probably be to just pass your Home Page form to the new SetUpInfo form.
private: System::Void Start_Click(System::Object^ sender, System::EventArgs^ e) {
this->Hide();
SetUpInfo^ setUpInfo = gcnew ExcelToPPT::SetUpInfo(this);
setUpInfo->Show(); ^^^^
}
In SetUpInfo.h:
public ref class SetUpInfo : Form
{
private:
HomePage^ homePage;
public:
SetUpInfo(HomePage^ homePage);
};
In SetUpInfo.cpp:
SetUpInfo::SetUpInfo(HomePage^ homePage)
{
this->homePage = homePage;
}
void SetUpInfo::SetUpInfo_Load(System::Object^ sender, System::EventArgs^ e)
{
button1->Text = this->homePage->Textbox1->Text;
}

How to navigate from one page to another in Windows phone 8 using XAML?

I am trying to make my first WP8 app but, i got a problem. I try to navigate to another page using the code below, but VS12 throws a error.
What am I doing wrong?
private void btnBMIBereken_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/BMI_Bereken.xaml", UriKind.Relative));
}
Your code is correct for navigating, just make sure the Page 'BMI_Bereken.xaml' actual exists at the root of your project.
Clean solution first and then rebuild again (right click on project/solution -> clean)
Then if it still crashes, try to use System.Windows.RoutedEventArgs e instead of RoutedEventArgs e
Guys i found the problem.
I use a self made button style for my buttons and i got on the visualstate pressed some wrong code. In fact I was trying to set the background collor of the button in the place of the name target name.
See the code below for what i did wrong.
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="#FF009AD3">
I know very stupid, but I want to thank everyone for the help.
Try this
private void btnBMIBereken_Click(object sender, RoutedEventArgs e)
{
Dispatcher.BeginInvoke(() =>
{
this.NavigationService.Navigate(new Uri("/BMI_Bereken.xaml", UriKind.Relative));
});
}
You could do something like this:
private void btnLogin_Click(object sender, RoutedEventArgs e)
{
if (txtDriverId.Text == "D0001" && txtPassword.Password == "open")
{
Frame.Navigate(typeof(VehicleCondition));
}
}