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

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

本文简介:选择自 hightech 的 blog

// function: bool mytaskbaraddicon(hwnd hwnd,uint uid, hicon hicon, lpstr lpsztip)
// purpose:  add icon in the statu area on the task bar
// comments:
//
//---------------------------------------------------------------------------------------

bool mytaskbaraddicon(hwnd hwnd,uint uid, hicon hicon, lpstr lpsztip)
{
    bool bresult;
 
 notifyicondata tnid;
  tnid.cbsize = sizeof(notifyicondata);
  tnid.hwnd = hwnd;
  tnid.uid = uid;    
  tnid.uflags = nif_icon | nif_tip | nif_message;
  tnid.ucallbackmessage = user_wm_notifyicon;  // callback message
  tnid.hicon = hicon;        // icon used
   
 if (lpsztip)
  lstrcpyn(tnid.sztip, lpsztip, sizeof(tnid.sztip));
    else        
  tnid.sztip[0] = '\0'; 

 //
 // send nim_add to create icon
 //

 bresult = shell_notifyicon(nim_add, &tnid);
 
 if (hicon) destroyicon(hicon);

 return bresult;
}

//---------------------------------------------------------------------------------------
//
// function: bool mytaskbardeleteicon(hwnd hwnd, uint uid)
// purpose:  delete icon in the statu area on the task bar
// comments:
//
//---------------------------------------------------------------------------------------

bool mytaskbardeleteicon(hwnd hwnd, uint uid)

 bool bresult;
    notifyicondata tnid;
  tnid.cbsize = sizeof(notifyicondata);
  tnid.hwnd = hwnd;
  tnid.uid = uid;

 //
 //send nim_delete to create icon
 //

 bresult = shell_notifyicon(nim_delete, &tnid);

 return bresult;
}

//---------------------------------------------------------------------------------------
//
// function: lresult cmainwindow::onmyiconnotify( wparam wparam, lparam lparam )
// purpose:  call back function of message mywm_notifyicon
// comments:
//
//---------------------------------------------------------------------------------------

lresult cmainwindow::onmyiconnotify( wparam wparam, lparam lparam )
{
    uint nid;
 uint umousemsg;
 nid = (uint)wparam;
    umousemsg = (uint) lparam;
 
 //
 // show or hide window
 //
 
 if (umousemsg == wm_lbuttondown) // click on icon
 {
  if ( boolwndhadshow )
   showwindow( sw_hide );
  else
   showwindow( sw_shownormal );
  
  boolwndhadshow = ~boolwndhadshow;
 }
 return true;
}

//---------------------------------------------------------------------------------------
//
// function:
//   lresult cmainwindow::onshowappiconic( wparam wparam, lparam lparam )
// purpose:
//   message handler of show icon on statu bar
//   and hide the window when programe run
// comments:
//   call back function of message mywm_showappiconic
//
//---------------------------------------------------------------------------------------

lresult cmainwindow::onshowappiconic( wparam wparam, lparam lparam )
{
 hicon theicon = loadicon(afxgetinstancehandle(),
       makeintresource(idr_file_inspector) );
 mytaskbaraddicon(getsafehwnd(),
      100,
      theicon,
      _t("file/folder supervisor"));
 showwindow( sw_hide );
 boolwndhadshow = false;
 return 1;
}

//---------------------------------------------------------------------------------------
//
// function: void cmainwindow::onclose()
// purpose:
//   when you want to close programe, the icon should
//   be delete from statue area on task bar,
//   we can use wm_close message and message handler to do this
// comments:
//
//---------------------------------------------------------------------------------------

void cmainwindow::onclose()
{
 //

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

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

go top