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 155 156 157 158 159 160
|
#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();
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~watcher()
{
if (components)
{
delete components;
}
}
private: 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->Items->AddRange(gcnew cli::array< System::Object^ >(2) {L"Gowno", L"Gowno2"});
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);
////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->Changed += gcnew FileSystemEventHandler(handler, &FSEventHandler::OnChanged);
fsWatcher->EnableRaisingEvents = true;
}
#pragma endregion
private: System::Void listBox1_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) {
}
ref class FSEventHandler
{
public:
void OnChanged (Object^ source, FileSystemEventArgs^ e)
{
/////HERE IS MY PROBLEM I THINK
watcher^ test = gcnew watcher();
test -> listBox1 -> BeginUpdate();
test -> listBox1 -> Items -> Add ("Strongigi");
test -> listBox1 -> EndUpdate();
}
void OnRenamed(Object^ source, RenamedEventArgs^ e)
{
Console::WriteLine("File: {0} renamed to {1}",
e->OldFullPath, e->FullPath);
}
};
};
}
|