Solved

System Tray Icon Hint Message (BCB4.0)

Posted on 2002-05-18
3
572 Views
Last Modified: 2012-08-13
I am using Borland C++ Builder 4.0 pro

I have an application that places an icon in the system tray, when the user minimizes the application it goes to the icon, and can be restored by double clicking the icon.  There also is a hint message that is displayed when the mouse is over the icon.

I would like the message to be updated when the user places the mouse over the icon.

At present I can update the hint message when the application starts, and when the user switches to other parts of the application, but NOT when the user actually has the mouse over the icon (just before the hint message is actually displayed.)

Below are the functions that handle the icon, and where I believe I need to make changes (though I am not 100% for sure about this)

void __fastcall TformMain::AddIcon()
{
   NOTIFYICONDATA IconData;
   IconData.cbSize = sizeof(NOTIFYICONDATA);
   IconData.uID = IDC_TRAYICON;
   IconData.hWnd = Handle;
   IconData.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
   IconData.uCallbackMessage = WM_TRAYNOTIFY;
   HINT_MESSAGE = displayHintMessage();
   lstrcpy(IconData.szTip, HINT_MESSAGE);
   IconData.hIcon = TrayIcon->Handle;

   Shell_NotifyIcon(NIM_ADD, &IconData);
}

void __fastcall TformMain::ModifyIcon()
{
   NOTIFYICONDATA IconData;
   IconData.cbSize = sizeof(NOTIFYICONDATA);
   IconData.uID = IDC_TRAYICON;
   IconData.hWnd = Handle;
   IconData.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
   IconData.uCallbackMessage = WM_TRAYNOTIFY;
   HINT_MESSAGE = displayHintMessage();  
   lstrcpy(IconData.szTip, HINT_MESSAGE);
   IconData.hIcon = TrayIcon->Handle;

   Shell_NotifyIcon(NIM_MODIFY, &IconData);
}

void __fastcall TformMain::WMTrayNotify(TMessage &Msg)
{
   switch(Msg.LParam)
   {
      case WM_RBUTTONUP:
         POINT WinPoint;
         GetCursorPos(&WinPoint);
         SetForegroundWindow(Handle);
         popupMenu->Popup(WinPoint.x, WinPoint.y);
         PostMessage(Handle, WM_NULL, 0, 0);
         break;
      case WM_LBUTTONDBLCLK:
         Application->Restore();
         break;
   }
}

Thanks in advance. . .
0
Comment
Question by:LordDamein
  • 2
3 Comments
 
LVL 49

Accepted Solution

by:
DanRollins earned 130 total points
ID: 7018423
In your WMTrayNotify handler, you could check for WM_MOUSEMOVE and at that time, call your ModifyIcon fn to update the text.

In my app, I use a different technique:  I have a timer that checks for status changes once every second, and updates the tip text (via my equivalent of your ModifyIcon() fn) if it has changed.

-- Dan
0
 

Author Comment

by:LordDamein
ID: 7018505
Wow.  I have implemented a timer to check for status changes and update the tip text if needed.  That is a great technique.  Thanks! ! !
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7018586
Glad to help.

You can also change the icon image.  For instance it looks pretty snazzy if the the icon gets a red 'x' over it when the program is stopped.  Advanced: If you cycle the icon changes more often, you can even make the thing look animated (though
that is distracting).

Just a side comment... that technique originally got me into trouble becasue I was doing a LoadIcon with each call -- rather than just assigning IconData.hIcon= a_pre_loaded_handle .

LoadIcon can be called repeatedly without problem (the system just returns the handle to the previously-loaded icon), so that was alright.... until I switched to
    LoadImage(...,...,IMAGE_ICON, 16,16,...)
so that I could display a 16x16 icon (it appears less 'blurred' when displayed in the tray).  In that case, each call to LoadImage chewed up a resouce handle (a resource leak!).  I actually shipped some product that way.  After running for a few hours, the entire operating system started croaking... menus broke, fonts failed, it was embarassing.

-- Dan
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Quicksort a dynamic deque 33 58
Template syntax for variable length arrays 9 65
Safe conversion? 4 17
FMX TCameraComponent Problem 2 13
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

706 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

20 Experts available now in Live!

Get 1:1 Help Now