vb6下製作托盤程式

2021-04-07 09:47:55 字數 3384 閱讀 4808

public const nif_icon = &h2

public const nif_message = &h1

public const nif_tip = &h4

public const nim_add = &h0

public const nim_delete = &h2

public const nim_modify = &h1

public const wm_mousemove = &h200

public const traylbuttondown = 7695

public const traylbuttonup = 7710

public const traylbuttondblclk = 7725

public const trayrbuttondown = 7740

public const trayrbuttonup = 7755

public const trayrbuttondblclk = 7770

public const traymousemove = 7680

public const wm_rbuttonup = &h205

public const wm_rbuttondown = &h204

public const wm_lbuttondblclk = &h203

public rc as long

type notifyicondata

cbsize as long

hwnd as long

uid as long

uflags as long

ucallbackmessage as long

hicon as long

sztip as string * 64

end type

dim traystructure as notifyicondata

public declare function shell_notifyicon lib "shell32.dll" alias _

"shell_notifyicona" (byval dwmessage as long, lpdata as notifyicondata) as long

public declare function beep lib "kernel32" (byval dwfreq as long, byval dwduration as long) as long

public declare function gettickcount lib "kernel32" () as long

public declare function sndplaysound lib "winmm.dll" alias "sndplaysounda" _

(byval lpszsoundname as string, byval uflags as long) as long

public sub pause(lnginterval as long)

dim lngend as long, lngnow as long, count1 as long

count1 = gettickcount()

lngend = count1 + (lnginterval * 1000)

dodoevents

lngnow = gettickcount()

loop until lngnow >= lngend

end sub

public function addicon(pic as picturebox, tip$)

traystructure.sztip = tip$ & chr$(0)

traystructure.uflags = nif_message + nif_icon + nif_tip

traystructure.uid = 100

traystructure.cbsize = len(traystructure)

traystructure.hwnd = pic.hwnd

traystructure.ucallbackmessage = wm_mousemove

traystructure.hicon = pic.picture

rc = shell_notifyicon(nim_add, traystructure)

end function

public function changeicon(pic as picturebox, tip$)

traystructure.sztip = tip$ & chr$(0)

traystructure.uflag = nif_icon + nif_tip

traystructure.hicon = pic.picture

shell_notifyicon nim_modify, traystructure

end function

public function deleteicon(pic as control)

traystructure.uid = 100

traystructure.cbsize = len(traystructure)

traystructure.hwnd = pic.hwnd

traystructure.ucallbackmessage = wm_mousemove

rc = shell_notifyicon(nim_delete, traystructure)

end function

public sub newtip(pic as control, tip$)

traystructure.uflag = nif_tip

traystructure.uid = 100

traystructure.cbsize = len(traystructure)

traystructure.hwnd = pic.hwnd

traystructure.ucallbackmessage = wm_mousemove

traystructure.sztip = tip$ & chr$(0)

rc = shell_notifyicon(nim_modify, traystructure)

end sub

需要說明的是shell_notifyicon這個api,微軟自帶的api瀏覽器下寫的是錯的

private sub picture1_mousemove(button as integer, shift as integer, x as single, y as single)

if hex(x) = "1e3c" then

me.popupmenu file

end if

end sub

file是選單,這個很簡單自己隨便寫乙個就成了,別忘了寫個end退出

製作自動執行程式 由vb6推廣引用

這需要將要啟動的應用程式路徑寫到登錄檔中具體的路徑是 hkey local machine software microsoft windows currentversion run 只需要在上面的路徑下寫乙個鍵並為此鍵設定乙個當前應用程式的路徑即開機自載 具體的方法 1 將下面這段 就是將鍵clo...

VB6技巧 總結

vb設定多行textbox的位置 由於自動輸入的文字比較多,最後輸入的跑到下面了,想要自動滾動到下面,本來以為 操作滾動條呢,但是沒有方法。於是我巧妙的採用了 顯示列表是設定了乙個多行 的 textbox 顯示列表.selstart len 顯示列表.text 1 顯示列表.sellength 1 ...

vb6 讀寫檔案

write file dim nhandle as integer,fname as string fname d 1.txt nhandle freefile open fname for output as nhandle print nhandle,0 print nhandle,2 clos...