Solved

System Tray Icon Hint Message (BCB4.0)

Posted on 2002-05-18
3
577 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

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…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

810 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