pb最小化,并且缩小到任务栏中

 窗体最小化时在systray区显示图标  
  一、声明变量:  
  1、新建结构变量:str_notifyicondata如下:cbsize                             long  
  hwnd                                 long  
  uid                                     long  
  uflag                                 long  
  ucallbackmessage         long  
  hicon                                 long  
  tips[64]                         character2、instance   Variables:Constant   Long   NIM_ADD   =   0   //显示  
  Constant   Long   NIM_MODIFY   =   1   //修改   
  Constant   Long   NIM_DELETE   =   2   //删除  
   
  Constant   Long   NIF_MESSAGEorNIF_ICONorNIF_TIP   =   7  
  Constant   Long   IMAGE_ICON   =   1  
  Constant   Long   LR_LOADFROMFILE   =   16  
   
  Constant   Long   WM_LBUTTONDBLCLK   =   515   //双击  
  Constant   Long   WM_RBUTTONUP   =   517   //右键单击  
   
  Long   hIcon  
   
  private:  
  str_notifyicondata   istr_notifyicondata3、Global   External   Functions   :Public   Function   Integer   Shell_NotifyIcon   (Long   dwMessage,   Any   lpData)   Library   "shell32"   Alias   For   "Shell_NotifyIconA"  
  Public   Function   Long   LoadImage   (Long   hInst,   String   lpsz,   Long   un1,   Long   n1,   Long   n2,   Long   un2)   Library   "user32"   Alias   For   "LoadImageA"   
  Public   Function   Long   DestroyIcon   (Long   hIcon)   Library   "user32"   Alias   For   "DestroyIcon" 二、自定义函数和事件:1.函数:wf_addtotray(string   as_icon,   long   al_handle,   string   as_tips)   returns   Integer//   功能:加载图标  
  //   参数说明:  
  //   string   as_icon   :加载的图标文件名  
  //   long   al_handle   :窗口句柄  
  //   string   as_tips   :显示的tips  
   
   
  if   hIcon   =   0   then   //   图标还没有装载  
  hIcon   =   LoadImage(0,   as_icon,   IMAGE_ICON,   0,   0,   LR_LOADFROMFILE)  
  end   if  
   
  if   hIcon   =   0   then  
  MessageBox   ("Error",   "图标装载失败!")  
  Return   -1  
  end   if  
   
  istr_notifyicondata.cbsize   =   88   
  //   窗口句柄  
  istr_notifyicondata.hwnd   =   al_handle  
  istr_notifyicondata.uid   =   0  
  //   窗口回调事件号,pbm_custom01为1024,pbm_custom02为1025,依此类推   
  istr_notifyicondata.ucallbackmessage   =   1024   
  //   图标  
  istr_notifyicondata.hIcon   =   hIcon  
  //   标识值,即为显示tips   
  istr_notifyicondata.tips   =   as_tips  
   
  istr_notifyicondata.uflags   =   NIF_MESSAGEorNIF_ICONorNIF_TIP//7   
   
  //   显示icon关键函数,   NIM_ADD   0为显示,1为修改,2为删除   
  shell_notifyicon   (   NIM_ADD,   istr_notifyicondata   )   
   
  return   12、函数:wf_removefromtray()   Returns   0//删除图标   NIM_DELETE   =   2  
  Shell_NotifyIcon(   NIM_DELETE,   istr_notifyicondata   )   
   
  //释放资源  
  if   hIcon   <>   0   then   DestroyIcon   (hIcon)  
  hIcon   =   03、事件:ue_event(   unsignedlong   wparam,long   lparam)   Returns   long[pbm_custom01]//Event   ID:pbm_custom01  
  m_popup   lm_popup&nbsp;  
  Integer   li_X,   li_Y&nbsp;  
   
   
  Choose   Case   lparam&nbsp;  
   
  Case   WM_LBUTTONDBLCLK   //   双击  
   
  wf_RemoveFromTray   ()   //删除图标、释放资源  
  //加载新图标  
  wf_AddToTray('sysicon2.ico',   handle(this),   "PB编程俱乐部")&nbsp;  
  This.Show   (   )   //   显示窗口&nbsp;  
   
  CASE   WM_RBUTTONUP   //   右键选择&nbsp;  
   
  li_X   =   This.X&nbsp;  
  li_Y   =   This.Y&nbsp;  
  //   移动到屏幕外以免show   时看到  
  This.Move   (   -   This.Width   -   10,   -   This.Height   -   10   )&nbsp;  
  //   在屏幕外显示窗口,以便能看到菜单条(菜单条属于此窗口)  
  This.Show   (   )&nbsp;  
   
  //在鼠标位置弹出菜单  
  lm_popup   =   CREATE   m_popup&nbsp;  
  lm_popup.m_item.PopMenu(PointerX(),   PointerY())&nbsp;  
   
  //   恢复设置&nbsp;  
  if   isvalid(This)   then  
  This.Hide   (   )&nbsp;  
  This.Move   (   li_X,   li_Y   )&nbsp;  
  DESTROY   lm_popup  
  end   if  
   
  end   choose&nbsp;  
  三、在window中写代码:1、在open()事件中://加载图标sysicon1.ico  
  if   wf_AddToTray('sysicon1.ico',   handle(this),   "PB编程俱乐部")   =   1   then  
  //隐藏父窗口  
  this.Hide   (   )&nbsp;  
  end   if2、在Resize()事件中://0-   SIZE_RESTORED  
  //1-   SIZE_MINIMIZED  
  //2-   SIZE_MAXIMIZED  
  //3-   SIZE_MAXSHOW  
  //4-   SIZE_MAXHIDE  
   
  //窗口最小化时隐藏窗口、更换图标  
  If   SizeType   =   1   Then&nbsp;  
  wf_RemoveFromTray   ()   //删除图标、释放资源  
  //加载新图标  
  if   wf_AddToTray('sysicon1.ico',   handle(this),   "PB编程俱乐部")   =   1   then  
  //隐藏父窗口  
  this.Hide   (   )&nbsp;  
  end   if  
  end   if3、在close()事件中://删除图标、释放资源  
  wf_RemoveFromTray   ()  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值