powerbuilder中把圖標放在時間顯示處
2024-07-21 02:10:24
供稿:網友
將窗口最小化為時鐘旁的小圖標
編輯整理:panya
建立主窗口“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圖標時點擊右鍵時彈出的菜單。