SchellExecute funktioniert nicht
-
Ich habe eine Programm geschrieben, in dem ich andere Programme starten kann. Das Problem ist nur mit ShellExecute funktioniert das nicht, der Compiler bringt immer die Fehlermeldung:
c:\Dokumente und Einstellungen\eckertj\Eigene Dateien\Visual Studio Projects\Programm Control\Form1.h(181): error C3861: 'ShellExecute': Bezeichner wurde auch mit einer argumentbezogenen Suche nicht gefundenDer Quellcode dazu:
pragma once#include <windows.h>
#include <iostream>
namespace ProgrammControl
{
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace std;/// <summary>
/// Zusammenfassung für Form1
///
/// Achtung: Wenn Sie den Namen dieser Klasse ändern, müssen Sie die Eigenschaft
/// 'Ressourcendateiname' für das Compilertool für verwaltete Ressourcen ändern,
/// das allen .resx-Dateien zugewiesen ist, von denen diese Klasse abhängt.
/// Anderenfalls können die Designer nicht korrekt mit den lokalisierten Ressourcen
/// arbeiten, die diesem Formular zugewiesen sind.
/// </summary>
public __gc class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
}protected:
void Dispose(Boolean disposing)
{
if (disposing && components)
{
components->Dispose();
}
__super::Dispose(disposing);
}
private: System::Windows::Forms::Button * button1;private: System::Windows::Forms::Button * button2;
private: System::Windows::Forms::GroupBox * groupBox1;
private: System::Windows::Forms::CheckBox * checkBox1;
private: System::Windows::Forms::CheckBox * checkBox2;
private: System::Windows::Forms::CheckBox * checkBox3;
private: System::Windows::Forms::CheckBox * checkBox4;
private: System::Windows::Forms::CheckBox * checkBox5;
private: System::Windows::Forms::Label * label1;private:
/// <summary>
/// Erforderliche Designervariable.
/// </summary>
System::ComponentModel::Container * components;/// <summary>
/// Erforderliche Methode für die Designerunterstützung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
/// </summary>
void InitializeComponent(void)
{
this->button1 = new System::Windows::Forms::Button();
this->button2 = new System::Windows::Forms::Button();
this->groupBox1 = new System::Windows::Forms::GroupBox();
this->checkBox1 = new System::Windows::Forms::CheckBox();
this->checkBox2 = new System::Windows::Forms::CheckBox();
this->checkBox3 = new System::Windows::Forms::CheckBox();
this->checkBox4 = new System::Windows::Forms::CheckBox();
this->checkBox5 = new System::Windows::Forms::CheckBox();
this->label1 = new System::Windows::Forms::Label();
this->groupBox1->SuspendLayout();
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(24, 312);
this->button1->Name = S"button1";
this->button1->Size = System::Drawing::Size(120, 32);
this->button1->TabIndex = 0;
this->button1->Text = S"button1";
this->button1->Click += new System::EventHandler(this, button1_Click);
//
// button2
//
this->button2->Location = System::Drawing::Point(192, 312);
this->button2->Name = S"button2";
this->button2->Size = System::Drawing::Size(120, 32);
this->button2->TabIndex = 2;
this->button2->Text = S"button2";
this->button2->Click += new System::EventHandler(this, button2_Click);
//
// groupBox1
//
this->groupBox1->Controls->Add(this->checkBox1);
this->groupBox1->Controls->Add(this->checkBox2);
this->groupBox1->Controls->Add(this->checkBox3);
this->groupBox1->Controls->Add(this->checkBox4);
this->groupBox1->Controls->Add(this->checkBox5);
this->groupBox1->Location = System::Drawing::Point(16, 64);
this->groupBox1->Name = S"groupBox1";
this->groupBox1->Size = System::Drawing::Size(304, 232);
this->groupBox1->TabIndex = 3;
this->groupBox1->TabStop = false;
this->groupBox1->Text = S"groupBox1";
//
// checkBox1
//
this->checkBox1->Location = System::Drawing::Point(24, 32);
this->checkBox1->Name = S"checkBox1";
this->checkBox1->Size = System::Drawing::Size(80, 24);
this->checkBox1->TabIndex = 0;
this->checkBox1->Text = S"checkBox1";
//
// checkBox2
//
this->checkBox2->Location = System::Drawing::Point(24, 72);
this->checkBox2->Name = S"checkBox2";
this->checkBox2->Size = System::Drawing::Size(80, 24);
this->checkBox2->TabIndex = 0;
this->checkBox2->Text = S"checkBox1";
//
// checkBox3
//
this->checkBox3->Location = System::Drawing::Point(24, 112);
this->checkBox3->Name = S"checkBox3";
this->checkBox3->Size = System::Drawing::Size(80, 24);
this->checkBox3->TabIndex = 0;
this->checkBox3->Text = S"checkBox1";
//
// checkBox4
//
this->checkBox4->Location = System::Drawing::Point(24, 152);
this->checkBox4->Name = S"checkBox4";
this->checkBox4->Size = System::Drawing::Size(80, 24);
this->checkBox4->TabIndex = 0;
this->checkBox4->Text = S"checkBox1";
//
// checkBox5
//
this->checkBox5->Location = System::Drawing::Point(24, 192);
this->checkBox5->Name = S"checkBox5";
this->checkBox5->Size = System::Drawing::Size(128, 24);
this->checkBox5->TabIndex = 0;
this->checkBox5->Text = S"checkBox1";
//
// label1
//
this->label1->Location = System::Drawing::Point(16, 16);
this->label1->Name = S"label1";
this->label1->Size = System::Drawing::Size(304, 24);
this->label1->TabIndex = 4;
this->label1->Text = S"label1";
//
// Form1
//
this->AutoScaleBaseSize = System::Drawing::Size(5, 13);
this->ClientSize = System::Drawing::Size(336, 365);
this->Controls->Add(this->label1);
this->Controls->Add(this->groupBox1);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->Name = S"Form1";
this->Load += new System::EventHandler(this, Form1_Load);
this->groupBox1->ResumeLayout(false);
this->ResumeLayout(false);}
private: System::Void button1_Click(System::Object * sender, System::EventArgs * e)
{
// Messagebox ausgeben
MessageBox(NULL,TEXT("Programm wird beendet"),TEXT("Bitte warten"),0);
// Programm beenden
Form1::Close();
}
private: System::Void button2_Click(System::Object * sender, System::EventArgs * e)
{
if(this->checkBox1->Checked == true)
{
ShellExecute(0, "open", "WINWORD.EXE",0, 0, SW_SHOWNORMAL);
}
}Ich hoffe das mir jemand helfen kann, ich habe noch nicht viel erfahrung in C++
-
Dieses Namespace-Kuddelmuddel sieht ja grauenhaft aus - für was für ein System schreibst du denn? Ich tippe ja stark darauf, daß du dort einen Namensraum vergessen hast einzubinden.
PS ein kleines Geschenk: [cpp]
-
Dieses Namespace-Kuddelmuddel ist nicht von mir sondern von Visual Studio.net
System Windows XP Professional. Ich hab das selbe Programm als Konsolenprogramm geschrieben, da funktioniert es super.
-
-
Danke, dann werde ich mich da mal durch arbeiten.
-
Versuch mal:
ShellExecute(0, _T("open"), _T("WINWORD.EXE"), NULL, NULL, SW_SHOWNORMAL);
-
Jochen Kalmbach schrieb:
Versuch mal:
ShellExecute(0, _T("open"), _T("WINWORD.EXE"), NULL, NULL, SW_SHOWNORMAL);
Habs versucht, aber es kommt wieder die selbe Fehlermeldung:
c:\Dokumente und Einstellungen\eckertj\Eigene Dateien\Visual Studio Projects\Programm Control\Form1.h(232): error C3861: 'ShellExecute': Bezeichner wurde auch mit einer argumentbezogenen Suche nicht gefunden
-
Und wenn Du ein "::" davorschreibst? also
::ShellExecute(0, _T("open"), _T("WINWORD.EXE"), NULL, NULL, SW_SHOWNORMAL);
-
Ich hoffe das der Quellcode jetzt besser zu lesen ist
#pragma once #include <windows.h> #include <iostream> namespace ProgrammControl { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; using namespace std; /// <summary> /// Zusammenfassung für Form1 /// /// Achtung: Wenn Sie den Namen dieser Klasse ändern, müssen Sie die Eigenschaft /// 'Ressourcendateiname' für das Compilertool für verwaltete Ressourcen ändern, /// das allen .resx-Dateien zugewiesen ist, von denen diese Klasse abhängt. /// Anderenfalls können die Designer nicht korrekt mit den lokalisierten Ressourcen /// arbeiten, die diesem Formular zugewiesen sind. /// </summary> public __gc class Form1 : public System::Windows::Forms::Form { public: Form1(void) { InitializeComponent(); } protected: void Dispose(Boolean disposing) { if (disposing && components) { components->Dispose(); } __super::Dispose(disposing); } private: System::Windows::Forms::Button * button1; private: System::Windows::Forms::Button * button2; private: System::Windows::Forms::GroupBox * groupBox1; private: System::Windows::Forms::CheckBox * checkBox1; private: System::Windows::Forms::CheckBox * checkBox2; private: System::Windows::Forms::CheckBox * checkBox3; private: System::Windows::Forms::CheckBox * checkBox4; private: System::Windows::Forms::CheckBox * checkBox5; private: System::Windows::Forms::Label * label1; private: System::Windows::Forms::CheckBox * checkBox6; private: System::Windows::Forms::CheckBox * checkBox7; private: /// <summary> /// Erforderliche Designervariable. /// </summary> System::ComponentModel::Container * components; /// <summary> /// Erforderliche Methode für die Designerunterstützung. /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. /// </summary> void InitializeComponent(void) { this->button1 = new System::Windows::Forms::Button(); this->button2 = new System::Windows::Forms::Button(); this->groupBox1 = new System::Windows::Forms::GroupBox(); this->checkBox1 = new System::Windows::Forms::CheckBox(); this->checkBox2 = new System::Windows::Forms::CheckBox(); this->checkBox3 = new System::Windows::Forms::CheckBox(); this->checkBox4 = new System::Windows::Forms::CheckBox(); this->checkBox5 = new System::Windows::Forms::CheckBox(); this->label1 = new System::Windows::Forms::Label(); this->checkBox6 = new System::Windows::Forms::CheckBox(); this->checkBox7 = new System::Windows::Forms::CheckBox(); this->groupBox1->SuspendLayout(); this->SuspendLayout(); // // button1 // this->button1->Location = System::Drawing::Point(24, 312); this->button1->Name = S"button1"; this->button1->Size = System::Drawing::Size(120, 32); this->button1->TabIndex = 0; this->button1->Text = S"button1"; this->button1->Click += new System::EventHandler(this, button1_Click); // // button2 // this->button2->Location = System::Drawing::Point(320, 312); this->button2->Name = S"button2"; this->button2->Size = System::Drawing::Size(120, 32); this->button2->TabIndex = 2; this->button2->Text = S"button2"; this->button2->Click += new System::EventHandler(this, button2_Click); // // groupBox1 // this->groupBox1->Controls->Add(this->checkBox1); this->groupBox1->Controls->Add(this->checkBox2); this->groupBox1->Controls->Add(this->checkBox3); this->groupBox1->Controls->Add(this->checkBox4); this->groupBox1->Controls->Add(this->checkBox5); this->groupBox1->Controls->Add(this->checkBox6); this->groupBox1->Controls->Add(this->checkBox7); this->groupBox1->Location = System::Drawing::Point(16, 64); this->groupBox1->Name = S"groupBox1"; this->groupBox1->Size = System::Drawing::Size(424, 192); this->groupBox1->TabIndex = 3; this->groupBox1->TabStop = false; this->groupBox1->Text = S"groupBox1"; // // checkBox1 // this->checkBox1->Location = System::Drawing::Point(24, 32); this->checkBox1->Name = S"checkBox1"; this->checkBox1->Size = System::Drawing::Size(80, 24); this->checkBox1->TabIndex = 0; this->checkBox1->Text = S"checkBox1"; // // checkBox2 // this->checkBox2->Location = System::Drawing::Point(24, 72); this->checkBox2->Name = S"checkBox2"; this->checkBox2->Size = System::Drawing::Size(80, 24); this->checkBox2->TabIndex = 0; this->checkBox2->Text = S"checkBox1"; // // checkBox3 // this->checkBox3->Location = System::Drawing::Point(24, 112); this->checkBox3->Name = S"checkBox3"; this->checkBox3->Size = System::Drawing::Size(80, 24); this->checkBox3->TabIndex = 0; this->checkBox3->Text = S"checkBox1"; // // checkBox4 // this->checkBox4->Location = System::Drawing::Point(24, 152); this->checkBox4->Name = S"checkBox4"; this->checkBox4->Size = System::Drawing::Size(80, 24); this->checkBox4->TabIndex = 0; this->checkBox4->Text = S"checkBox1"; // // checkBox5 // this->checkBox5->Location = System::Drawing::Point(208, 32); this->checkBox5->Name = S"checkBox5"; this->checkBox5->Size = System::Drawing::Size(128, 24); this->checkBox5->TabIndex = 0; this->checkBox5->Text = S"checkBox1"; // // label1 // this->label1->Location = System::Drawing::Point(16, 16); this->label1->Name = S"label1"; this->label1->Size = System::Drawing::Size(304, 24); this->label1->TabIndex = 4; this->label1->Text = S"label1"; // // checkBox6 // this->checkBox6->Location = System::Drawing::Point(208, 72); this->checkBox6->Name = S"checkBox6"; this->checkBox6->Size = System::Drawing::Size(128, 24); this->checkBox6->TabIndex = 0; this->checkBox6->Text = S"checkBox1"; // // checkBox7 // this->checkBox7->Location = System::Drawing::Point(208, 112); this->checkBox7->Name = S"checkBox7"; this->checkBox7->Size = System::Drawing::Size(128, 24); this->checkBox7->TabIndex = 0; this->checkBox7->Text = S"checkBox1"; // // Form1 // this->AutoScaleBaseSize = System::Drawing::Size(5, 13); this->ClientSize = System::Drawing::Size(456, 365); this->Controls->Add(this->label1); this->Controls->Add(this->groupBox1); this->Controls->Add(this->button2); this->Controls->Add(this->button1); this->Name = S"Form1"; this->Load += new System::EventHandler(this, Form1_Load); this->groupBox1->ResumeLayout(false); this->ResumeLayout(false); } private: System::Void button1_Click(System::Object * sender, System::EventArgs * e) { // Messagebox ausgeben this->label1->Text = "Programm wird beendet"; MessageBox(NULL,TEXT("Programm wird beendet"),TEXT("Bitte warten"),0); // Programm beenden Form1::Close(); } private: System::Void button2_Click(System::Object * sender, System::EventArgs * e) { if(this->checkBox1->Checked == true) { ShellExecute(0, "open", "WINWORD.EXE",0, 0, SW_SHOWNORMAL); } } private: System::Void Form1_Load(System::Object * sender, System::EventArgs * e) { // Objekte beschriften this->Form1::Text = "Programm starten"; this->label1->Text = "Bitte wählen Sie das Programm das gestartet werden soll"; this->button1->Text = "Beenden"; this->button2->Text = "Ausführen"; this->groupBox1->Text = "Programm auswählen"; this->checkBox1->Text = "Word"; this->checkBox2->Text = "Excel"; this->checkBox3->Text = "Paint"; this->checkBox4->Text = "Phase5"; this->checkBox5->Text = "PC Herunterfahren"; this->checkBox6->Text = "PC Neustarten"; this->checkBox7->Text = "Abmelden"; // Setzen der Fensterfarbe Form1::set_BackColor(System::Drawing::Color::AliceBlue); } }; }