IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Visual Studio Discussion :

Aide - visual studio 2008 - windows form application


Sujet :

Visual Studio

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 14
    Points : 7
    Points
    7
    Par défaut Aide - visual studio 2008 - windows form application
    Bonjour,

    Suite à mon précédent post: http://www.developpez.net/forums/sho...d.php?t=552899

    J'ai voulu créer un programme sous visual studio 2008 avec des windows form application me permettant de gérer les 2 moteurs.
    Cependant j'ai des erreurs, et je ne sais pas comment les corriger:

    Voici mon programme form.h:
    #pragma once
    #include "stdafx.h"
    #include "Form1.h"
    #include "E:\Stage_robot\Stepper Bee +\stp.h" // rename the header file
    #include "windows.h"
    #include "tchar.h" //UNICODE

    namespace Control_Robot_ER1 {

    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;

    /// <summary>
    /// Summary for Form1
    ///
    /// WARNING: If you change the name of this class, you will need to change the
    /// 'Resource File Name' property for the managed resource compiler tool
    /// associated with all .resx files this class depends on. Otherwise,
    /// the designers will not be able to interact properly with localized
    /// resources associated with this form.
    /// </summary>

    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
    Form1(void)
    {
    InitializeComponent();
    //
    //TODO: Add the constructor code here
    //
    }


    protected:
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    ~Form1()
    {
    if (components)
    {
    delete components;
    }
    }
    private: System::Windows::Forms::Button^ button1;
    protected:
    private: System::Windows::Forms::Button^ button2;
    private: System::Windows::Forms::Button^ button3;
    private: System::Windows::Forms::Button^ button4;
    private: System::Windows::Forms::Button^ button5;
    private: System::Windows::Forms::Label^ label1;
    private: System::Windows::Forms::Button^ button6;
    private: System::Windows::Forms::Button^ button7;
    private: System::Windows::Forms::Label^ label2;
    private: System::Windows::Forms::Label^ label3;
    private: System::Windows::Forms::TextBox^ textBox1;
    private: System::Windows::Forms::Label^ label4;
    private: System::Windows::Forms::TextBox^ textBox2;
    private: System::Windows::Forms::Label^ label5;
    private: System::Windows::Forms::Button^ button8;
    private: System::Windows::Forms::Label^ label6;
    private: System::Windows::Forms::ComboBox^ comboBox1;

    private:
    /// <summary>
    /// Required designer variable.
    /// </summary>
    System::ComponentModel::Container ^components;

    #pragma region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    void InitializeComponent(void)
    {
    this->button1 = (gcnew System::Windows::Forms::Button());
    this->button2 = (gcnew System::Windows::Forms::Button());
    this->button3 = (gcnew System::Windows::Forms::Button());
    this->button4 = (gcnew System::Windows::Forms::Button());
    this->button5 = (gcnew System::Windows::Forms::Button());
    this->label1 = (gcnew System::Windows::Forms::Label());
    this->button6 = (gcnew System::Windows::Forms::Button());
    this->button7 = (gcnew System::Windows::Forms::Button());
    this->label2 = (gcnew System::Windows::Forms::Label());
    this->label3 = (gcnew System::Windows::Forms::Label());
    this->textBox1 = (gcnew System::Windows::Forms::TextBox());
    this->label4 = (gcnew System::Windows::Forms::Label());
    this->textBox2 = (gcnew System::Windows::Forms::TextBox());
    this->label5 = (gcnew System::Windows::Forms::Label());
    this->button8 = (gcnew System::Windows::Forms::Button());
    this->label6 = (gcnew System::Windows::Forms::Label());
    this->comboBox1 = (gcnew System::Windows::Forms::ComboBox());
    this->SuspendLayout();
    //
    // button1
    //
    this->button1->Location = System::Drawing::Point(83, 12);
    this->button1->Name = L"button1";
    this->button1->Size = System::Drawing::Size(75, 23);
    this->button1->TabIndex = 0;
    this->button1->Text = L"Forward";
    this->button1->UseVisualStyleBackColor = true;
    this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
    //
    // button2
    //
    this->button2->Location = System::Drawing::Point(12, 41);
    this->button2->Name = L"button2";
    this->button2->Size = System::Drawing::Size(75, 23);
    this->button2->TabIndex = 1;
    this->button2->Text = L"Left";
    this->button2->UseVisualStyleBackColor = true;
    this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
    //
    // button3
    //
    this->button3->Location = System::Drawing::Point(153, 41);
    this->button3->Name = L"button3";
    this->button3->Size = System::Drawing::Size(75, 23);
    this->button3->TabIndex = 2;
    this->button3->Text = L"Right";
    this->button3->UseVisualStyleBackColor = true;
    this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
    //
    // button4
    //
    this->button4->Location = System::Drawing::Point(83, 71);
    this->button4->Name = L"button4";
    this->button4->Size = System::Drawing::Size(75, 23);
    this->button4->TabIndex = 3;
    this->button4->Text = L"Backward";
    this->button4->UseVisualStyleBackColor = true;
    this->button4->Click += gcnew System::EventHandler(this, &Form1::button4_Click);
    //
    // button5
    //
    this->button5->BackColor = System::Drawing::Color::Red;
    this->button5->FlatAppearance->BorderColor = System::Drawing::Color::White;
    this->button5->ForeColor = System::Drawing::SystemColors::Control;
    this->button5->Location = System::Drawing::Point(12, 191);
    this->button5->Name = L"button5";
    this->button5->Size = System::Drawing::Size(92, 61);
    this->button5->TabIndex = 4;
    this->button5->Text = L"Stop";
    this->button5->UseVisualStyleBackColor = false;
    this->button5->Click += gcnew System::EventHandler(this, &Form1::button5_Click);
    //
    // label1
    //
    this->label1->AutoSize = true;
    this->label1->Location = System::Drawing::Point(150, 242);
    this->label1->Name = L"label1";
    this->label1->Size = System::Drawing::Size(49, 13);
    this->label1->TabIndex = 5;
    this->label1->Text = L"Direction";
    //
    // button6
    //
    this->button6->Location = System::Drawing::Point(309, 11);
    this->button6->Name = L"button6";
    this->button6->Size = System::Drawing::Size(75, 53);
    this->button6->TabIndex = 6;
    this->button6->Text = L"Swivel on the right";
    this->button6->UseVisualStyleBackColor = true;
    this->button6->Click += gcnew System::EventHandler(this, &Form1::button6_Click);
    //
    // button7
    //
    this->button7->Location = System::Drawing::Point(309, 70);
    this->button7->Name = L"button7";
    this->button7->Size = System::Drawing::Size(75, 57);
    this->button7->TabIndex = 7;
    this->button7->Text = L"Swivel on the left";
    this->button7->UseVisualStyleBackColor = true;
    this->button7->Click += gcnew System::EventHandler(this, &Form1::button7_Click);
    //
    // label2
    //
    this->label2->AutoSize = true;
    this->label2->Location = System::Drawing::Point(245, 242);
    this->label2->Name = L"label2";
    this->label2->Size = System::Drawing::Size(49, 13);
    this->label2->TabIndex = 8;
    this->label2->Text = L"Distance";
    //
    // label3
    //
    this->label3->AutoSize = true;
    this->label3->Location = System::Drawing::Point(80, 114);
    this->label3->Name = L"label3";
    this->label3->Size = System::Drawing::Size(72, 13);
    this->label3->TabIndex = 9;
    this->label3->Text = L"Distance (cm)";
    //
    // textBox1
    //
    this->textBox1->Location = System::Drawing::Point(72, 130);
    this->textBox1->Name = L"textBox1";
    this->textBox1->Size = System::Drawing::Size(100, 20);
    this->textBox1->TabIndex = 10;
    //
    // label4
    //
    this->label4->AutoSize = true;
    this->label4->Location = System::Drawing::Point(319, 133);
    this->label4->Name = L"label4";
    this->label4->Size = System::Drawing::Size(47, 13);
    this->label4->TabIndex = 11;
    this->label4->Text = L"Angle (°)";
    //
    // textBox2
    //
    this->textBox2->Location = System::Drawing::Point(293, 149);
    this->textBox2->Name = L"textBox2";
    this->textBox2->Size = System::Drawing::Size(100, 20);
    this->textBox2->TabIndex = 12;
    //
    // label5
    //
    this->label5->AutoSize = true;
    this->label5->Location = System::Drawing::Point(349, 242);
    this->label5->Name = L"label5";
    this->label5->Size = System::Drawing::Size(34, 13);
    this->label5->TabIndex = 13;
    this->label5->Text = L"Angle";
    //
    // button8
    //
    this->button8->Location = System::Drawing::Point(586, 11);
    this->button8->Name = L"button8";
    this->button8->Size = System::Drawing::Size(75, 53);
    this->button8->TabIndex = 14;
    this->button8->Text = L"Reset";
    this->button8->UseVisualStyleBackColor = true;
    this->button8->Click += gcnew System::EventHandler(this, &Form1::button8_Click);
    //
    // label6
    //
    this->label6->AutoSize = true;
    this->label6->Location = System::Drawing::Point(445, 22);
    this->label6->Name = L"label6";
    this->label6->Size = System::Drawing::Size(72, 13);
    this->label6->TabIndex = 15;
    this->label6->Text = L"Speed (km/h)";
    //
    // comboBox1
    //
    this->comboBox1->FormattingEnabled = true;
    this->comboBox1->Items->AddRange(gcnew cli::array< System::Object^ >(10) {L"0.5 km/h", L"1 km/h", L"1.5 km/h", L"2 km/h",
    L"2.5 km/h", L"3 km/h", L"3.5 km/h", L"4 km/h", L"4.5 km/h", L"5 km/h"});
    this->comboBox1->Location = System::Drawing::Point(423, 41);
    this->comboBox1->Name = L"comboBox1";
    this->comboBox1->Size = System::Drawing::Size(121, 21);
    this->comboBox1->TabIndex = 16;
    //
    // Form1
    //
    this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    this->ClientSize = System::Drawing::Size(689, 264);
    this->Controls->Add(this->comboBox1);
    this->Controls->Add(this->label6);
    this->Controls->Add(this->button8);
    this->Controls->Add(this->label5);
    this->Controls->Add(this->textBox2);
    this->Controls->Add(this->label4);
    this->Controls->Add(this->textBox1);
    this->Controls->Add(this->label3);
    this->Controls->Add(this->label2);
    this->Controls->Add(this->button7);
    this->Controls->Add(this->button6);
    this->Controls->Add(this->label1);
    this->Controls->Add(this->button5);
    this->Controls->Add(this->button4);
    this->Controls->Add(this->button3);
    this->Controls->Add(this->button2);
    this->Controls->Add(this->button1);
    this->Name = L"Form1";
    this->Text = L"ER1_Robot Control";
    this->ResumeLayout(false);
    this->PerformLayout();

    }
    #pragma endregion

    int distance;
    private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
    label1->Text="Forward";

    distance= System::Convert::ToInt64(textBox1->Text);
    label2->Text=String::Format("Distance: {0}", distance);

    InitStp();
    RunMotor1 (1000 ,50 ,0 ,0);
    RunMotor2 (3000 ,20 ,0 ,0);

    }
    private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
    label1->Text="Left";

    distance= System::Convert::ToInt64(textBox1->Text);
    label2->Text=String::Format("Distance: {0}", distance);
    }
    private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
    label1->Text="Right";

    distance= System::Convert::ToInt64(textBox1->Text);
    label2->Text=String::Format("Distance: {0}", distance);
    }
    private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {
    label1->Text="Backward";

    distance= System::Convert::ToInt64(textBox1->Text);
    label2->Text=String::Format("Distance: {0}", distance);
    }
    private: System::Void button5_Click(System::Object^ sender, System::EventArgs^ e) {
    label1->Text="Stop";
    label2->Text="Stop";
    label5->Text="Stop";


    }
    int angle;
    private: System::Void button6_Click(System::Object^ sender, System::EventArgs^ e) {
    label1->Text="Swivel on the right";

    angle= System::Convert::ToInt64(textBox2->Text);
    label5->Text=String::Format("Angle: {0}", angle);

    }
    private: System::Void button7_Click(System::Object^ sender, System::EventArgs^ e) {
    label1->Text="Swivel on the left";

    angle= System::Convert::ToInt64(textBox2->Text);
    label5->Text=String::Format("Angle: {0}", angle);
    }
    private: System::Void button8_Click(System::Object^ sender, System::EventArgs^ e) {

    int angle=0;
    int distance=0;

    label1->Text= "Direction";
    label2->Text= "Distance";
    label5->Text= "Angle";
    }

    };
    }

    Voici mon fichier robot_control_ER1.cpp:
    ///////////////////////////////////////////////////////////////////////////////////////
    #include "stdafx.h"
    #include "Form1.h"
    #include "E:\Stage_robot\Stepper Bee +\stp.h" // rename the header file
    #include "windows.h"
    #include "tchar.h" //UNICODE

    using namespace Control_Robot_ER1;

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

    //
    HINSTANCE HStpDll; // declaration of variable to hold the handle to the dll
    HStpDll = LoadLibrary(_T("stp.dll")); // load the dll into memory and return handle

    Type_InitStp InitStp;
    Type_RunMotor1 RunMotor1;
    Type_StopMotor1 StopMotor1;
    Type_RunMotor2 RunMotor2;
    Type_StopMotor2 StopMotor2;
    Type_SetStepMode SetStepMode;
    Type_GetCurrentStatus GetCurrentStatus;

    InitStp = (Type_InitStp)GetProcAddress( HStpDll, "InitStp");
    RunMotor1 = (Type_RunMotor1)GetProcAddress( HStpDll, "RunMotor1");
    RunMotor2 = (Type_RunMotor2)GetProcAddress( HStpDll, "RunMotor2");
    StopMotor1 = (Type_StopMotor1)GetProcAddress( HStpDll, "StopMotor1");
    StopMotor2 = (Type_StopMotor2)GetProcAddress( HStpDll, "StopMotor2");
    SetStepMode = (Type_SetStepMode)GetProcAddress( HStpDll, "SetStepMode");
    GetCurrentStatus = (Type_GetCurrentStatus)GetProcAddress(HStpDll,"GetCurrentStatus");

    InitStp();

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

    //

    return 0;
    }
    ///////////////////////////////////////////////////////////////////////////////////////
    Et voici mes erreurs:

    1>c:\users\fabien\documents\visual studio 2008\projects\programme\control_robot_er1\control_robot_er1\Form1.h(304) : error C3861: 'InitStp': identifier not found

    1>c:\users\fabien\documents\visual studio 2008\projects\programme\control_robot_er1\control_robot_er1\Form1.h(305) : error C3861: 'RunMotor1': identifier not found

    1>c:\users\fabien\documents\visual studio 2008\projects\programme\control_robot_er1\control_robot_er1\Form1.h(306) : error C3861: 'RunMotor2': identifier not found

    Je ne comprend pas mes erreurs car comme vous pouvez le voir sur le précédent post, en win32 application tous fonctionner correctement.

    Merci d'avance

    Fab

    ps: désolé pour la longueur du message mais je n'arrivais pas à l'éditer autrement.

  2. #2
    Inactif  

    Homme Profil pro
    Ingénieur test de performance
    Inscrit en
    Décembre 2003
    Messages
    1 986
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Ingénieur test de performance
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Décembre 2003
    Messages : 1 986
    Points : 2 605
    Points
    2 605
    Par défaut
    Bonjour.

    Il semblerait que tu déclares les valeurs de "InitStp, RunMotor1, etc..." dans le fichier robot_control_ER1.cpp. Le fichier "form.h", ne peut pas connaître ces valeurs.

    Toute valeur déclarée dans un .cpp ne peut pas être connue par un .h.

    Plusieurs possibilités, par exemple, avec un .h :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
     
    // global.h
     
    extern Type_InitStp InitStp;
    extern Type_RunMotor1 RunMotor1;
    extern Type_StopMotor1 StopMotor1;
    extern Type_RunMotor2 RunMotor2;
    extern Type_StopMotor2 StopMotor2;
    extern Type_SetStepMode SetStepMode;
    extern Type_GetCurrentStatus GetCurrentStatus;
    Ensuite inclure ce fichier dans "form.h".

    Dans la FAQ C++, tu dois avoir quelques renseignements sur le bon usage des fichiers d'en-tête. Un petit tour serait le bienvenu.

  3. #3
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mai 2008
    Messages
    14
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2008
    Messages : 14
    Points : 7
    Points
    7
    Par défaut
    Bonjour,

    En effet, j'ai modifié le programme comme tu me l'as conseillé, et je n'ai plus de soucis merci !


    Fab

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Je n'ai pas Windows form application dans Visual Studio !
    Par ramito_roro dans le forum Visual Studio
    Réponses: 14
    Dernier message: 02/06/2015, 07h18
  2. Réponses: 6
    Dernier message: 03/06/2014, 10h09
  3. Réponses: 1
    Dernier message: 31/08/2011, 14h06
  4. Réponses: 3
    Dernier message: 28/09/2009, 17h35
  5. RS232 avec Windows Form sous Visual Studio 2008
    Par Jerepain dans le forum Visual C++
    Réponses: 8
    Dernier message: 14/05/2009, 18h02

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo