查看單個文章
舊 2005-06-21, 05:02 PM   #2 (permalink)
魔術王子
版區管理員
 
魔術王子 的頭像
榮譽勳章
UID - 115097
在線等級: 級別:42 | 在線時長:1998小時 | 升級還需:23小時級別:42 | 在線時長:1998小時 | 升級還需:23小時
註冊日期: 2004-01-13
住址: 魔術學園
文章: 3007
精華: 0
現金: 15048 金幣
資產: 2678678 金幣
預設

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
魔術王子 目前離線  
送花文章: 1536, 收花文章: 1557 篇, 收花: 3898 次
回覆時引用此帖