unit sendto_folder; //{$DEFINE DEBUG} interface uses Classes, Windows; type TMySendToFolderNotification = class(TThread) private { Private 宣言 } F_hHandle: THandle; procedure UpdateFolder; protected procedure Execute; override; public constructor Create(sFolderName: WideString); destructor Destroy; override; end; implementation uses {$IFDEF DEBUG} myDebug, {$ENDIF} Forms, SysUtils, myFile, myString, myList, main; { TMySendToFolderNotification } constructor TMySendToFolderNotification.Create(sFolderName: WideString); begin F_hHandle := FindFirstChangeNotificationW( PWideChar(gfnsStrEndCut(sFolderName, '\')), False, FILE_NOTIFY_CHANGE_FILE_NAME //ファイル名の変更を監視 or FILE_NOTIFY_CHANGE_LAST_WRITE //ファイルの更新を監視 ); inherited Create(False); end; destructor TMySendToFolderNotification.Destroy; begin Terminate; if (F_hHandle <> 0) then begin FindCloseChangeNotification(F_hHandle); F_hHandle := 0; end; inherited; end; procedure TMySendToFolderNotification.Execute; begin while not(Terminated) do begin if (WaitForSingleObject(F_hHandle, INFINITE) = WAIT_OBJECT_0) then begin Synchronize(UpdateFolder); end; FindNextChangeNotification(F_hHandle); Sleep(1); //これがないとCPU使用率が天井に張り付く end; end; procedure TMySendToFolderNotification.UpdateFolder; begin if (Terminated) or (Application.Terminated) then begin Exit; end; G_MainForm.CreateSendToMenu; end; end.