|
-
Sep 13th, 2000, 10:37 PM
#1
Thread Starter
Junior Member
I need my program to put an icon in the system tray area, so i'm using this code:
Public Sub CreateIcon(Control As PictureBox)
Dim Tic As NOTIFYICONDATA
Dim Erg As Variant
Tic.cbSize = Len(Tic)
Tic.hWnd = Control.hWnd
Tic.uID = 1&
Tic.uFlags = NIF_MESSAGE Or NIF_ICON Or NIF_TIP 'NIF_DOALL
Tic.uCallbackMessage = WM_MOUSEMOVE
Tic.hIcon = Control.Picture
Tic.szTip = App.ProductName & AppVersionS & Chr$(0)
Erg = Shell_NotifyIcon(NIM_ADD, Tic)
End Sub
if i start closing my apps pressing Alt+F4, sometime even my VB app get closed (i don't want this happen because it's a security app), how can i avoid this behavior?
-
Sep 13th, 2000, 10:40 PM
#2
Try this:
Code:
'Module code:
Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Public Const NIM_ADD = &H0
Public Const NIM_MODIFY = &H1
Public Const NIM_DELETE = &H2
Public Const NIF_MESSAGE = &H1
Public Const NIF_ICON = &H2
Public Const NIF_TIP = &H4
Public Const WM_LBUTTONUP = &H202
Public Const WM_RBUTTONUP = &H205
Public Const WM_MOUSEMOVE = &H200
Public 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
Public VBGTray As NOTIFYICONDATA
'Form Declarations:
Private Sub GoSystemTray()
VBGTray.cbSize = Len(VBGTray)
VBGTray.hwnd = Me.hwnd
VBGTray.uId = vbNull
VBGTray.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
VBGTray.ucallbackMessage = WM_MOUSEMOVE
VBGTray.hIcon = Me.Icon
'tool tip text
VBGTray.szTip = Me.Caption & vbNullChar
Call Shell_NotifyIcon(NIM_ADD, VBGTray)
App.TaskVisible = False 'remove application from taskbar
Me.Hide
End Sub
'Form Code:
Private Sub Form_MouseMove(button As Integer, Shift As Integer, X As Single, Y As Single)
Static lngMsg As Long
Static blnFlag As Boolean
Dim result As Long
lngMsg = X / Screen.TwipsPerPixelX
If blnFlag = False Then
blnFlag = True
Select Case lngMsg
'right-click
Case WM_RBUTTONUP
result = SetForegroundWindow(Me.hwnd)
PopupMenu MyPopUpMenu
Case WM_LBUTTONUP
result = SetForegroundWindow(Me.hwnd)
PopupMenu MyPopUpMenu
End Select
blnFlag = False
End If
End Sub
Private Sub Form_Resize()
If Me.WindowState = 1 Then
Call GoSystemTray
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
VBGTray.cbSize = Len(VBGTray)
VBGTray.hwnd = Me.hwnd
VBGTray.uId = vbNull
Call Shell_NotifyIcon(NIM_DELETE, VBGTray)
End Sub
-
Sep 13th, 2000, 11:15 PM
#3
Thread Starter
Junior Member
Nope, it did not work 
It's the same, if you start closing apps (alt+f4), i think the icon sometime got the focus, and it get closed.
Any other idea?
-
Sep 14th, 2000, 01:53 PM
#4
Use this:
Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Cancel = True
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|