Click to See Complete Forum and Search --> : Application that displays an icon in the system tray and not in the taskbar?


AsTuR
May 12th, 1999, 12:42 PM
How can i make an application that displays an icon in the system tray and not in the taskbar?
And how can i make it without any icon? I mean, like winamp.

Ashley Antony
May 13th, 1999, 03:04 AM
Use Shell_NotifyIcon() API,

Ashley.Antony@in.bosch.com
B'lore,
India.

May 13th, 1999, 06:19 AM
This is a sample code which displays an icon with a context menu in the systemtray. Use can the code by changing the menu identifier,icon identifier etc..

Partha Sarathy

#define WM_ICONNOTIFY WM_USER + 1

LRESULT CEmailGUIDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
NOTIFYICONDATA nid;


switch(message)
{
case WM_CREATE :
nid.cbSize = sizeof(nid);
nid.hWnd = m_hWnd;
nid.uID = 1;
nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
nid.uCallbackMessage = WM_ICONNOTIFY;
nid.hIcon = AfxGetApp()->LoadIcon(MAKEINTRESOURCE(IDI_SAMPLE));
strcpy(nid.szTip,"System Tray");
Shell_NotifyIcon(NIM_ADD,&nid);
break;


case WM_ICONNOTIFY :
if((UINT)lParam == WM_LBUTTONDOWN)
{
::ShowWindow(m_hWnd,SW_SHOW);
::SetForegroundWindow(m_hWnd);
}
if((UINT)lParam == WM_RBUTTONDOWN)
{
CMenu menu,*SubMenu;
menu.LoadMenu(IDR_ICONMENU);
SubMenu = menu.GetSubMenu(0);
// Make first menu item the default (bold font)
::SetMenuDefaultItem(SubMenu->m_hMenu, 0, TRUE);

CPoint point;
GetCursorPos(&point);
::SetForegroundWindow(m_hWnd);
SubMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,point.x,point.y,this);

::PostMessage(m_hWnd,WM_ICONNOTIFY, 0, 0);
menu.DestroyMenu();
}

break;

case WM_DESTROY :
nid.cbSize = sizeof(nid);
nid.hWnd = m_hWnd;
nid.uID = 1;
nid.uFlags = 0;
Shell_NotifyIcon(NIM_DELETE,&nid);
PostQuitMessage(0);
break;
default :
break;
};