我想用waitForSingleObject来监听目录中是不是有新文件,可是在WHILE循环中总是使整个窗体都死了???程序如下:procedure TForm1.jt(Sender: TObject);
var NotificationHandle:THandle;
waiting:boolean;
dwResult: DWORD;
begin
NotificationHandle:=FindFirstChangeNotification(PChar(filebox.Directory), FALSE,FILE_NOTIFY_CHANGE_FILE_NAME);
if (NotificationHandle <> INVALID_HANDLE_VALUE) then
statusbar1.Panels[1].Text:='现在正在监听目录'
else
begin
showmessage('目录监听出错!');
exit;
end;
waiting:=true;
Application.ProcessMessages;
while waiting do
begin
dwResult := WaitForSingleObject(NotificationHandle,INFINITE);
waiting:=false;
{if (dwResult=WAIT_OBJECT_0) then
begin
showmessage('目录中的新文件进入了!');
statusbar1.Panels[1].Text:='有新文件';
if Application.MessageBox('你想继续监听目录吗?', 'Continue?', MB_ICONQUESTION or MB_YESNO)=IDYES then
FindNextChangeNotification(NotificationHandle)
else
begin
statusbar1.Panels[1].Text:='目录监听取消';
waiting:=false;
end;
end; }
end;
FindCloseChangeNotification(NotificationHandle);end;
如果用directorlistbox的COUNT属性来检测时,也是同样的问题..???????
var NotificationHandle:THandle;
waiting:boolean;
dwResult: DWORD;
begin
NotificationHandle:=FindFirstChangeNotification(PChar(filebox.Directory), FALSE,FILE_NOTIFY_CHANGE_FILE_NAME);
if (NotificationHandle <> INVALID_HANDLE_VALUE) then
statusbar1.Panels[1].Text:='现在正在监听目录'
else
begin
showmessage('目录监听出错!');
exit;
end;
waiting:=true;
Application.ProcessMessages;
while waiting do
begin
dwResult := WaitForSingleObject(NotificationHandle,INFINITE);
waiting:=false;
{if (dwResult=WAIT_OBJECT_0) then
begin
showmessage('目录中的新文件进入了!');
statusbar1.Panels[1].Text:='有新文件';
if Application.MessageBox('你想继续监听目录吗?', 'Continue?', MB_ICONQUESTION or MB_YESNO)=IDYES then
FindNextChangeNotification(NotificationHandle)
else
begin
statusbar1.Panels[1].Text:='目录监听取消';
waiting:=false;
end;
end; }
end;
FindCloseChangeNotification(NotificationHandle);end;
如果用directorlistbox的COUNT属性来检测时,也是同样的问题..???????
Application.ProcessMessages;
还有 10分也太少了吧:)