Προς το περιεχόμενο

embeleia sthn c++.net


@athanat0s

Προτεινόμενες αναρτήσεις

Δημοσ.

private: System::Void button1_Click(System::Object * sender, System::EventArgs * e)

{

 

FileSystemWatcher* watcher[]=new FileSystemWatcher*[5];

 

watcher[0]=new FileSystemWatcher;

 

watcher[0]->Path = (dynamic_cast<String*>(listBox1->Items->get_Item(listBox1->Items->get_Count()-1)));

 

/* Watch for changes in LastAccess and LastWrite times, and

the renaming of files or directories. */

 

watcher[0]->NotifyFilter = static_cast<NotifyFilters>( NotifyFilters::LastAccess | NotifyFilters::LastWrite

| NotifyFilters::FileName | NotifyFilters::DirectoryName );

 

// Only watch text files.

watcher[0]->Filter = S"";

watcher[0]->IncludeSubdirectories=true;

// Add event handlers.

//watcher->Changed += new FileSystemEventHandler(0, Watcher::OnChanged);

watcher[0]->Created += new FileSystemEventHandler(0, Watcher::OnChanged);

watcher[0]->Deleted += new FileSystemEventHandler(0, Watcher::OnChanged);

watcher[0]->Renamed += new RenamedEventHandler(0, Watcher::OnRenamed);

 

// Begin watching.

watcher[0]->EnableRaisingEvents = true;

 

}

 

 

private: System::Void button3_Click_1(System::Object * sender, System::EventArgs * e)

{

 

}

 

h erwthsh einai pws mporw na kanw access to watcher[0] apo thn function tou button3_Click???

oti kai na kanw mou leei oti eimai ektos embeleias.

Δημοσ.

Δεν χρειάζεται μόλις την δηλώσεις να την κάνεις και άμεσα object. Instantiation μπορείς κανονικά να την κάνεις στο Click που θες, απλά θα μπορούν να την δουν και οι άλλες fumctions

  • 2 εβδομάδες αργότερα...
Δημοσ.

Watcher.h

using namespace System;

using namespace System::IO;

 

public __gc class Watcher

{

public:

// Define the event handlers.

static void OnCreated(Object* /*source*/, FileSystemEventArgs* e);

 

static void OnRenamed(Object* /*source*/, RenamedEventArgs* e);

 

static void OnDeleted(Object* /*source*/, FileSystemEventArgs* e);

 

 

 

};

 

 

Watcher.cpp

#include "stdafx.h"

#include "Watcher.h"

#using <mscorlib.dll>

using namespace System;

using namespace System::Windows::Forms;

 

void Watcher::OnCreated(Object* /*source*/, FileSystemEventArgs* e)

{

// Specify what is done when a file is changed, created, or deleted.

//MessageBox::Show((dynamic_cast<String*>(e->FullPath)),dynamic_cast<String*>(__box(e->ChangeType)));

MessageBox::Show("created");

 

 

}

 

 

void Watcher::OnRenamed(Object* /*source*/, RenamedEventArgs* e)

{

// Specify what is done when a file is renamed.

//MessageBox::Show(dynamic_cast<String*>(e->OldFullPath),dynamic_cast<String*>(e->FullPath));

MessageBox::Show("renamed");

}

 

 

void Watcher::OnDeleted(Object* /*source*/, FileSystemEventArgs* e)

{

// Specify what is done when a file is renamed.

//MessageBox::Show(dynamic_cast<String*>(e->OldFullPath),dynamic_cast<String*>(e->FullPath));

MessageBox::Show("deleted");

}

 

 

pws mporw na kane access ena listBox pou brisketai panw sthn Form1 mesa apo thn klash watcher???Oti kai na kanw den douleuei.Ti prepei na kanw include?

Αρχειοθετημένο

Αυτό το θέμα έχει αρχειοθετηθεί και είναι κλειστό για περαιτέρω απαντήσεις.

  • Δημιουργία νέου...