Solved

System Tray Icon Hint Message (BCB4.0)

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
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.

910 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

22 Experts available now in Live!

Get 1:1 Help Now