home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2002 May
/
Chip_2002-05_cd1.bin
/
chplus
/
cpp
/
3
/
ikona.exe
/
traymain.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1998-02-09
|
5KB
|
182 lines
//----------------------------------------------------------------------------
//Borland C++Builder
//Copyright (c) 1987, 1998 Borland International Inc. All Rights Reserved.
//----------------------------------------------------------------------------
//---------------------------------------------------------------------------
#include <vcl.h>
#include <shellapi.h>
#pragma hdrstop
#include "traymain.h"
//---------------------------------------------------------------------------
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DrawItem(TMessage& Msg)
{
IconDrawItem((LPDRAWITEMSTRUCT)Msg.LParam);
TForm::Dispatch(&Msg);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::MyNotify(TMessage& Msg)
{
POINT MousePos;
switch(Msg.LParam)
{
case WM_RBUTTONUP:
if (GetCursorPos(&MousePos))
{
PopupMenu1->PopupComponent = Form1;
SetForegroundWindow(Handle);
PopupMenu1->Popup(MousePos.x, MousePos.y);
}
else
Show();
break;
case WM_LBUTTONUP:
ToggleState();
break;
default:
break;
}
TForm::Dispatch(&Msg);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
TrayMessage(NIM_DELETE);
}
//---------------------------------------------------------------------------
bool __fastcall TForm1::TrayMessage(DWORD dwMessage)
{
NOTIFYICONDATA tnd;
PSTR pszTip;
pszTip = TipText();
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 = IconHandle();
if (pszTip)
lstrcpyn(tnd.szTip, pszTip, sizeof(tnd.szTip));
else
tnd.szTip[0] = '\0';
}
else
{
tnd.hIcon = NULL;
tnd.szTip[0] = '\0';
}
return (Shell_NotifyIcon(dwMessage, &tnd));
}
//---------------------------------------------------------------------------
HANDLE __fastcall TForm1::IconHandle(void)
{
if (RadioButton1->Checked)
return (Image1->Picture->Icon->Handle);
else
return (Image2->Picture->Icon->Handle);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ToggleState(void)
{
if (RadioButton1->Checked)
{
RadioButton1->Checked = false;
RadioButton2->Checked = true;
}
else
{
RadioButton2->Checked = false;
RadioButton1->Checked = true;
}
TrayMessage(NIM_MODIFY);
}
//---------------------------------------------------------------------------
PSTR __fastcall TForm1::TipText(void)
{
if (RadioButton1->Checked)
return (Edit1->Text.c_str());
else
return (Edit2->Text.c_str());
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CheckBox1Click(TObject *Sender)
{
if (CheckBox1->Checked)
{
TrayMessage(NIM_ADD);
TrayMessage(NIM_MODIFY);
}
else
TrayMessage(NIM_DELETE);
Button1->Enabled = CheckBox1->Checked;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Hide();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RadioButtonClick(TObject *Sender)
{
if (!CheckBox1->Checked)
return;
TrayMessage(NIM_MODIFY);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::EditKeyUp(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if (!CheckBox1->Checked)
return;
TrayMessage(NIM_MODIFY);
}
//---------------------------------------------------------------------------
LRESULT IconDrawItem(LPDRAWITEMSTRUCT lpdi)
{
HICON hIcon;
hIcon = (HICON)LoadImage(g_hinst, 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 TForm1::Properties1Click(TObject *Sender)
{
Show();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ToggleState1Click(TObject *Sender)
{
ToggleState();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Shutdown1Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------