Unit1.cpp內容
語法:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::TRAYCALLBACK(TMessage& Message)
{
POINT MousePos;
switch(Message.LParam)
{
case WM_RBUTTONUP:
//
if (GetCursorPos(&MousePos))
{
PopupMenu1->PopupComponent = Form1;
SetForegroundWindow(Handle);
PopupMenu1->Popup(MousePos.x, MousePos.y);
}
break;
case WM_LBUTTONUP:
::ShellExecute(::GetDesktopWindow(),"explore",NULL,NULL,NULL,SW_SHOWNORMAL);
break;
default:
break;
}
TForm::Dispatch(&Message);
}
//---------------------------------------------------------------------------
void TForm1::ShowIcon()
{
Icon.cbSize=sizeof(NOTIFYICONDATA);
Icon.hWnd=Handle;
Icon.uID=(UINT)MYNOTIFYICONID;
Icon.uFlags=NIF_MESSAGE|NIF_ICON|NIF_TIP;
Icon.uCallbackMessage=MYWM_NOTIFYICON;
Icon.hIcon=LoadIcon(HInstance,"MAINICON");
strcpy(Icon.szTip,"Icon");
Shell_NotifyIcon(NIM_ADD,&Icon);
ShowWindow(Application->Handle,SW_HIDE);
ShowWindow(Handle,SW_HIDE);
}
//---------------------------------------------------------------------------
void TForm1::HideIcon()
{
Icon.cbSize=sizeof(NOTIFYICONDATA);
Icon.hWnd=Handle;
Icon.uID=(UINT)MYNOTIFYICONID;
Icon.uFlags=0;
Icon.uCallbackMessage=MYWM_NOTIFYICON;
Icon.hIcon=0;
strcpy(Icon.szTip,"Icon");
Shell_NotifyIcon(NIM_DELETE,&Icon);
ShowWindow(Application->Handle,SW_NORMAL);
ShowWindow(Handle,SW_NORMAL);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormActivate(TObject *Sender)
{
ShowIcon();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N2Click(TObject *Sender)
{
::ShellExecute(::GetDesktopWindow(),"explore",NULL,NULL,NULL,SW_SHOWNORMAL);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N4Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
HideIcon();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::N1Click(TObject *Sender)
{
char WinDir[MAX_PATH];
::GetWindowsDirectory(WinDir,MAX_PATH);
AnsiString sysdir=AnsiString(WinDir)+"\\Notepad.exe";
::ShellExecute(NULL,"open",sysdir.c_str(),NULL,NULL,SW_SHOWNORMAL);
}
//---------------------------------------------------------------------------
粗體部分需要KeyIn