27. august 2002 - 09:34
Der er
4 kommentarer og
1 løsning
assigne ikon til trayIcon
Hej eksperter.
Jeg roder med ovenstående. Benytter et cSysTray istedet for et IconNotifyer. Hvad er koden for at lægge et ikon placeret ex. C:\ikon.ico ind som ikon.
Jeg har følgende kode at arbejde med...
Me.AxcSysTray1.set_TrayIcon(??? hvad skal der stå her ???)
På forhånd tak...
28. august 2002 - 19:18
#3
Kan du bruge dette?
* Opret et module
* Brug den form som er der i forvejen
* Indsæt denne kode i modulet:
--------START---------
Public Declare Function mciExecute Lib "winmm.dll" (ByVal lpstrCommand As String) As Long
Public Const WM_RBUTTONUP = &H205
Public Const WM_LBUTTONUP = &H202
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONDBLCLK = &H203
Global Const WM_MOUSEMOVE = &H200
Global Const NIM_ADD = 0&
Global Const NIM_DELETE = 2&
Global Const NIM_MODIFY = 1&
Global Const NIF_ICON = 2&
Global Const NIF_MESSAGE = 1&
Global Const ABM_GETTASKBARPOS = &H5&
Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
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
Type APPBARDATA
cbSize As Long
hwnd As Long
uCallbackMessage As Long
uEdge As Long
rc As RECT
lParam As Long
End Type
Global Notify As NOTIFYICONDATA
Global BarData As APPBARDATA
Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Private Declare Function SHAppBarMessage Lib "shell32.dll" (ByVal dwMessage As Long, pData As APPBARDATA) As Long
Sub modIcon(Form1 As Form, IconID As Long, Icon As Object, ToolTip As String)
Dim Result As Long
Notify.cbSize = 88&
Notify.hwnd = Form1.hwnd
Notify.uID = IconID
Notify.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
Notify.uCallbackMessage = WM_MOUSEMOVE
Notify.hIcon = Icon
Notify.szTip = ToolTip & Chr$(0)
Result = Shell_NotifyIcon(NIM_MODIFY, Notify)
End Sub
Sub AddIcon(Form1 As Form, IconID As Long, Icon As Object, ToolTip As String)
Dim Result As Long
BarData.cbSize = 36&
Result = SHAppBarMessage(ABM_GETTASKBARPOS, BarData)
Notify.cbSize = 88&
Notify.hwnd = Form1.hwnd
Notify.uID = IconID
Notify.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
Notify.uCallbackMessage = WM_MOUSEMOVE
Notify.hIcon = Icon
Notify.szTip = ToolTip & Chr$(0)
Result = Shell_NotifyIcon(NIM_ADD, Notify)
End Sub
Sub delIcon(IconID As Long)
Dim Result As Long
Notify.uID = IconID
Result = Shell_NotifyIcon(NIM_DELETE, Notify)
End Sub
----------SLUT----------
* Opret en menu fra menue ditor
* Lav understående punkter
---Punkt1 :: Navn "p1"
---Punkt2 :: Navn "p2"
---Minimere :: Navn "Close"
* Dobbeltklik på formen
* Vælg generel
* Kopier denne kode ind i generel
------START--------
Option Explicit
Public Counter As Integer
Public IconObject As Object
Private Sub Close_Click()
Form1.Hide
Set IconObject = Form1.Icon
AddIcon Form1, IconObject.Handle, IconObject, "Tray"
End Sub
Private Sub Form_Resize()
If Form1.WindowState = 1 Then Me.Hide
End Sub
Private Sub Form_Unload(Cancel As Integer)
delIcon IconObject.Handle
delIcon Form1.Icon.Handle
End Sub
Private Sub Form_Load()
Form1.Hide
Set IconObject = Form1.Icon
AddIcon Form1, IconObject.Handle, IconObject, "Tray"
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Static Message As Long
Message = X / Screen.TwipsPerPixelX
Select Case Message
Case WM_RBUTTONUP:
'Hvis der bliver højre klikket:
Me.PopupMenu Pop
Case WM_LBUTTONUP:
'Hvis der bliver venstre klikket:
Form1.WindowState = 0
Form1.Show
Form1.SetFocus
End Select
End Sub
Private Sub p1_Click()
MsgBox Me.p1.Caption
End Sub
Private Sub p2_Click()
MsgBox Me.p2.Caption
End Sub
Private Sub Timer1_Timer()
Label1.Caption = Val(Label1.Caption) + 1
End Sub
-----SLUT------
* Husk at vælge et passende ikon til formen.
Mvh.
KantoRaZa/NorthCode