Witam,
męczę się nad tym problemem już jakieś 2 dni i kończą mi się pomysły.
Kod:
#pragma once
#include "stdafx.h"
#include<iostream>
namespace Espadron {
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 System::IO;
/// <summary>
/// Summary for watcher
/// </summary>
public ref class watcher : public System::Windows::Forms::Form
{
public:
watcher(void)
{
InitializeComponent();
////FileSystemWatcher
FileSystemWatcher^ fsWatcher = gcnew FileSystemWatcher( );
fsWatcher->Path = "c:\\Espadron\\";
fsWatcher->NotifyFilter = static_cast<NotifyFilters>
(NotifyFilters::FileName |
NotifyFilters::Attributes |
NotifyFilters::LastAccess |
NotifyFilters::LastWrite |
NotifyFilters::Security |
NotifyFilters::Size );
FSEventHandler^ handler = gcnew FSEventHandler();
fsWatcher->Created += gcnew FileSystemEventHandler(handler, &FSEventHandler::OnChanged);
fsWatcher->EnableRaisingEvents = true;
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~watcher()
{
if (components)
{
delete components;
}
}
public: System::Windows::Forms::ListBox^ listBox1;
protected:
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->listBox1 = (gcnew System::Windows::Forms::ListBox());
this->SuspendLayout();
//
// listBox1
//
this->listBox1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 9.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(238)));
this->listBox1->FormattingEnabled = true;
this->listBox1->ItemHeight = 16;
this->listBox1->Location = System::Drawing::Point(12, 14);
this->listBox1->Name = L"listBox1";
this->listBox1->Size = System::Drawing::Size(630, 196);
this->listBox1->TabIndex = 0;
this->listBox1->SelectedIndexChanged += gcnew System::EventHandler(this, &watcher::listBox1_SelectedIndexChanged);
//
// watcher
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(654, 230);
this->Controls->Add(this->listBox1);
this->Name = L"watcher";
this->Text = L"watcher";
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void listBox1_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) {
}
ref class FSEventHandler
{
public:
void OnChanged (Object^ source, FileSystemEventArgs^ e)
{
JAK TUTAJ ODWOLAC SIE DO LISTBOX1????????
}
void OnRenamed(Object^ source, RenamedEventArgs^ e)
{
Console::WriteLine("File: {0} renamed to {1}",
e->OldFullPath, e->FullPath);
}
};
};
}
Pytanie: Jak odwołać się do ListBox, który jest w innej klasie i na dodatek zdefiniowany(?) w funkcji?
Próbowałem spokrewnić klasy: ref class FSEventHandler : public watcher
oraz paru kombinacji dostania się do innej klasy/funkcji. Przy próbie spokrewnienia klas wywala błąd 'Espadron::watcher' : base class undefined
Myślałem nad wskaźnikiem/referencją, ale nie wiem gdzie to dokładnie wstawić...