将窗口最小化为时钟旁的小图标(PowerBulider)
2024-07-21 02:09:20
供稿:网友
中国最大的web开发资源网站及技术社区,
将窗口最小化为时钟旁的小图标
建立主窗口"w_main",口定义如下"local external fuctions":
function long loadlibrary( ref string string ) library "kernel32" alias for loadlibrarya
function long freelibrary( long long ) library "kernel32"
function boolean shell_notifyicon( ulong long, ref s_str str ) library "shell32" alias for "shell_notifyicona"
function long loadicon( long long, long long ) library "user32" alias for loadicona
定义结构型变量:
s_str:
size
unsignedlong
hwnd
long
id
unsignedlong
flags
unsignedlong
callbackmessage
unsignedlong
icon
long
tips[64]
character
定义实例变量:
private:
s_str istr_icon
窗口最小化按钮click事件写入如下script:
string ls_resource
long ll_handle
// 下三句为装入图标资源,notepad.exe即为写字板,exe执行时显示的图标内定为1
ls_resource = "notepad.exe"
ll_handle = loadlibrary ( ls_resource )
istr_icon.icon = loadicon ( ll_handle, 1 )
// 窗口回调事件号,pbm_custom01即为1024,02为1025,依此类推
istr_icon.callbackmessage = 1024
istr_icon.tips = "应用程序"
istr_icon.hwnd = handle ( parent )
istr_icon.size = 88
istr_icon.id = 1
// 标识值,即为显示tips 4, 显示icon 2, 激活窗口对应事件号
istr_icon.flags = 7
// 显示icon关键函数, 0为显示,1为修改,2为删除
shell_notifyicon ( 0, istr_icon )
parent.hide ( )
// 释放资源
freelibrary ( ll_handle )
为窗口创建用户定义事件ue_event,event id为pbm_custom01,为其写script:
m_popup lm_popup
integer li_x, li_y
choose case lparam
case 513 // lbuttonup
// 删除图标
shell_notifyicon( 2, istr_icon )
// 显示窗口
this.show ( )
case 517 // rbuttonup
li_x = this.x
li_y = this.y
// 移动到屏幕外以免show 时看到,你可关闭此句看什么效果
this.move ( - this.width - 10, - this.height - 10 )
// 加这句才能看到菜单条(菜单条属于此windows)
this.show ( )
lm_popup = create m_popup
lm_popup.m_item.popmenu ( pointerx ( ), pointery ( ) )
// 恢复设置
this.hide ( )
this.move ( li_x, li_y )
destroy lm_popup
end choose
其中,"m_popup"为最小化成trayicon图标时点击右键时弹出的菜单。