窗体最小化时在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
Integer li_X, li_Y
Choose Case lparam
Case WM_LBUTTONDBLCLK // 双击
wf_RemoveFromTray () //删除图标、释放资源
//加载新图标
wf_AddToTray('sysicon2.ico', handle(this), "PB编程俱乐部")
This.Show ( ) // 显示窗口
CASE WM_RBUTTONUP // 右键选择
li_X = This.X
li_Y = This.Y
// 移动到屏幕外以免show 时看到
This.Move ( - This.Width - 10, - This.Height - 10 )
// 在屏幕外显示窗口,以便能看到菜单条(菜单条属于此窗口)
This.Show ( )
//在鼠标位置弹出菜单
lm_popup = CREATE m_popup
lm_popup.m_item.PopMenu(PointerX(), PointerY())
// 恢复设置
if isvalid(This) then
This.Hide ( )
This.Move ( li_X, li_Y )
DESTROY lm_popup
end if
end choose
三、在window中写代码:1、在open()事件中://加载图标sysicon1.ico
if wf_AddToTray('sysicon1.ico', handle(this), "PB编程俱乐部") = 1 then
//隐藏父窗口
this.Hide ( )
end if2、在Resize()事件中://0- SIZE_RESTORED
//1- SIZE_MINIMIZED
//2- SIZE_MAXIMIZED
//3- SIZE_MAXSHOW
//4- SIZE_MAXHIDE
//窗口最小化时隐藏窗口、更换图标
If SizeType = 1 Then
wf_RemoveFromTray () //删除图标、释放资源
//加载新图标
if wf_AddToTray('sysicon1.ico', handle(this), "PB编程俱乐部") = 1 then
//隐藏父窗口
this.Hide ( )
end if
end if3、在close()事件中://删除图标、释放资源
wf_RemoveFromTray ()
一、声明变量:
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
Integer li_X, li_Y
Choose Case lparam
Case WM_LBUTTONDBLCLK // 双击
wf_RemoveFromTray () //删除图标、释放资源
//加载新图标
wf_AddToTray('sysicon2.ico', handle(this), "PB编程俱乐部")
This.Show ( ) // 显示窗口
CASE WM_RBUTTONUP // 右键选择
li_X = This.X
li_Y = This.Y
// 移动到屏幕外以免show 时看到
This.Move ( - This.Width - 10, - This.Height - 10 )
// 在屏幕外显示窗口,以便能看到菜单条(菜单条属于此窗口)
This.Show ( )
//在鼠标位置弹出菜单
lm_popup = CREATE m_popup
lm_popup.m_item.PopMenu(PointerX(), PointerY())
// 恢复设置
if isvalid(This) then
This.Hide ( )
This.Move ( li_X, li_Y )
DESTROY lm_popup
end if
end choose
三、在window中写代码:1、在open()事件中://加载图标sysicon1.ico
if wf_AddToTray('sysicon1.ico', handle(this), "PB编程俱乐部") = 1 then
//隐藏父窗口
this.Hide ( )
end if2、在Resize()事件中://0- SIZE_RESTORED
//1- SIZE_MINIMIZED
//2- SIZE_MAXIMIZED
//3- SIZE_MAXSHOW
//4- SIZE_MAXHIDE
//窗口最小化时隐藏窗口、更换图标
If SizeType = 1 Then
wf_RemoveFromTray () //删除图标、释放资源
//加载新图标
if wf_AddToTray('sysicon1.ico', handle(this), "PB编程俱乐部") = 1 then
//隐藏父窗口
this.Hide ( )
end if
end if3、在close()事件中://删除图标、释放资源
wf_RemoveFromTray ()