?
Solved

In/Out Board - Right-click menus and Icon

Posted on 2003-02-26
7
Medium Priority
?
331 Views
Last Modified: 2012-05-04
Hi All,
I have a In/Out Board application I would like to run in icon mode ( near the clock ), but when I open it I don't want it on the task bar, just always visible, so when you close it the icon stays near the clock.
Also any way I can get menus by right clicking on the icon?
Also is it hard to get the icon to change? IE from red to green?

Cheers

Steven
0
Comment
Question by:StevenFay
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 1

Expert Comment

by:Smashmad
ID: 8030524
When you open it.. do you want it always on top?
0
 
LVL 1

Accepted Solution

by:
Smashmad earned 600 total points
ID: 8030617
Hi Steven, i hope this work.

'YOU MUST PUT THIS IN A .BAS MODULE

'this type is necessary for the Shell_NotifyIcon API
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 for use with SetWindowLong API
Public Const GWL_WNDPROC = (-4)
Public Const GWL_USERDATA = (-21)

'Constants for use with Shell_NotifyIcon API
Public Const NIM_ADD = &H0
Public Const NIM_MODIFY = &H1
Public Const NIM_DELETE = &H2

'Constants for use with NOTIFYICONDATA Type
Public Const NIF_MESSAGE = &H1
Public Const NIF_ICON = &H2
Public Const NIF_TIP = &H4

'Constants for use in Callback lParam value
Public Const WM_MOUSEMOVE = &H200
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const WM_LBUTTONDBLCLK = &H203
Public Const WM_RBUTTONDOWN = &H204
Public Const WM_RBUTTONUP = &H205
Public Const WM_RBUTTONDBLCLK = &H206
Public Const WM_MBUTTONDOWN = &H207
Public Const WM_MBUTTONUP = &H208
Public Const WM_MBUTTONDBCLICK = &H209

'API declarations for setting the tray icon
'Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean

'API declarations for capturing mouse events in the tray icon
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long



Public IconTray As NOTIFYICONDATA
Private WindowProc As Long



'NOW THE FUNCTONS
Public Sub AddIconTray(Frm As Form, tolTipText As String, icon)
With IconTray
    .cbSize = Len(IconTray)
    .hwnd = Frm.hwnd
    .uId = vbNull
    .uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
    .uCallBackMessage = WM_MOUSEMOVE
    .hIcon = icon
    .szTip = tolTipText & vbNullChar
End With
       
Shell_NotifyIcon NIM_ADD, IconTray
       
'set tray callback function
WindowProc = SetWindowLong(Frm.hwnd, GWL_WNDPROC, AddressOf CallBack)
End Sub


Public Function CallBack(ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
       
        'if the user clicked on the tray icon then
        'lets look at how they clicked and decide what to do.
        'when we set the tray icon, we gave it a callback message value of WM_MOUSEMOVE
        'if we receive that value, then we know its the tray icon responding.
       
        'the lParam value specifies what action was performed.
        'ie: left mouse down, middle mouse double click, etc..
        If msg = WM_MOUSEMOVE Then Call Form1.TrayMessage(lParam)
       
        CallBack = CallWindowProc(WindowProc, hwnd, msg, wParam, lParam)
End Function


Public Sub RemoveIconTray()
    'Disable callback
    SetWindowLong FrmMain.hwnd, GWL_WNDPROC, WindowProc
   
    Shell_NotifyIcon NIM_DELETE, IconTray
   
End Sub




'NOW, IN FORM1 (if its called form1, if not, you must change the name in the CallBack function) PLACE THIS CODE:

Public Sub TrayMessage(msg As Long)
Select Case msg
Case WM_LBUTTONDBLCLK 'doble click
     'example.. you can use any of WM_ constant, defined in the module
Case WM_RBUTTONUP 'click con el boton derecho
    'to popup a menu, create it like you create a menu for a form, and use it like that:
    PopupMenu mnuSysTray, , , , mnuTrayOpen
End Select
End Sub


DONT FORGET to call RemoveIconTray(), before exiting your program:
Private Sub Form_Unload(Cancel As Integer)
     Call RemoveIconTray
End Sub


Good Luck!
0
 
LVL 1

Expert Comment

by:Smashmad
ID: 8030666
If you dont want it to appear in the taskbar, set form's property
ShowInTaskBar = False

If you want the program to hide in the tray icon instead of close, you have to use the QueryUnload Event:


Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
'If user press the "X" in the top-Right corner
If UnloadMode = 0 Then
    Cancel = 1
    me.hide
End If
End Sub

BE VERY CAREFULL WHILE PROGRAMING WITH THOSE FUNCTIONS.. if you are debuging your app, and you force it to Stop, you will get a system error and VB will close.. (and you could lose your code).. be shure that you call removeiconTry before finish the app.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:StevenFay
ID: 8030969
Thanks for the replies guys
Am playing with it now;
Smashmad when I try and use the ShowInTaskBar it gives me a "Function or interface marked as restricted; or the function uses an automation type not supported in Visual basic"
0
 

Author Comment

by:StevenFay
ID: 8030990
Thanks for the replies guys
Am playing with it now;
Smashmad when I try and use the ShowInTaskBar it gives me a "Function or interface marked as restricted; or the function uses an automation type not supported in Visual basic"
0
 

Author Comment

by:StevenFay
ID: 8031063
Thanks for the replies guys
Am playing with it now;
Smashmad when I try and use the ShowInTaskBar it gives me a "Function or interface marked as restricted; or the function uses an automation type not supported in Visual basic"
0
 
LVL 1

Expert Comment

by:Smashmad
ID: 8037698
Hi Steven.
What VB version are you using?
you have to set up that property in forms, not in modules. And Im not sure, but it could be a property that you cant set in ejecution time.  So set it with the property dialog of the form.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month8 days, 21 hours left to enroll

764 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