|
-
Nov 7th, 2000, 01:25 AM
#1
Thread Starter
Junior Member
I have created an app that minimizes to the systray and the popup menu works fine, EXCEPT: when the user clicks off of the menu without selecting an option it doesn't cancel the menu.
How do I make the menu go away when the user clicks off of it???
-
Nov 7th, 2000, 02:07 AM
#2
Fanatic Member
try doing something like
if menu is not focused on then
hide menu
end if
i know there's a way to do that but i just cant remember the code right now.. i dont have a good memory.
-
Nov 7th, 2000, 09:44 PM
#3
Thread Starter
Junior Member
The only event I can find for the menu is 'Click', where would I put the code??
How do I check to see if a menu has focus???
-
Nov 7th, 2000, 10:50 PM
#4
Hyperactive Member
I've made apps which minimize to the system tray and the pop-up always goes away if you
click outside the menu. Show us some code.
-
Nov 8th, 2000, 12:03 AM
#5
Thread Starter
Junior Member
<Form Code>
Private Sub cmdRequest_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If frmRequest.Visible = False Then
cmdRequest.SetFocus
End If
End Sub
Private Sub cmdExit_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If frmRequest.Visible = False Then
cmdExit.SetFocus
End If
End Sub
Private Sub cmdRequest_Click()
frmRequest.Show
End Sub
Private Sub cmdExit_Click()
Dim Kill As Variant
Kill = MsgBox("Are you sure you want to quit?", vbMsgBoxSetForeground + vbYesNo, "Exit Confirmation")
If Kill = vbYes Then
DeleteIcon
End
End If
End Sub
Private Sub Form_Activate()
If frmRequest.Visible = True Then
frmRequest.Show
End If
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Call DeleteIcon
End Sub
Private Sub Form_Resize()
If Me.WindowState = 1 Then
CreateIcon
Me.Hide
ElseIf Me.WindowState = 0 Or Me.WindowState = 2 Then
DeleteIcon
Me.Show
End If
End Sub
Public Sub CreateIcon()
Dim Tic As NOTIFYICONDATA
Tic.cbSize = Len(Tic)
Tic.hwnd = Picture1.hwnd
Tic.uID = 1&
Tic.uFlags = NIF_DOALL
Tic.uCallbackMessage = WM_MOUSEMOVE
Tic.hIcon = Picture1.Picture
Tic.szTip = "ATS Interactive EFAX 3.0" & Chr$(0)
erg = Shell_NotifyIcon(NIM_ADD, Tic)
End Sub
Public Sub DeleteIcon()
Dim Tic As NOTIFYICONDATA
Tic.cbSize = Len(Tic)
Tic.hwnd = Picture1.hwnd
Tic.uID = 1&
erg = Shell_NotifyIcon(NIM_DELETE, Tic)
End Sub
Private Sub mnuExit_Click()
Call cmdExit_Click
End Sub
Private Sub mnuRequest_Click()
frmMain.Hide
frmRequest.Show
End Sub
Private Sub mnuRestore_Click()
Me.WindowState = 0
Me.Show
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
X = X / Screen.TwipsPerPixelX
Select Case X
Case WM_RBUTTONDOWN
Me.PopupMenu mnuPopUp, 8
Case WM_LBUTTONDBLCLK
DeleteIcon
Me.WindowState = 0
frmMain.Show
End Select
End Sub
<Module Code>
Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias _
"Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As _
NOTIFYICONDATA) As Long
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 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 NIF_DOALL = NIF_MESSAGE Or NIF_ICON Or NIF_TIP
Public Const WM_MOUSEMOVE = &H200
Public Const WM_LBUTTONDBLCLK = &H203
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_RBUTTONDOWN = &H204
You guys might recognize some of this, I got a lot of the systray stuff from this site.
The program will be used on windows 95/98/NT platforms.
Also, the popup menu will go away sometimes, but not until you click off of it and then move the mouse over it again (the menu not the picture).
-
Nov 8th, 2000, 04:01 PM
#6
Hyperactive Member
I don't have time today to go through your code, but here is what works for me. You can adapt it
to your own needs.
Code:
'Need a form, a timer, and a picturebox(systray icon)
'Oh and you need to create a menu - mnuMyPopupMenu
'In Form1 declare section
Option Explicit
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 Declare Function Shell_NotifyIcon Lib "shell32" _
Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid _
As NOTIFYICONDATA) As Boolean
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2
Private Const WM_MOUSEMOVE = &H200
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
'In form1 code section
Private Sub Form_Load()
t.cbSize = Len(t)
t.hwnd = Picture1.hwnd 'icon for the systray
t.uId = 1&
t.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
t.ucallbackMessage = WM_MOUSEMOVE
t.hIcon = Picture1.Picture
t.szTip = strTip
Shell_NotifyIcon NIM_ADD, t
Timer1.Enabled = True
Me.Hide
App.TaskVisible = False
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Timer1.Enabled = False
t.cbSize = Len(t)
t.hwnd = Picture1.hwnd
t.uId = 1&
Shell_NotifyIcon NIM_DELETE, t
End Sub
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Hex(X) = "1E3C" Then 'RightButton was clicked
Me.PopupMenu mnuMyPopUpMenu 'pops up the menu
End If
If Hex(X) = "1E1E" Then
'code
'Left button was clicked
End If
End Sub
Private Sub Timer1_Timer()
t.cbSize = Len(t)
t.hwnd = Picture1.hwnd
t.uId = 1&
t.uFlags = NIF_ICON Or NIF_TIP
t.hIcon = Picture1.Picture
t.szTip = strTip
Shell_NotifyIcon NIM_MODIFY, t
Timer1.Enabled = True
End Sub
I got most of this from this forum also. (I would like to thank the author, but I don't
remember who it was . ) I'm not sure, but I think the timer might make the difference.
-
Nov 8th, 2000, 05:08 PM
#7
Fanatic Member
how do u make it hide when u unload it by pressing the "x" button?
i mean how do u hide the form and keep the icon there... like napster? or msn messenger?
-
Nov 8th, 2000, 05:45 PM
#8
Frenzied Member
Code:
Private Sub Form_Unload(UnloadMode As Integer, Cancel As Integer)
Cancel = True 'Cancel the unloading...
Me.Visible = False 'Hide the form...
'You might want to add a functionality to quit your program from code (would be handy :)), look at the UnloadMode in your VB helpfile for more info.
End Sub
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Nov 8th, 2000, 05:52 PM
#9
Fanatic Member
Thanx for the update...
i am trying to get into c# (c sharp) programming... i dindt even know there was such thing but its for microsoft.net hehe
thanx
-
Nov 8th, 2000, 08:45 PM
#10
Thread Starter
Junior Member
I personally do not like the way that Napster lets you think you closed the program when you press the close button, so I don't do it like that. Instead, I prompt to see if the user really wants to close the app, and if so it dies. If this code is not used, frmMain unloads but the app is still running with no way to use it and it has to be killed by the application manager. Here is the _Unload code I used:
Private Sub Form_QueryUnload(cancel As Integer, UnloadMode As Integer)
Dim Kill As Variant
Kill = MsgBox("Are you sure you want to quit?", vbMsgBoxSetForeground + vbYesNo, "Exit Confirmation")
If Kill = vbYes Then
DeleteIcon
End
End If
cancel = True
End Sub
Thanks to everyone for your replies!
The timer thing was right, thanks a lot DSY5!!!
Also, there are two systray code posts that I used from this site. Recognition goes to Wolfgang (dsy5's code came from here)& Sam Huggill. Thanks a lot for the help!
-
Nov 8th, 2000, 08:55 PM
#11
Thread Starter
Junior Member
By the way...How do I format my posts to show code as in VB and add these cute little happy faces where I want them????
-
Nov 9th, 2000, 11:54 AM
#12
[code]code here[/code]
For smilies, click the cute lil' face .
You may also want to take a look at the faq.
-
Nov 9th, 2000, 12:23 PM
#13
Fanatic Member
You can also use italic and bold text. This shows you how.
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
|