VB6在拖托盘中写入应用程序图标
2006-02-27 11:38:22 来源:WEB开发网2、菜单:工程--添加模块按“打开”这样就添加了一个新模块,名为Module1,保存为Module1.bas
3、在Module1中写下如下代码:
OptionExplicit
PublicConstMAX_TOOLTipAsInteger=64
PublicConstNIF_ICON=&H2
PublicConstNIF_MESSAGE=&H1
PublicConstNIF_TIP=&H4
PublicConstNIM_ADD=&H0
PublicConstNIM_DELETE=&H2
PublicConstWM_MOUSEMOVE=&H200
PublicConstWM_LBUTTONDOWN=&H201
PublicConstWM_LBUTTONUP=&H202
PublicConstWM_LBUTTONDBLCLK=&H203
PublicConstWM_RBUTTONDOWN=&H204
PublicConstWM_RBUTTONUP=&H205
PublicConstWM_RBUTTONDBLCLK=&H206
PublicConstSW_RESTORE=9
PublicConstSW_HIDE=0
PublicnfIconDataAsNOTIFYICONDATA
PublicTypeNOTIFYICONDATA
cbSizeAsLong
hWndAsLong
uIDAsLong
uFlagsAsLong
uCallbackMessageAsLong
hIconAsLong
szTipAsString*MAX_TOOLTIP
EndType
PublicDeclareFunctionShowWindowLib"user32"(ByValhWndAsLong,ByValnCmdShowAsLong)AsLong
PublicDeclareFunctionShell_NotifyIconLib"shell32.dll"Alias"Shell_NotifyIconA"(ByValdwMessageAsLong,lpDataAsNOTIFYICONDATA)AsLong
4、在Form1的Load事件中写下如下代码:
PRivateSubForm_Load()
'以下把程序放入SystemTray====================================SystemTrayBegin
WithnfIconData
.hWnd=Me.hWnd
.uID=Me.Icon
.uFlags=NIF_ICONOrNIF_MESSAGEOrNIF_TIP
.uCallbackMessage=WM_MOUSEMOVE
.hIcon=Me.Icon.Handle
'定义鼠标移动到托盘上时显示的Tip
.szTip=App.Title "(版本"&App.Major&"."&App.Minor&"."&App.Revision&")"&vbNullChar
.cbSize=Len(nfIconData)
EndWith
CallShell_NotifyIcon(NIM_ADD,nfIconData)
'=============================================================SystemTrayEnd
Me.Hide
EndSub
5、在Form1的QueryUnload事件中写入如下代码:
PrivateSubForm_QueryUnload(CancelAsInteger,UnloadModeAsInteger)
CallShell_NotifyIcon(NIM_DELETE,nfIconData)
EndSub
6、在Form1的MouseMove事件中写下如下代码:
PrivateSubForm_MouseMove(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)
DimlMsgAsSingle
lMsg=X/Screen.TwipsPerPixelX
SelectCaselMsg
CaseWM_LBUTTONUP
'MsgBox"请用鼠标右键点击图标!",vbInformation,"实时播音专家"
'单击左键,显示窗体
ShowWindowMe.hWnd,SW_RESTORE
'下面两句的目的是把窗口显示在窗口最顶层
'Me.Show
'Me.SetFocus
''CaseWM_RBUTTONUP
''PopupMenuMenuTray'如果是在系统Tray图标上点右键,则弹出菜单MenuTray
''CaseWM_MOUSEMOVE
''CaseWM_LBUTTONDOWN
''CaseWM_LBUTTONDBLCLK
''CaseWM_RBUTTONDOWN
''CaseWM_RBUTTONDBLCLK
''CaseElse
EndSelect
EndSub
7、现在将程序保存起来运行看看系统托盘处是否增加了一个本工程的图标。单击此图标,Form1就自动弹出来了。
->赞助商链接