Højreklik på TRAY.
Hej,Jeg vil gerne have lavet så at man kan højreklikke på mit tray ikon i en menu. Det skal være sådan at inde i koden, der kan jeg så vælge at lave en fx, closeknap_click() Unload Me
Jeg ved at når man laver det, så skal man ind under Menu Editor og lave den menu som man vil have (Menu Editor er meget simpelt). Og så skal man sætte visible til False på Menuen. Og på en måde skal man så få den frem når man højreklikke på tray-ikonet, hvor den skal vises der hvor man højreklikker.
Jeg har mit trayikon's script i denne CLASS:
'-------------------------- MIN CLASS --------------------
Option Explicit
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type
Private Type NOTIFYICONDATA
cbSize As Long
hwnd As Long
uID As Long
uFlags As Long
uCallbackMessage As Long
hIcon As Long
szTip As String * 128
dwState As Long
dwStateMask As Long
szInfo As String * 256
uTimeoutAndVersion As Long
szInfoTitle As String * 64
dwInfoFlags As Long
guidItem As GUID
End Type
Private Const APP_SYSTRAY_ID As Long = 999 'unique identifier
Private Const NIM_ADD As Long = &H0
Private Const NIM_MODIFY As Long = &H1
Private Const NIM_DELETE As Long = &H2
Public Enum eIcon
NIIF_NONE = &H0
NIIF_INFO = &H1
NIIF_WARNING = &H2
NIIF_ERROR = &H3
NIIF_NOSOUND = &H10
End Enum
Private Const NIF_MESSAGE As Long = &H1
Private Const NIF_ICON As Long = &H2
Private Const NIF_TIP As Long = &H4
Private Const NIF_INFO As Long = &H10
Private Const NIS_SHAREDICON As Long = &H2
Private Const WM_LBUTTONDBLCLK As Long = &H203
Private Const WM_LBUTTONDOWN As Long = &H201
Private Const WM_LBUTTONUP As Long = &H202
Private Const WM_MBUTTONDBLCLK As Long = &H209
Private Const WM_MBUTTONDOWN As Long = &H207
Private Const WM_MBUTTONUP As Long = &H208
Private Const WM_RBUTTONDBLCLK As Long = &H206
Private Const WM_RBUTTONDOWN As Long = &H204
Private Const WM_RBUTTONUP As Long = &H205
Private Const WM_MOUSEMOVE As Long = &H200
Private Const WM_BALLOONUSERCLICK As Long = &H405
Private Const NOTIFYICONDATA_V1_SIZE As Long = 88 ' pre-5.0 structure size
Private Const NOTIFYICONDATA_V2_SIZE As Long = 488 ' pre-6.0 structure size
Private Const NOTIFYICONDATA_V3_SIZE As Long = 504 ' 6.0+ structure size
Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetFileVersionInfoSize Lib "version.dll" Alias "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, lpdwHandle As Long) As Long
Private Declare Function GetFileVersionInfo Lib "version.dll" Alias "GetFileVersionInfoA" (ByVal lptstrFilename As String, ByVal dwHandle As Long, ByVal dwLen As Long, lpData As Any) As Long
Private Declare Function VerQueryValue Lib "version.dll" Alias "VerQueryValueA" (pBlock As Any, ByVal lpSubBlock As String, lpBuffer As Any, nVerSize As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private NotifyIcon As NOTIFYICONDATA
Private WithEvents FormHook As Form
Attribute FormHook.VB_VarHelpID = -1
Private m_Remove As Boolean
Private m_NotifyIconDataSize As Long
Public Event Message(ByVal Msg As Integer)
Public Sub NotifyRemove()
If m_Remove Then
With NotifyIcon
.cbSize = m_NotifyIconDataSize
.hwnd = FormHook.hwnd
.uID = APP_SYSTRAY_ID
Call Shell_NotifyIcon(NIM_DELETE, NotifyIcon)
m_Remove = False
End With
End If
End Sub
Public Sub NotifyCreate(frmHook As Form, picIcon As IPictureDisp, ByVal strTip As String)
If Not m_Remove Then
Set FormHook = frmHook
With NotifyIcon
.cbSize = m_NotifyIconDataSize
.hwnd = FormHook.hwnd
.uID = APP_SYSTRAY_ID
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
.dwState = NIS_SHAREDICON
.uCallbackMessage = WM_MOUSEMOVE
.hIcon = picIcon
.szTip = strTip & Chr$(0)
Call Shell_NotifyIcon(NIM_ADD, NotifyIcon)
m_Remove = True
End With
End If
End Sub
Public Sub NotifyModify(ByVal picIcon As IPictureDisp, ByVal strTip As String)
If m_Remove Then
With NotifyIcon
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
.hIcon = picIcon
.szTip = strTip & Chr$(0)
Call Shell_NotifyIcon(NIM_MODIFY, NotifyIcon)
End With
End If
End Sub
Public Sub NotifyBalloon(ByVal strTitle As String, ByVal strTip As String, nIcon As eIcon)
If m_Remove Then
With NotifyIcon
.uFlags = NIF_INFO
.dwInfoFlags = nIcon
.szInfoTitle = strTitle & Chr$(0)
.szInfo = strTip & Chr$(0)
Call Shell_NotifyIcon(NIM_MODIFY, NotifyIcon)
End With
End If
End Sub
Private Sub Class_Initialize()
Select Case True
Case IsShellVersion(6)
m_NotifyIconDataSize = NOTIFYICONDATA_V3_SIZE ' 6.0+ structure size
Case IsShellVersion(5)
m_NotifyIconDataSize = NOTIFYICONDATA_V2_SIZE ' pre-6.0 structure size
Case Else
m_NotifyIconDataSize = NOTIFYICONDATA_V1_SIZE ' pre-5.0 structure size
End Select
End Sub
Private Sub Class_Terminate()
Set FormHook = Nothing
End Sub
Private Sub FormHook_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim intMsg As Integer
Dim intMessage As Integer
intMsg = (X / Screen.TwipsPerPixelX)
Select Case intMsg
Case WM_LBUTTONDBLCLK
intMessage = 1
Case WM_LBUTTONDOWN
intMessage = 2
Case WM_LBUTTONUP
intMessage = 3
Case WM_MBUTTONDBLCLK
intMessage = 4
Case WM_MBUTTONDOWN
intMessage = 5
Case WM_MBUTTONUP
intMessage = 6
Case WM_RBUTTONDBLCLK
intMessage = 7
Case WM_RBUTTONDOWN
intMessage = 8
Case WM_RBUTTONUP
intMessage = 9
Case WM_BALLOONUSERCLICK ' Virker kun i Windows XP
intMessage = 10
End Select
If intMessage > 0 Then
Call SetForegroundWindow(FormHook.hwnd)
RaiseEvent Message(intMessage)
End If
End Sub
Private Function IsShellVersion(ByVal Version As Long) As Boolean
Dim nBufferSize As Long
Dim nUnused As Long
Dim lpBuffer As Long
Dim nVerMajor As Integer
Dim bBuffer() As Byte
Const sDLLFile As String = "shell32.dll"
nBufferSize = GetFileVersionInfoSize(sDLLFile, nUnused)
If nBufferSize > 0 Then
ReDim bBuffer(nBufferSize - 1) As Byte
Call GetFileVersionInfo(sDLLFile, 0&, nBufferSize, bBuffer(0))
If VerQueryValue(bBuffer(0), "\", lpBuffer, nUnused) = 1 Then
CopyMemory nVerMajor, ByVal lpBuffer + 10, 2
IsShellVersion = nVerMajor >= Version
End If
End If
End Function
Public Function Version() As Integer
Select Case True
Case IsShellVersion(6)
Version = 3 ' 6.0+ structure size
Case IsShellVersion(5)
Version = 2 ' pre-6.0 structure size
Case Else
Version = 1 ' pre-5.0 structure size
End Select
End Function
'-------------------------- MIN CLASS SLUT ---------------
Og så er der mit hovedvindue:
'-------------------------- HOVEDVINDUE ------------------
Option Explicit
Private Const VK_F7 As Long = &H76
Private Const VK_F12 As Long = &H7B
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private WithEvents objTray As CTrayIcon
Attribute objTray.VB_VarHelpID = -1
Private Sub Form_Load()
WebBrowser1.Navigate "http://dinside.dk"
Dim strTip As String
Set objTray = New CTrayIcon
strTip = "tips"
Call objTray.NotifyCreate(Me, Me.Icon, strTip)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call objTray.NotifyRemove
End Sub
Private Sub Timer1_Timer()
Dim nKey As Long
Dim nKeye As Long
Static blnState As Boolean
nKey = VK_F7 ' Her er det F7 tasten som viser/fjerne programmet
If blnState = False Then
If GetAsyncKeyState(nKey) <> 0 Then
If Me.Visible = False Then
Me.Visible = True
Else
Me.Visible = False
End If
blnState = True
End If
ElseIf GetAsyncKeyState(nKey) = 0 Then
blnState = False
End If
End Sub
'-------------------------- SLUT HOVEDVINDUE -------------
Som gør at der hver gang der klikkes F7, så skjules eller vises vinduet.