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

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

本文简介:选择自 hightech 的 blog

 // add your message handler code here and/or call default
 //
 
 mytaskbardeleteicon( getsafehwnd(), 100 );
 cwnd::onclose();
}

//---------------------------------------------------------------------------------------
//
// function:
//  void cmainwindow::onsyscommand( uint nid, lparam lparam )
// purpose:
//  when window were minimumized, the window should be hide,
//  we use on_syscommand message and message handle to do this
// comments:
//
//---------------------------------------------------------------------------------------
void cmainwindow::onsyscommand( uint nid, lparam lparam )
{
 if ( nid==sc_minimize  )
 {
  showwindow( sw_hide );
  boolwndhadshow = false;
 }
 else
  cwnd::onsyscommand( nid, lparam );
}


//---------------------------------------------------------------------------------------
//
// function: void cmainwindow::onbrowsebutonclicked ()
// purpose:  message handler of ok button
// comments:
//
//---------------------------------------------------------------------------------------
void cmainwindow::onbrowsebutonclicked ()
{

 //
 //  must call imalloc::free to free the memory by this pointer
 //
 
 lpmalloc pmalloc;
 browseinfo bi;
 char pszdirname[max_path];// save the directory name
 lpitemidlist pidl;

 //
 // if retrieve a handle to the shell allocator's imalloc interface sucessfuly
 //
 
 if (succeeded(shgetmalloc(&pmalloc)))
 {
  zeromemory(&bi,sizeof(bi));
  bi.hwndowner = getsafehwnd();
  bi.pidlroot = null;
  bi.pszdisplayname = pszdirname;
  bi.lpsztitle = _t("select the file or folder which will be supervised:");
  bi.ulflags = bif_browseincludefiles;
  bi.lpfn = null;
  bi.lparam = 0;
  if ((pidl = ::shbrowseforfolder(&bi)) != null)
  {
   //
   // get full path user selected
   //
   
   if (::shgetpathfromidlist(pidl, pszdirname))
   m_objectpath.setwindowtext(pszdirname);
  }
  pmalloc->free(pidl);
  pmalloc->release();
 }
  
  //
  // try to detect the inspect object is directory or file
  // can also use:
  // dword getfileattributes(lpctstr lpfilename);
  //
  
  dword objecttype;  
  objecttype = getfileattributes(pszdirname);
  if(objecttype & file_attribute_directory)
  {
   m_groupboxfi.setwindowtext (_t("folder supervised:"));
   m_groupboxfs.setwindowtext (_t("folder size limitation"));
  }
  else
  {
   m_groupboxfi.setwindowtext (_t("file supervised:"));
   m_groupboxfs.setwindowtext (_t("file size limitation"));
  }
  
  //
  //enable the cancel button
  //
   m_cancel.enablewindow(true);
}

//---------------------------------------------------------------------------------------
//
// function: void cmainwindow::onokbuttonclicked ()
// purpose:  message handler of ok button
// comments:
//  this function transfer a structure's pointer
//  as a lpvoid parameter to worker thread. this is the normal way
//  to handle the worker thread parameters. besides, you can also
//  input a address of an object directly.
//
//---------------------------------------------------------------------------------------

void cmainwindow::onokbuttonclicked ()
{
  m_cancel.enablewindow( false );
  showwindow( sw_hide );
  boolwndhadshow = false;
  
  //
  // reset the manual event object before start worker thread
  //

  m_eventstopwatch.resetevent ();

  //
  // prepare the parameter for worker thread
  // sometimes if you only need m_hwnd, you can also
  // input &m_hwnd directly there
  //

  threadparam * pthreadparam=new threadparam;

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

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

go top