10. maj 2000 - 14:14Der er
1 kommentar og 1 løsning
Hvordan lægger jeg programmet ned som Icon i Trayen?
Hej Er der nogen der har en hurtig og simpel måde at lave iconner i system trayen? Det skal være sådan når jeg trykker på iconnet, skal den skifte form.visible=0 til form.visible=1?
Der bliver investeret massivt i AI. Teknologien er mere tilgængelig end nogensinde, og ambitionerne er høje. Alligevel oplever mange virksomheder, at resultaterne udebliver.
Følgende virker i windows 98 (måske ikke i win 95):
Indsættes i modul: 'Module code Option Explicit
'Declarations and constants for placing icons in tray Private 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
Private TrayIcon As NOTIFYICONDATA
Public Const WM_LBUTTONDBLCLICK = &H203 Public Const WM_LBUTTONDOWN = &H201 Public Const WM_LBUTTONUP = &H202 Public Const WM_RBUTTONDBLCLK = &H206 Public Const WM_RBUTTONDOWN = &H204 Public Const WM_RBUTTONUP = &H205 Public Const WM_MOUSEMOVE = &H200 Const NIM_ADD = &H0 Const NIM_MODIFY = &H1 Const NIM_DELETE = &H2 Const NIF_MESSAGE = &H1 Const NIF_ICON = &H2 Const NIF_TIP = &H4
'API declaration to place icon in tray Private Declare Function Shell_NotifyIcon Lib "shell32" Alias _ "Shell_NotifyIconA" (ByVal dwMessage As Long, _ pnid As NOTIFYICONDATA) As Boolean
Public Sub AddIcon(frm As Form, Optional sTip As String) 'Sub to place icon in tray With TrayIcon .cbSize = Len(TrayIcon) .hwnd = frm.hwnd .uId = vbNull .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE .ucallbackMessage = WM_MOUSEMOVE .hIcon = frm.Icon 'set tool tip text If sTip = "" Then .szTip = frm.Caption & vbNullChar Else .szTip = sTip & vbNullChar End If End With 'Places icon in tray Call Shell_NotifyIcon(NIM_ADD, TrayIcon) 'Hide the form 'frm.Hide End Sub
Public Sub RemoveIcon(frm As Form) 'Sub to remove icon from tray With TrayIcon .cbSize = Len(TrayIcon) .hwnd = frm.hwnd .uId = vbNull End With 'Removes icon from tray Call Shell_NotifyIcon(NIM_DELETE, TrayIcon) End Sub
indsæt følgende i formens Mousemove event:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim lMsg As Long lMsg = X / Screen.TwipsPerPixelX Debug.Print lMsg 'Debug.Print lMsg Select Case lMsg Case WM_LBUTTONDBLCLICK 'code for left button double-click Me.WindowState = 0 Me.Show Case WM_LBUTTONDOWN 'code for left button down Case WM_LBUTTONUP 'code for left button up Case WM_RBUTTONDBLCLK 'code for right button double-clicked Case WM_RBUTTONDOWN 'code for right button down Case WM_RBUTTONUP 'code for right button up 'typically show a popup menu 'with at least one menu item 'to exit the application! 'me.PopupMenu Indstillinger End Select End Sub
og følgende i resize eventet:
Private Sub Form_Resize() If Me.ScaleHeight = 0 Then Me.Visible = False end if End Sub
Brug addicon fuktionen i form_load eventet og removeIcon i form_unload eventet
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.