Solved

VB 5.0 App in Windows 95 Taskbar

Posted on 1998-06-18
16
235 Views
Last Modified: 2010-05-03
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?
0
Comment
Question by:dfhaines
  • 8
  • 4
  • 2
  • +2
16 Comments
 
LVL 1

Expert Comment

by:redbaron082997
ID: 1463695
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.
0
 
LVL 1

Expert Comment

by:redbaron082997
ID: 1463696
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
0
 

Author Comment

by:dfhaines
ID: 1463697
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
0
 

Author Comment

by:dfhaines
ID: 1463698
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.
0
 
LVL 1

Expert Comment

by:redbaron082997
ID: 1463699
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.
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1463700
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.
0
 
LVL 1

Expert Comment

by:redbaron082997
ID: 1463701
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
0
 
LVL 1

Expert Comment

by:redbaron082997
ID: 1463702
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

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:dfhaines
ID: 1463703
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?
0
 
LVL 6

Expert Comment

by:clifABB
ID: 1463704
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.
0
 
LVL 1

Expert Comment

by:redbaron082997
ID: 1463705
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-depot-inc.com
0
 
LVL 1

Expert Comment

by:redbaron082997
ID: 1463706
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.
0
 
LVL 1

Expert Comment

by:kesonline
ID: 1463707
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.
0
 

Author Comment

by:dfhaines
ID: 1463708
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
0
 
LVL 1

Accepted Solution

by:
redbaron082997 earned 70 total points
ID: 1463709
See above. Thanks dfhaines.
0
 

Expert Comment

by:ohayden
ID: 1463710
'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


0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now