我用VC写是可以的,用delphi确实不行,而且是在98下不行,估计是对longbool的设置不一致,<br>你最好用vc写吧,用vc写的我贴给你<br>void CHookdirDlg::OnOK() <br>{<br> // TODO: Add extra validation here<br>DWORD dwWaitStatus; <br>HANDLE dwChangeHandles[2]; <br> <br>// Watch the C:/WINDOWS directory for file creation and <br>// deletion. <br>CString ss; <br><br><br>dwChangeHandles[0] = FindFirstChangeNotification( <br> "C://temp1", // directory to watch <br> FALSE, // do not watch the subtree <br> FILE_NOTIFY_CHANGE_FILE_NAME); // watch file name changes <br> <br>if (dwChangeHandles[0] == INVALID_HANDLE_VALUE) {<br> //ExitProcess(GetLastError()); <br> ss.Format("Step 1 Error code:%d",GetLastError());<br> m_lbInfo.AddString(ss);<br> return;<br>}<br> <br>// Watch the C:/ subtree for directory creation and <br>// deletion. <br> <br>dwChangeHandles[1] = FindFirstChangeNotification( <br> "C://temp2", // directory to watch <br> TRUE, // watch the subtree <br> FILE_NOTIFY_CHANGE_FILE_NAME); // watch dir. name changes <br> <br>if (dwChangeHandles[1] == INVALID_HANDLE_VALUE) {<br> ss.Format("Step 2 Error code:%d",GetLastError());<br> m_lbInfo.AddString(ss);<br> return;<br>}<br> <br>// Change notification is set. Now wait on both notification <br>// handles and refresh accordingly. <br> <br> while (TRUE) <br> { <br> <br> // Wait for notification.<br> <br> dwWaitStatus = WaitForMultipleObjects(2, dwChangeHandles, <br> FALSE, INFINITE); <br> <br> switch (dwWaitStatus) <br> { <br> case WAIT_OBJECT_0: <br> <br> // A file was created or deleted in C:/WINDOWS. <br> // Refresh this directory and restart the <br> // change notification. RefreshDirectory is an <br> // application-defined function. <br> <br> //RefreshDirectory("C://WINDOWS") <br> if ( FindNextChangeNotification( <br> dwChangeHandles[0]) == FALSE ) <br> ExitProcess(GetLastError()); <br> //break;<br> ss="Step 1 OK ";<br> m_lbInfo.AddString(ss);<br> return; <br> case WAIT_OBJECT_0 + 1: <br> <br> // A directory was created or deleted in C:/. <br> // Refresh the directory tree and restart the <br> // change notification. RefreshTree is an <br> // application-defined function. <br> <br> // RefreshTree("C://"); <br> if (FindNextChangeNotification( <br> dwChangeHandles[1]) == FALSE) <br> ExitProcess(GetLastError()); <br> //break; <br> ss="Step 2 OK ";<br> m_lbInfo.AddString(ss);<br> return; <br> default: <br> ExitProcess(GetLastError()); <br> }<br> } <br> <br> CDialog::OnOK();<br>}