pthreadparam->hwnd= m_hwnd; // message target
pthreadparam->pevent = &m_eventstopwatch; // event to stop thread
//
// start file inspector thread.
//
afxbeginthread(threadfunction, pthreadparam);
}
//---------------------------------------------------------------------------------------
//
// function: void cmainwindow::oncancelbuttonclicked ()
// purpose: message handler of cancel button
// comments:
//
//---------------------------------------------------------------------------------------
void cmainwindow::oncancelbuttonclicked ()
{
showwindow( sw_hide );
boolwndhadshow = false;
}
//---------------------------------------------------------------------------------------
//
// function: void cmainwindow::onexitbuttonclicked ()
// purpose: message handler of exit button
// comments:
//
//---------------------------------------------------------------------------------------
void cmainwindow::onexitbuttonclicked ()
{
showwindow( sw_hide );
boolwndhadshow = false;
m_eventstopwatch.setevent();
//
// close the window
//
postmessage (wm_close,0,0);
}
//---------------------------------------------------------------------------------------
//
// function: void cmainwindow::onobjectpathchanged ()
// purpose: message handler of object path changed
// comments:
//
//---------------------------------------------------------------------------------------
void cmainwindow::onobjectpathchanged ()
{
m_cancel.enablewindow(true);
}
//---------------------------------------------------------------------------------------
//
// function: uint threadfunction(lpvoid pparam)
// purpose: worker thread function
// comments:
//
//---------------------------------------------------------------------------------------
uint threadfunction(lpvoid pparam)
{
//
// unbound the parameters
//
threadparam *pthreadparam = (threadparam * ) pparam;
hwnd hwnd = pthreadparam -> hwnd;
cevent *pevent = pthreadparam -> pevent;
//delete pthreadparam;
delete pthreadparam;
dword dwwaitstatus;
handle *dwchangehandles=new handle[3];
//
// use this event handle to stop the thread
//
dwchangehandles[2] = pevent->m_hobject;
//
// watch the c:\ directory for file creation and deletion.
//
dwchangehandles[0] = findfirstchangenotification(
"c:\\", // directory to watch
false, // do not watch the subtree
file_notify_change_file_name); // watch file name changes
//
// watch the d:\ subtree for directory creation and deletion.
//
dwchangehandles[1] = findfirstchangenotification(
"d:\\", // directory to watch
true, // watch the subtree
file_notify_change_dir_name); // watch dir. name changes
while (true)
{
/*--------------------------------------------------------------------------
examples:
here is the examples if you want to use waitforsingleobject
to imply the function.
//
// check if user want to exit file inspector.
// please make sure that the second parameter of
// waitforsingleobject is 0, and in this case the
// first parameter must be manual event.