| 
			
				 
					作者: 程式碼
					
				 
		//--------------------------------------------------------------------------- 
 
#include <shlobj.h> 
#define NO_WIN32_LEAN_AND_MEAN  // 擺在這個位置, 就一定Complier OK 
#include <vcl.h> 
#pragma hdrstop 
 
#include "Unit1.h" 
#include "math.h" 
#include "stdlib.h" 
#include <Clipbrd.hpp> 
#include "inifiles.hpp" //要 include 這個東西才有 TIniFile 類別 
//--------------------------------------------------------------------------- 
#pragma package(smart_init) 
#pragma resource "*.dfm" 
TForm1 *Form1; 
//--------------------------------------------------------------------------- 
__fastcall TForm1::TForm1(TComponent* Owner) 
  : TForm(Owner) 
{ 
} 
//--------------------------------------------------------------------------- 
 
void __fastcall TForm1::Button1Click(TObject *Sender) 
{ 
  LPITEMIDLIST  DesktopPidl; 
  char DesktopDir[MAX_PATH]; 
    char sysDir[MAX_PATH]; 
  //將系統路徑填入此字元陣列中 
    ::GetSystemDirectory(sysDir, sizeof(sysDir)); 
    HRESULT hres; 
    IShellLink* psl; 
    //取得 IShellLink 介面的指標 
    hres = CoCreateInstance(CLSID_ShellLink, NULL, 
                            CLSCTX_INPROC_SERVER, 
                            IID_IShellLink, (void**)(&psl)); 
    LPMALLOC      ShellMalloc; 
//    LPITEMIDLIST  DesktopPidl; 
//    char DesktopDir[MAX_PATH]; 
 
    if(FAILED(SHGetMalloc(&ShellMalloc))) 
      return; 
 
    if(FAILED(SHGetSpecialFolderLocation(NULL, 
                                           CSIDL_DESKTOPDIRECTORY, 
                                           &DesktopPidl))) 
    return; 
 
    if(!SHGetPathFromIDList(DesktopPidl, DesktopDir)) 
    { 
      ShellMalloc->Free(DesktopPidl); 
      ShellMalloc->Release(); 
      return; 
    } 
 
    ShellMalloc->Free(DesktopPidl); 
    ShellMalloc->Release(); 
 
    //若成功取得,則進行 IShellLink 各項資料設定 
    if(SUCCEEDED(hres)) 
    { 
      //取得 IPersistFile 介面的指標 
      IPersistFile* ppf; 
      hres = psl->QueryInterface(IID_IPersistFile, (void**)(&ppf)); 
      //若成功取得,則進行 IShellLink 各項資料設定 
      if(SUCCEEDED(hres)) 
      { 
        //此範例連接檔的路徑,即是此執行檔路徑 
        hres = psl->SetPath(Application->ExeName.c_str()); 
        //此範例連接檔的路徑,即是此執行檔工作路徑 
        hres = psl->SetWorkingDirectory(ExtractFileDir(Application->ExeName).c_str()); 
        //設定此連接檔的類型 
        hres = psl->SetDescription("C_ShellLink"); 
        //設定此連接檔放置何處,本範例的連接檔放置在桌面上 
        WideString strShortCutLocation(DesktopDir); 
        strShortCutLocation += "\\C_ShellLink.lnk"; 
        hres = ppf->Save(strShortCutLocation.c_bstr(), TRUE); 
        //hres = ppf->Save(WideString(DesktopDir+"\\C_ShellLink.lnk"), true); 
        //完成後,將IPersistFile介面釋放 
        ppf->Release(); 
      } 
      //完成後,將IShellLink介面釋放 
    } 
    psl->Release(); 
    Button1->Enabled=false; 
} 
//--------------------------------------------------------------------------- 
 
void __fastcall TForm1::FormCreate(TObject *Sender) 
{ 
  BorderStyle=bsNone; 
  Width=200; //若系統不是WIndows 7請移除本段程式碼 
  LPITEMIDLIST  DesktopPidl; 
  char DesktopDir[MAX_PATH]; 
  RECT rec; 
  HWND hwnd; 
  hwnd=::FindWindow("Shell_TrayWnd",NULL); 
  ::GetWindowRect(hwnd,&rec); 
  Top=rec.top-Height; 
  Left=rec.right-Width; 
  if(FileExists(ChangeFileExt( Application->ExeName, ".ini" ))){ 
    Button2->Caption="取消INI檔"; 
    TIniFile *MyIni; 
    MyIni = new TIniFile(ChangeFileExt( Application->ExeName, ".ini" ) ); 
    Top=MyIni->ReadInteger("Option","Top",Top); 
    Left=MyIni->ReadInteger("Option","Left",Left); 
    delete MyIni; 
  } 
  if(FAILED(SHGetSpecialFolderLocation(NULL,CSIDL_DESKTOPDIRECTORY,&DesktopPidl))) return;    //CSIDL_LOCAL_APPDATA 
  SHGetPathFromIDList(DesktopPidl, DesktopDir); 
  if(FileExists((AnsiString(DesktopDir)+"\\C_ShellLink.lnk").c_str())) Button1->Enabled=false; 
} 
//--------------------------------------------------------------------------- 
void __fastcall TForm1::Button2Click(TObject *Sender) 
{ 
  if(FileExists(ChangeFileExt( Application->ExeName, ".ini" ))){ 
    Button2->Caption="儲存INI檔"; 
    DeleteFile(ChangeFileExt( Application->ExeName, ".ini" )); 
  } else { 
    Button2->Caption="取消INI檔"; 
    TIniFile *MyIni; 
    MyIni = new TIniFile(ChangeFileExt( Application->ExeName, ".ini" ) ); 
    MyIni->WriteInteger( "Option","Top",Top); 
    MyIni->WriteInteger( "Option","Left",Left); 
    delete MyIni; 
  } 
} 
//--------------------------------------------------------------------------- 
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action) 
{ 
  if(FileExists(ChangeFileExt( Application->ExeName, ".ini" ))){ 
    TIniFile *MyIni; 
    MyIni = new TIniFile(ChangeFileExt( Application->ExeName, ".ini" ) ); 
    MyIni->WriteInteger( "Option","Top",Top); 
    MyIni->WriteInteger( "Option","Left",Left); 
    delete MyIni; 
  } 
} 
//--------------------------------------------------------------------------- 
void __fastcall TForm1::Timer1Timer(TObject *Sender) 
{ 
  int x,y,hr,min,sec; 
  float j; 
  x=Image1->Width/2; 
  y=Image1->Height/2; 
  Image1->Canvas->Pen->Color=clBlack; 
  Image1->Canvas->Pen->Width=2; 
  Image1->Canvas->Ellipse(0,0,Image1->Width,Image1->Height); 
  for(int i=0;i<60;i=i+5){ 
    j=-1.57+3.14*i/30; 
    if (i==0||i==15||i==30||i==45){ 
      Image1->Canvas->Pen->Width=2; 
      Image1->Canvas->MoveTo(x+cos(j)*85,y+sin(j)*85); 
      Image1->Canvas->LineTo(x+cos(j)*98,y+sin(j)*98); 
    } else { 
      Image1->Canvas->Pen->Width=1; 
      Image1->Canvas->MoveTo(x+cos(j)*90,y+sin(j)*90); 
      Image1->Canvas->LineTo(x+cos(j)*98,y+sin(j)*98); 
    } 
    if (i==0) Image1->Canvas->TextOut((x+cos(j)*80)-5,(y+sin(j)*80)-5,"12"); 
    else Image1->Canvas->TextOut((x+cos(j)*80)-5,(y+sin(j)*80)-5,i/5); 
  } 
  Image1->Canvas->Pen->Color=clBlue; 
  min=TimeToStr(Time()).SubString(9,2).ToInt(); 
  j=-1.57+3.14*min/30; 
  Image1->Canvas->Pen->Width=4; 
  Image1->Canvas->MoveTo(x,y); 
  Image1->Canvas->LineTo(x+cos(j)*70,y+sin(j)*70); 
  hr=TimeToStr(Time()).SubString(6,2).ToInt(); 
//  j=-1.57+3.14*(hr*5)/30; 
  j=-1.57+3.14*hr/6+(3.14/360*min); 
  Image1->Canvas->Pen->Width=7; 
  Image1->Canvas->MoveTo(x,y); 
  Image1->Canvas->LineTo(x+cos(j)*55,y+sin(j)*55); 
   
  Image1->Canvas->Pen->Color=clRed; 
  sec=TimeToStr(Time()).SubString(12,2).ToInt(); 
  j=-1.57+3.14*sec/30; 
  Image1->Canvas->Pen->Width=3; 
  Image1->Canvas->MoveTo(x,y); 
  Image1->Canvas->LineTo(x+cos(j)*80,y+sin(j)*80); 
} 
//--------------------------------------------------------------------------- 
 
void __fastcall TForm1::Button3Click(TObject *Sender) 
{ 
  Close(); 
} 
//--------------------------------------------------------------------------- 
 
void __fastcall TForm1::Image1MouseDown(TObject *Sender, 
      TMouseButton Button, TShiftState Shift, int X, int Y) 
{ 
  if(Button==mbLeft){ 
    ::ReleaseCapture(); 
    SNDMSG(Handle,WM_SYSCOMMAND,SC_MOVE+HTCAPTION,0); 
  }   
} 
//--------------------------------------------------------------------------- 
			
		 |