dfhaines
asked on
VB 5.0 App in Windows 95 Taskbar
As you know, when you run an app a corresponding entry is placed in the Windows 95 Taskbar. This entry usually consists of the App icon and a title. Next to the Current Time in the taskbar, you might find small icons such as Norton Antivirus. I would like to code my VB 5.0 app such that its icon is placed next to the current time, i.e., next to the Norton Antivirus icon, and not on the taskbar like most other applications.
Any thoughts?
Any thoughts?
What you are asking for is a tray'd app. I have code to do this, so I will lock the question while I get the code & post it as a comment. Give me a few minutes.
Here is the code for traying an app:
Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Dim TrayIcon As NOTIFYICONDATA
' Used by Shell_NotifyIcon
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 Sub Form_Load()
' ************************** ********** ********** ********** ********** ********** ********** *
' ** Form Load **
' ************************** ********** ********** ********** ********** ********** ********** *
' More Tray Icon Stuff
' The Tooltip for the icon
TrayIcon.szTip = "Tray Icon Tip" & Chr$(0)
TrayIcon.cbSize = Len(TrayIcon)
' Handle of the window used to handle messages
TrayIcon.hWnd = Me.hWnd
' ID code of the icon
TrayIcon.uId = vbNull
' Flags
TrayIcon.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
' ID of the call back message
TrayIcon.ucallbackMessage = WM_MOUSEMOVE
' The icon
TrayIcon.hIcon = imgIcon.Picture
' Add icon to the tray
Call Shell_NotifyIcon(NIM_ADD, TrayIcon)
' Don't let application appear in the Windows task list
App.TaskVisible = False
Hide
End Sub
Ronnie
Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Dim TrayIcon As NOTIFYICONDATA
' Used by Shell_NotifyIcon
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 Sub Form_Load()
' **************************
' ** Form Load **
' **************************
' More Tray Icon Stuff
' The Tooltip for the icon
TrayIcon.szTip = "Tray Icon Tip" & Chr$(0)
TrayIcon.cbSize = Len(TrayIcon)
' Handle of the window used to handle messages
TrayIcon.hWnd = Me.hWnd
' ID code of the icon
TrayIcon.uId = vbNull
' Flags
TrayIcon.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
' ID of the call back message
TrayIcon.ucallbackMessage = WM_MOUSEMOVE
' The icon
TrayIcon.hIcon = imgIcon.Picture
' Add icon to the tray
Call Shell_NotifyIcon(NIM_ADD, TrayIcon)
' Don't let application appear in the Windows task list
App.TaskVisible = False
Hide
End Sub
Ronnie
ASKER
Ronnie,
Thanks for your quick response. Before I can accept this answer, however, I need to know the declarations for the constants mentioned in your proposed answer (i.e., NIM_ADD, NIM_ICON, NIF_TIP, NIF_MESSAGE, WM_MOUSEMOVE). Resubmit the answer with these declarations and then I will be able to test your solution.
Thanks,
David
Thanks for your quick response. Before I can accept this answer, however, I need to know the declarations for the constants mentioned in your proposed answer (i.e., NIM_ADD, NIM_ICON, NIF_TIP, NIF_MESSAGE, WM_MOUSEMOVE). Resubmit the answer with these declarations and then I will be able to test your solution.
Thanks,
David
ASKER
I would like to make the following clarifications via case scenarios:
Case 1:
When you minimize the application, it should not appear as most other applications appear in the taskbar (i.e., Microsoft Word). Rather, it should appear as an icon next to the current time display at the right-most part of the taskbar (provided your taskbar is placed at the bottom of the screen).
Case 2:
When this application is minimized, you should only need to click on the little icon next to the current time display in the taskbar in order to restore it to normal size.
Thanks.
Case 1:
When you minimize the application, it should not appear as most other applications appear in the taskbar (i.e., Microsoft Word). Rather, it should appear as an icon next to the current time display at the right-most part of the taskbar (provided your taskbar is placed at the bottom of the screen).
Case 2:
When this application is minimized, you should only need to click on the little icon next to the current time display in the taskbar in order to restore it to normal size.
Thanks.
Sorry about that, Give me a minute and I will get those for you. BTW you do not have to reject the answer if you are happy with the current expert. You can most a comment without grading or rejecting.
Personally, I would use a freeware ocx like SysTray32 available at:
http://www.download.com/PC/Result/TitleDetail/0,4,0-37597,501000.html
But then, that's just me.
http://www.download.com/PC/Result/TitleDetail/0,4,0-37597,501000.html
But then, that's just me.
Well personally, I like to have total control of an app, and when you start using plug-ins you get into more trouble. Even if they are stable, unless you have the source, and a lot of people using it to determine when you have reached the limits, you get into trouble.
dfhaines: I am having someone send me the rest of the file from my home pc. Might take a few.
Ronnie
dfhaines: I am having someone send me the rest of the file from my home pc. Might take a few.
Ronnie
here are the declarations that I used:
' Used to detect clicking on the icon
Private Const WM_LBUTTONDBLCLK = &H203
Private Const WM_RBUTTONUP = &H205
' Used to control the icon
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIF_MESSAGE = &H1
Private Const NIM_DELETE = &H2
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
' Used as the ID of the call back message
Private Const WM_MOUSEMOVE = &H200
' Used to detect clicking on the icon
Private Const WM_LBUTTONDBLCLK = &H203
Private Const WM_RBUTTONUP = &H205
' Used to control the icon
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIF_MESSAGE = &H1
Private Const NIM_DELETE = &H2
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
' Used as the ID of the call back message
Private Const WM_MOUSEMOVE = &H200
ASKER
Ronnie,
I tried using the code, however, it did not meet the cases I set out in my last comment. In my project, I have two forms and one module. I placed your code, aside from the Form_Load code, in the General Declarations of the module and removed the Private call so I could use the function, type and constants in my form.
Any thoughts?
I tried using the code, however, it did not meet the cases I set out in my last comment. In my project, I have two forms and one module. I placed your code, aside from the Form_Load code, in the General Declarations of the module and removed the Private call so I could use the function, type and constants in my form.
Any thoughts?
redbaron:
Not to dwell on the subject but VB is based on the use of "plug-ins". To *not* use them when you can opens yourself up for a lot more work, including the maintenance nightmare of modifying the code of a dozen apps when the OS changes either through a rev or an SP.
Finally, you comment that you "like to have total control over an app" and yet you are using the API. My question is how much control of the API do you have?
Don't get me wrong, I'm not trying to steal your points. The answer you gave was correct and you should be awarded the points. All I'm saying is there is more than one way to do almost anything. I have better things to do than maintain code, so I choose the easy way.
Not to dwell on the subject but VB is based on the use of "plug-ins". To *not* use them when you can opens yourself up for a lot more work, including the maintenance nightmare of modifying the code of a dozen apps when the OS changes either through a rev or an SP.
Finally, you comment that you "like to have total control over an app" and yet you are using the API. My question is how much control of the API do you have?
Don't get me wrong, I'm not trying to steal your points. The answer you gave was correct and you should be awarded the points. All I'm saying is there is more than one way to do almost anything. I have better things to do than maintain code, so I choose the easy way.
is your main form an MDI client, or what? If you want to send me the code I will take a look at it and see what needs to be done.
mailto:mollerr@computer-de pot-inc.co m
mailto:mollerr@computer-de
cliffAbb:
I agree with the statement you made. I guess that coming from C, I am not very used to including items that I can't compile and test indiviually. VB has a lot of that, like you stated.
I agree with the statement you made. I guess that coming from C, I am not very used to including items that I can't compile and test indiviually. VB has a lot of that, like you stated.
Microsoft makes a very nice taskbar OCX, that should make it a piece of cake to do this. Go to the VB Owner's Area (www.microsoft.com/vbasic/). There should be a sample program there. You'll have to compile to OCX yourself, if you don't want to, or can't get to the site, mail me (ben@kescom.net) and I'll send it. The syntax is pretty simple. Here's my code:
Private Sub cSysTray1_MouseDown(Button As Integer, Id As Long)
Me.Visible = Not Me.Visible
End Sub
That's all I had to do. There's properties like what button, is the icon in the tray, etc.
Private Sub cSysTray1_MouseDown(Button
Me.Visible = Not Me.Visible
End Sub
That's all I had to do. There's properties like what button, is the icon in the tray, etc.
ASKER
Ronnie,
Resubmit your answer and I will accept it. I downloaded the systray ocx from Karland and it worked well. At some later point when I have time, I will try to debug the code you provided that I incorporated into my project.
Thanks,
David
Resubmit your answer and I will accept it. I downloaded the systray ocx from Karland and it worked well. At some later point when I have time, I will try to debug the code you provided that I incorporated into my project.
Thanks,
David
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
'Put this code in a form called form1 and
'create a button called command1
Private Sub Command1_Click()
ShowIcon
End Sub
Public Sub ShowIcon()
With nid
.cbSize = Len(nid)
.hwnd = Form1.hwnd
.uId = vbNull
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
.uCallBackMessage = WM_MOUSEMOVE
.hIcon = Form1.Icon
.szTip = "Text Here" & vbNullChar
End With
Shell_NotifyIcon NIM_ADD, nid
End Sub
' *********** PUT THE REST OF THIS CODE IN A MODULE!!! **********
'user defined type required by Shell_NotifyIcon API call
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
'constants required by Shell_NotifyIcon API call:
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_MOUSEMOVE = &H200
Public Const WM_LBUTTONDOWN = &H201 'Button down
Public Const WM_LBUTTONUP = &H202 'Button up
Public Const WM_LBUTTONDBLCLK = &H203 'Double-click
Public Const WM_RBUTTONDOWN = &H204 'Button down
Public Const WM_RBUTTONUP = &H205 'Button up
Public Const WM_RBUTTONDBLCLK = &H206 'Double-click
Public Declare Function Shell_NotifyIcon Lib "shell32" _
Alias "Shell_NotifyIconA" _
(ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Public nid As NOTIFYICONDATA
'create a button called command1
Private Sub Command1_Click()
ShowIcon
End Sub
Public Sub ShowIcon()
With nid
.cbSize = Len(nid)
.hwnd = Form1.hwnd
.uId = vbNull
.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
.uCallBackMessage = WM_MOUSEMOVE
.hIcon = Form1.Icon
.szTip = "Text Here" & vbNullChar
End With
Shell_NotifyIcon NIM_ADD, nid
End Sub
' *********** PUT THE REST OF THIS CODE IN A MODULE!!! **********
'user defined type required by Shell_NotifyIcon API call
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
'constants required by Shell_NotifyIcon API call:
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_MOUSEMOVE = &H200
Public Const WM_LBUTTONDOWN = &H201 'Button down
Public Const WM_LBUTTONUP = &H202 'Button up
Public Const WM_LBUTTONDBLCLK = &H203 'Double-click
Public Const WM_RBUTTONDOWN = &H204 'Button down
Public Const WM_RBUTTONUP = &H205 'Button up
Public Const WM_RBUTTONDBLCLK = &H206 'Double-click
Public Declare Function Shell_NotifyIcon Lib "shell32" _
Alias "Shell_NotifyIconA" _
(ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Public nid As NOTIFYICONDATA