一个典型的例子解决常见的高级Windows程序设计问题[6]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 hightech 的 blog

  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.

本文关键:线程,状态栏小图标,文件实时监视
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top