am using a new thread which is a revisit to my previous thread "Tow Questions"
my second question was dat how do i put my application's icon in System Tray ?
Printable View
am using a new thread which is a revisit to my previous thread "Tow Questions"
my second question was dat how do i put my application's icon in System Tray ?
in the previous thread, you said to the task barQuote:
my second question was dat how do i put my application's icon in System Tray ?
to put into the system tray you use an api call to
Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
· dwMessage
Identifier of the message to send. This parameter can be one of these values:
NIM_ADD
Adds an icon to the status area.
NIM_DELETE
Deletes an icon from the status area.
NIM_MODIFY
Modifies an icon in the status area.
· pnid
Pointer to a NOTIFYICONDATA structure. The content of the structure depends on the value of dwMessage.
try a search on "NotifyIcon" to see if any examples have been posted previously
rgds peter
....or you can try this file:
heylo
well first of all i have imlemented the Shell Notification Icon n its workin fi9 for me, secondly the file u gave me is not workin i tried on win XP as well 98
now my question is dat i want to change the icon according to the data coming from the port, jus like when we connect internet using dial up connection, there comes two computer like icon in the system tray n they blink lights according to the in/out traffic
you have to use the loadpicture command to change a forms icon.
me.icon =loadpicture("newicon.ico")
there is quite a bit in the helpfile for it
rgds peter
well if i change the icon using
me.icon = loadpicture( someicon )
it only changes the icon of the form n not the one display in the System Tray
A 3rd party OCX usually does the trick, and require minum code and configuration :bigyello:
i searched google, came up few results, but most of them were commercial n one was no more available on da net, so if u do knw ne such ocx pls upload it here or gimme da link !
well another prb wid icon is that as the application gets terminated the icon doesn't disappear until i point the mouse over to that icon in hte sytem tray
Why would you want to use 3rd party ocxs? They just make your app larger in size when distributing and may create some problems.
Basic code for adding to systray is
VB Code:
NID.cbSize = Len(NID) NID.hWnd = yourpicbox.hWnd NID.uID = 0 NID.uID = NID.uID + 1 NID.uFlags = NIF_MESSAGE Or NIF_ICON Or NIF_TIP NID.uCallbackMessage = WM_MOUSEMOVE NID.hIcon = yourpicbox.Picture NID.szTip = yourtooltiptext + Chr$(0) Shell_NotifyIconA NIM_ADD, NID
Use APIviewer for all the declarations (NID is NOTIFYICONDATA type and make sure it's public otherwise removing won't work)
to remove the systray use Shell_NotifyIconA NIM_DELETE, NID
all systray commands now are processed in your yourpicbox_mousemove.
use msg = (x And &HFF) * &H100 to determine what is going on over the systray icon and If msg = &HF00 then whatever (left click), etc.
P.S. I don't remember the constants for all the mouse actions but I think they are all WM_ group.
hi well u were ryte, NID_DELET was private n making it public removes the icon from systray
now wat abt the next question dat i want to frequently update the icon, n lemme tell u project is same sa windows dialler n the icon i want to change is jus like blinking lights when data comes n goes.
adding n deleting icon each time wont do the job !
search on google for "mbtray". it's a .ocx file and it's easy to understand.
Here's the code. I figured I'd make a nice mod for my collection also.
VB Code:
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 Public Enum bMode Add = 1 Modify = 2 Delete = 3 End Enum Private Const WM_MOUSEMOVE As Integer = &H200 Private Const NIM_ADD = &H0& Private Const NIM_MODIFY As Integer = &H1 Private Const NIM_DELETE As Integer = &H2 Private Const NIF_MESSAGE As Integer = &H1 Private Const NIF_ICON As Integer = &H2 Private Const NIF_TIP As Integer = &H4 Private Declare Function Shell_NotifyIconA Lib "SHELL32" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long Public NID As NOTIFYICONDATA Public Sub TrayIcon(TrayPic As PictureBox, Optional TrayTip As String = "", Optional in_bMode As bMode = 1) If in_bMode = Add Then NID.cbSize = Len(NID) NID.hWnd = TrayPic.hWnd NID.uID = 0 NID.uFlags = NIF_MESSAGE Or NIF_ICON Or NIF_TIP NID.uCallbackMessage = WM_MOUSEMOVE NID.hIcon = TrayPic.Picture NID.szTip = TrayTip + Chr$(0) Shell_NotifyIconA NIM_ADD, NID ElseIf in_bMode = Modify Then NID.cbSize = Len(NID) NID.hIcon = TrayPic.Picture NID.szTip = TrayTip + Chr$(0) Shell_NotifyIconA NIM_MODIFY, NID ElseIf in_bMode = Delete Then Shell_NotifyIconA NIM_DELETE, NID End If End Sub
To add a pic use TrayIcon yourpicturebox, "test_add", Add
To modify (animate to a next slide) use TrayIcon your2ndpicturebox, "test_modify", Modify
To delete use TrayIcon TrayPic, vbNullString, Delete
Make sure an ICON is loaded into your picturebox, not a bitmap.
hi well i havent tried ur code as yet but can jus explain the parameters passed to NotifyIconData n explain their purpose !
A systray example from my archives. See also the topic the attachment is posted in for more information. :)
Hi everybdy...
....VB Code:
Private Const WM_MOUSEMOVE As Integer = &H200....
can any one of u please tell me how to remeber all these CONSTANTS...Is there any specific way to remember or else will these come automatically with the API viewer(Like Type Variables..)..I tried with API Viewer,but they didn't come ..Please tell me :( whatz the use of these constants and hw to remember these..
rgrds
Srikanth..
THey are in API viewer. Make sure you load WIN32API.txt and the contants will be in the API Type dropdown.
P.S. It is impossible to remember all the contants on top of all the declarations because you can make your own DLL with its own declarations and your own constants like Const Five As Integer = 5. They are used to simplify coding/for the code to make more sense, you do NOT have to use them. You can replace every Five with a 5 in the code, or in your example every WM_MOSEMOVE with 512 (&H200 = 512). The problem is if you use 512, how are you going to remember when updating your project that 512 is mousemove? Instead of having
case 513
case 519
case 516
I'd rather have
case WM_LBUTTONDOWN
case WM_MBUTTONDOWN
case WM_RBUTTONDOWN
It just makes your life easier.
hyousuf2: Click here for the explanation
Hmmmm...
The code that has been posted, no offence Merri, is a little bit of a hack.
By this I mean using a forms Mouse events to handle systray events. Personally I don't like this. It also means you have to replicate code from app to app that use the systray.
The link in my sig has come systray code that allows you to create a systray icon with it's own window to handle it's events. No need for a form.
It also allows for dynamic menus at runtime and does not reply on the menu from a form.
It is also capable of animated systray icons, of which there is a demo of in my code.
The systray code is wrapped up in a simple class that exposes usefull events and properties to the UI.
The code to use my systray icon class would be something like:
Hope this helps.Code:Option Explicit
Private mobjSystray As Systray
Private Sub Form_Load()
Set mobjSysTray = New SysTray
With mobjSysTray
Set .ImageList = ImageList1
.Icon = 1
.Menu.Add "Show", "SHOW", , , , False
.Menu.Add "Hide", "HIDE", , , , True
.Menu.Add "-"
.Menu.Add "Annimate", "ANNIMATE", , , False
.Menu.Add "-"
.Menu.Add "Exit Application", "EXIT"
.EnableMenu = True
.Visible = True
End With
End Sub
Private Sub mobjSysTray_DoubleClick(ByVal Button As MouseButtonConstants)
ShowForm
End Sub
Private Sub mobjSysTray_MenuClick(Item As vbSysTrayTools.MenuItem)
Select Case Item.Key
Case "SHOW"
ShowForm
Case "HIDE"
HideForm
Case "ANNIMATE"
'Annimate
Case "EXIT"
Unload Me
End Select
End Sub
Private Sub ShowForm()
With mobjSysTray.Menu
.Item("SHOW").Enabled = False
.Item("HIDE").Enabled = True
End With
Me.WindowState = vbNormal
Me.Show
End Sub
Private Sub HideForm()
With mobjSysTray.Menu
.Item("SHOW").Enabled = True
.Item("HIDE").Enabled = False
End With
Me.Hide
End Sub
WOka
PS I found this thread while trying to search for a method to get the hWnd of the icon window in the systray, as I need this for something I am working on. Anyone got any ideas?
a couple of mins ago i was going thru another thread, right here and guess what i found, the guy has a working(assumed) version of system tray icon or something u need and he is working with windows xp.
http://www.vbforums.com/showthread.php?t=320143
try it. he has attached a project there which has the class module. u even have a readymade example. :D
That example isn't the neatest I've seen around, but better than most, plus they are STILL using a form to deal with the systray messages. This is NOT required as is a cheap hack.
Also, the systray code doesn't have much functionality.
Woka