[Winform] Problème de tutorial Winforms en C++/CLI
Bonjour,
Je suis en train de mettre au winform en C++ et pour le coup je réalise le parcours d'un tuto:
http://nico-pyright.developpez.com/t...2005/winforms/
Le tutorial est pour VS 2005 et j'utilise VS 2008, théoriquement je devrais pas trop avoir de problème... Sachant que dans MSDN les infos concernant le framework 2.0 sont les même dans le 3.5 pour des classes qui sont contenues dans les deux framework.
J'en suis à ce chapitre:
5.2.Elaboration de l'application
Lorsque je compile mon application j'ai 51 erreurs :(
Voici mon code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
| #pragma once
namespace NetSend
{
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::Label^ label1;
protected:
private: System::Windows::Forms::ProgressBar^ progressBar;
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
//variable of search computer of network
private: System::Collections::ArrayList ^ listOfComputer;
private: System::DirectoryServices::DirectoryEntries ^ entries;
#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->label1 = (gcnew System::Windows::Forms::Label());
this->progressBar = (gcnew System::Windows::Forms::ProgressBar());
this->SuspendLayout();
//
// label1
//
this->label1->AutoSize = true;
this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 19, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->label1->Location = System::Drawing::Point(158, 41);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(218, 30);
this->label1->TabIndex = 0;
this->label1->Text = L"WAIT PLEASE ....";
this->label1->TextAlign = System::Drawing::ContentAlignment::MiddleCenter;
//
// progressBar
//
this->progressBar->ForeColor = System::Drawing::Color::FromArgb(static_cast<System::Int32>(static_cast<System::Byte>(0)), static_cast<System::Int32>(static_cast<System::Byte>(192)),
static_cast<System::Int32>(static_cast<System::Byte>(0)));
this->progressBar->Location = System::Drawing::Point(49, 108);
this->progressBar->Name = L"progressBar";
this->progressBar->Size = System::Drawing::Size(437, 38);
this->progressBar->TabIndex = 1;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->BackColor = System::Drawing::SystemColors::ActiveCaption;
this->ClientSize = System::Drawing::Size(535, 185);
this->Controls->Add(this->progressBar);
this->Controls->Add(this->label1);
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::None;
this->Name = L"Form1";
this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
this->Text = L"Form1";
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
System::Collections::ArrayList ^ getListOfComputer ()
{
return listOfComputer;
}
private:
void ThreadProcess(void)
{
for each(System::DirectoryServices::DirectoryEntry ^ entry in entries)
{
try
{
System::Net::IPHostEntry ^ ip = System::Net::Dns::GetHostEntry(entry->Name);
listOfComputer->Add(entry->Name);
}
catch (System::Exception ^ ex)
{
}
this->progressBar->PerformStep();
Sleep(500);//Wait 0,5 secondes for a good display of loading.
}
this->Close();
}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e)
{
listOfComputer = gcnew System::Collections::ArrayList();
System::String ^ domainName = "WORKGROUP";
System::DirectoryServices::DirectoryEntry ^ domainEntry = gcnew System::DirectoryServices::DirectoryEntry(System::String::Format("WinNT://{0}", domainName));
domainEntry->Children->SchemaFilter->Add("computer");
entries = domainEntry->Children;
int nb = 0;
for each(System::DirectoryServices::DirectoryEntry ^ entry in entries)
nb++;
this->progressBar->Minimum = 0;
this->progressBar->Maximum = nb;
this->progressBar->Value = 0;
this->progressBar->Step = 1;
System::Threading::Thread ^ t = gcnew System::Threading::Thread(gcnew System::Threading::ThreadStart(this, &NetSendDotNet::Form1::ThreadProcess));
t->Start();
}
};
} |
Pour commencer il me dit que
Code:
private: System::DirectoryServices::DirectoryEntries ^ entries;
n'est pas correct:
Citation:
1>c:\users\christophe\documents\visual studio 2008\projects\net-send\net-send\Form1.h(56) : error C3083: 'DirectoryServices': the symbol to the left of a '::' must be a type
1>c:\users\christophe\documents\visual studio 2008\projects\net-send\net-send\Form1.h(56) : error C2039: 'DirectoryEntries' : is not a member of 'System'
1>c:\users\christophe\documents\visual studio 2008\projects\net-send\net-send\Form1.h(56) : error C2143: syntax error : missing ';' before '^'
1>c:\users\christophe\documents\visual studio 2008\projects\net-send\net-send\Form1.h(56) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\christophe\documents\visual studio 2008\projects\net-send\net-send\Form1.h(56) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
J'ai regarder dans MSDN mais apparement la dépendance est bonne:
http://msdn.microsoft.com/fr-fr/libr...yservices.aspx
Les autres erreurs sont dû je pense aux problème de déclaration des objets déclarés en attributs dans la classe.
Je suis débutant en C++ CLI. Je ne demande pas que l'on me donne la correction de mon code mais un début de piste pour corriger mes erreurs et comprendre pourquoi c'est de cette façon et pas d'une autre.
:f1:
Merci d'avances.