?? utrayicon3.cpp
字號(hào):
//---------------------------------------------------------------------------
#include <vcl.h>
#include <shellapi.h>
#include <stdio.h>
#pragma hdrstop
#include <UTrayIcon3.h>
//---------------------------------------------------------------------------
TTrayIcon3 * TrayIcon3 ;
//---------------------------------------------------------------------------
bool IconWMDrawItem (LPDRAWITEMSTRUCT lpdi)
{ HICON hIcon = (HICON)LoadImage
(HInstance, 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 FAST TTrayIcon3:: WMDrawItem (TMessage& Msg)
{ IconWMDrawItem((LPDRAWITEMSTRUCT)Msg.LParam);
Dispatch(&Msg); // ???
}
//---------------------------------------------------------------------------
void FAST TTrayIcon3:: MyNotify (TMessage& Msg)
{
POINT MousePos;
switch(Msg.LParam)
{ case WM_RBUTTONUP:
if (GetCursorPos(&MousePos) && PopupMenu )
{
PopupMenu->PopupComponent = this ;
// SetForegroundWindow(??? Handle) ;
// handle of window to bring to foreground
PopupMenu->Popup(MousePos.x, MousePos.y) ;
}
// else Show();
break;
case WM_LBUTTONUP:
if(OnLeftClick) OnLeftClick(this, Msg) ;
break;
}
// Dispatch(&Msg);
}
//---------------------------------------------------------------------------
bool FAST TTrayIcon3:: 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 = FIcon->Handle ;
size_t st = sizeof(tnd.szTip) ;
CSTR cs = FTip.c_str() ;
strncpy (tnd.szTip, cs, st );
tnd.szTip[st-1] = '\0' ;
}
else
{ tnd.hIcon = NULL;
tnd.szTip[0] = '\0' ;
}
return Shell_NotifyIcon(dwMessage, &tnd) ;
}
//---------------------------------------------------------------------------
ASTR ASTR_LowName (ASTR FNam)
{ int ix = FNam.LastDelimiter(".") ;
if(1<ix) FNam = FNam.SubString(1, ix-1) ;
return FNam.LowerCase() ;
}
//---------------------------------------------------------------------------
void FAST TTrayIcon3:: Load_Icons (void)
{ Count = Items->Count ;
for(int ix=0 ; ix<Count ; ix++)
{ ASTR FNam = Items->Strings[ix] ;
TIcon* pi = new TIcon() ;
pi->LoadFromFile(FNam) ;
Items->Objects[ix] = pi ;
Items->Strings[ix] = ASTR_LowName(FNam) ;
}
}
//---------------------------------------------------------------------------
void FAST TTrayIcon3:: Del_Icons (void)
{ for(int ix=0 ; ix< Items->Count ; ix++)
{ delete Items->Objects[ix] ;
Items->Objects[ix] = NULL ;
}
}
//---------------------------------------------------------------------------
void FAST TTrayIcon3:: Off_Tray (void)
{ if(TrayOn) { TrayMessage(NIM_DELETE) ; TrayOn = false ; }
}
//---------------------------------------------------------------------------
FAST TTrayIcon3::TTrayIcon3(TWinControl* AOwner) : TFileListBox(AOwner)
{
Parent = AOwner ; // ??? yes - thats why need (TWinControl* AOwner)
Visible = false ; // else we bomb on Items->Count
FIcon = NULL ;
FTip = FIconName = "" ;
TrayOn = false ;
Mask = "*.ico" ;
Load_Icons() ;
}
//---------------------------------------------------------------------------
FAST TTrayIcon3:: ~TTrayIcon3 (void)
{ Off_Tray() ;
Del_Icons() ;
}
//---------------------------------------------------------------------------
void FAST TTrayIcon3:: SetIcon (TIcon* AIcon )
{ FIcon = AIcon ;
if (FIcon)
{ if(!TrayOn) { TrayMessage(NIM_ADD) ; TrayOn = true ; }
TrayMessage(NIM_MODIFY);
}
else Off_Tray() ;
}
//---------------------------------------------------------------------------
void FAST TTrayIcon3:: SetIconName (ASTR AIconName )
{ FIconName = AIconName.LowerCase() ;
int ix = Items->IndexOf(FIconName) ;
TIcon* AIcon ;
if(0<=ix) AIcon = (TIcon*) Items->Objects[ix] ;
else AIcon = Application->Icon ;
// TIcon* AIcon = (0<=ix) ? (TIcon*) Items->Objects[ix] : NULL ;
// avoiding NULL because app !Visible when wsMinimized
SetIcon(AIcon) ;
}
//---------------------------------------------------------------------------
void FAST TTrayIcon3:: NameAndTip (ASTR AIconName, ASTR ATip)
{ FTip = ATip ;
SetIconName(AIconName) ;
}
//---------------------------------------------------------------------------
void FAST TTrayIcon3:: SetTip( ASTR ATip)
{ FTip = ATip ;
if(!TrayOn) return ;
TrayMessage(NIM_MODIFY);
}
//---------------------------------------------------------------------------
ASTR FAST TTrayIcon3:: GetDir( void )
{ return FDirectory ; }
//---------------------------------------------------------------------------
void FAST TTrayIcon3:: SetDir( ASTR ADir )
{ Del_Icons() ;
Directory = ADir ;
Update() ;
Load_Icons() ;
}
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -