Quote:
Originally posted by thebug:
How can i put icon in system tray (m$ win) with BCB (Borland C++ Builder) ?
|
in *.h
...
#define MYWM_NOTIFY WM_USER
#define IDC_MYICON 1006
...
void __fastcall DrawItem(TMessage& Msg);
void __fastcall MyNotify(TMessage& Msg);
...
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_DRAWITEM, TMessage, DrawItem)
MESSAGE_HANDLER(MYWM_NOTIFY, TMessage, MyNotify)
END_MESSAGE_MAP(TForm)
in *.cpp
LRESULT IconDrawItem(LPDRAWITEMSTRUCT lpdi)
{
HICON hIcon;
hIcon = (HICON)LoadImage(Application->Handle, MAKEINTRESOURCE(lpdi->CtlID),
IMAGE_ICON, 16, 16, 0);
if (!hIcon)
return(FALSE);
DrawIconEx(lpdi->hDC, lpdi->rcItem.left, lpdi->rcItem.top, hIcon,
16, 16, 0, NULL, DI_NORMAL);
return(TRUE);
}
//---------------------------------------------------------------------------
void __fastcall TFrm:
![Big Grin](https://forum.armkb.com/images/smilies/biggrin.gif)
rawItem(TMessage& Msg)
{
IconDrawItem((LPDRAWITEMSTRUCT)Msg.LParam);
TForm:
![Big Grin](https://forum.armkb.com/images/smilies/biggrin.gif)
ispatch(&Msg);
}
//---------------------------------------------------------------------------
void __fastcall TFrm::MyRestore(TMessage& Msg)
{
AppRestoreClick(NULL);
}
//---------------------------------------------------------------------------
void __fastcall TFrm::MyNotify(TMessage& Msg)
{
POINT MousePos;
switch(Msg.LParam)
{
case WM_RBUTTONUP:
if (GetCursorPos(&MousePos))
{
PopupMenu->PopupComponent = Frm;
SetForegroundWindow(Handle);
PopupMenu->Popup(MousePos.x, MousePos.y);
}
else
Show();
break;
/*case WM_LBUTTONUP: */ //TrayMessage(NIM_MODIFY); break;
case WM_LBUTTONDBLCLK: AppRestoreClick(NULL); break;
default:
break;
}
TForm:
![Big Grin](https://forum.armkb.com/images/smilies/biggrin.gif)
ispatch(&Msg);
}
//---------------------------------------------------------------------------
bool __fastcall TFrm::TrayMessage(DWORD dwMessage)
{
NOTIFYICONDATA tnd;
tnd.cbSize = sizeof(NOTIFYICONDATA);
tnd.hWnd = Handle;
tnd.uID = IDC_MYICON;
tnd.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
tnd.uCallbackMessage = MYWM_NOTIFY;
if (dwMessage == NIM_MODIFY)
{
tnd.hIcon = (HICON)Application->Icon->Handle;
lstrcpyn(tnd.szTip, Application->Title.c_str(), sizeof(tnd.szTip));
}
else
{
tnd.hIcon = NULL;
tnd.szTip[0] = '\0';
}
return (Shell_NotifyIcon(dwMessage, &tnd));
}
to set tray:
TrayMessage(NIM_ADD);
TrayMessage(NIM_MODIFY);
to delete:
TrayMessage(NIM_DELETE);
TrayMessage(NIM_MODIFY);