//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "ClockWndMain.h"
#include "Unit1.h"
#include <math.h>
#include <winuser.h>
#include <mmsystem.h>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TClockWnd *ClockWnd;
COLORREF ptCol1=RGB(167,166,170);
COLORREF ptCol2=RGB(255,255,255);
COLORREF IptCol1=RGB(0,255,255);
COLORREF IptCol2=RGB(0,128,128);
COLORREF IptCol3=RGB(0,0,0);
//COLORREF SecondCol=RGB(231,231,231);
TColor SecondCol=clBtnFace;
COLORREF ptrCol1=RGB(0,128,128);
COLORREF ptrCol2=RGB(167,166,170);
HRGN hrgn;
bool bStart=false;
HWND GetDesktopListView()
{ //231
return GetWindow(GetWindow(FindWindow("Progman",NULL),GW_CHILD),GW_CHILD);
}
//---------------------------------------------------------------------------
__fastcall TClockWnd::TClockWnd(TComponent* Owner)
: TForm(Owner)
{
Width=140;
Height=140;
Left=Screen->WorkAreaWidth - 176;//848;
Top=Screen->WorkAreaHeight -170; //598;
//Timer3->Interval=30000;
}
//---------------------------------------------------------------------------
void __fastcall TClockWnd::FormPaint(TObject *Sender)
{
Timer1Timer(Timer1);
}
//---------------------------------------------------------------------------
void __fastcall TClockWnd::DrawClockFrame(POINT pt,int radius,TCanvas *MyCanvas)
{
//TODO: Add your source code here
int i;
int jiaodo=0;
int x,y;
double b;
for(i=0;i<60;i++)
{
b=jiaodo*3.14/180.0;
x=radius*cos(b)+pt.x;
y=radius*sin(b)+pt.y;
if(i%5==0)
{
MyCanvas->Pixels[x][y]=(TColor)IptCol2;
MyCanvas->Pixels [x-1][y]=(TColor)IptCol1;
MyCanvas->Pixels [x-1][y-1]=(TColor)IptCol1;
MyCanvas->Pixels [x][y-1]=(TColor)IptCol1;
MyCanvas->Pixels [x-1][y+1]=(TColor)IptCol1;
MyCanvas->Pixels [x][y+1]=(TColor)IptCol3;
MyCanvas->Pixels [x+1][y+1]=(TColor)IptCol3;
MyCanvas->Pixels [x+1][y]=(TColor)IptCol3;
MyCanvas->Pixels [x+1][y-1]=(TColor)IptCol3;
}
else
{
MyCanvas->Pixels [x][y]=(TColor)ptCol2;
MyCanvas->Pixels [x][y-1]= (TColor)ptCol1;
MyCanvas->Pixels [x-1][y-1]=(TColor)ptCol1;
MyCanvas->Pixels [x-1][y]=(TColor)ptCol1;
}
jiaodo+=6;
}
}
void __fastcall TClockWnd::FormCreate(TObject *Sender)
{
hrgn=CreateEllipticRgn(0,0,140,140);
SetWindowRgn(Handle,hrgn,1);
long lRt=GetWindowLong(Handle,GWL_EXSTYLE);
lRt=lRt|WS_EX_LAYERED;
SetWindowLong(Handle,GWL_EXSTYLE,lRt);
//SetLayeredWindowAttributes(Handle,clBtnFace,255,LWA_ALPHA);
OnTopNClick(NULL);
TouMingNClick(NULL);
}
//---------------------------------------------------------------------------
void __fastcall TClockWnd::FormMouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
Refresh();
if(Button==mbLeft)
{
ReleaseCapture();
Perform(WM_SYSCOMMAND,0xf017,0);
}
}
//---------------------------------------------------------------------------
void __fastcall TClockWnd::ExitNClick(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TClockWnd::Timer1Timer(TObject *Sender)
{
static unsigned short pmin=70;
static unsigned short psec=70;
TDateTime t=Now();
unsigned short hour,min,sec,msec;
t.DecodeTime(&hour,&min,&sec,&msec);
POINT centerPt;
centerPt.x = 135/2+1+1;
centerPt.y = 135/2+1+1;
int r;
r=centerPt.x-2;
if(r>centerPt.y-2)r=centerPt.y-2;
r=r-1;
//Canvas->Brush->Color =clBtnFace;
//Canvas->FillRect(Rect(0,0,140,140));
//DrawClockTime((int)hour,(int)min,(int)sec,centerPt,r,Canvas);
if(pmin!=min)
{
Image2->Canvas->Brush->Color =clBtnFace;
Image2->Canvas->FillRect(Rect(0,0,140,140));
DrawClockFrame(centerPt,r,Image2->Canvas);
DrawClockHourMin(hour,min,centerPt,r,Image2->Canvas);
}
//TCanvas *newCanvas=new TCanvas;
Canvas->CopyMode=cmSrcCopy;
DrawClockSec(psec,sec,centerPt,r,Image1->Canvas);
Canvas->CopyRect(Rect(0,0,140,140),Image2->Canvas,Rect(0,0,140,140));
//int old=Canvas->CopyMode;
Canvas->CopyMode=cmSrcInvert;
Canvas->CopyRect(Rect(0,0,140,140),Image1->Canvas,Rect(0,0,140,140));
pmin=min;
psec=sec;
}
//---------------------------------------------------------------------------
void __fastcall TClockWnd::DrawClockSec(unsigned short psec,unsigned short sec, POINT pt, int radius, TCanvas * MyCanvas)
{
//TODO: Add your source code here
int jiaodo,r,x,y;
double b;
MyCanvas->Brush->Color =clBlack;
MyCanvas->FillRect(Rect(0,0,140,140));
if(psec<60)
{
jiaodo=90+6*psec;
r=radius*0.9;
b=jiaodo*3.14/180.0;
x=-r*cos(b)+pt.x;
y=-r*sin(b)+pt.y;
MyCanvas->Pen->Color =(TColor)clBlack;
MyCanvas->MoveTo(pt.x,pt.y);
MyCanvas->LineTo(x,y);
}
jiaodo=90+6*sec;
r=radius*0.9;
b=jiaodo*3.14/180.0;
x=-r*cos(b)+pt.x;
y=-r*sin(b)+pt.y;
MyCanvas->Pen->Color =(TColor)SecondCol;
MyCanvas->MoveTo(pt.x,pt.y);
MyCanvas->LineTo(x,y);
}
void __fastcall TClockWnd::DrawClockHourMin(unsigned short hour, unsigned short min, POINT pt, int radius, TCanvas * MyCanvas)
{
//TODO: Add your source code here
TPoint pt1[5];
TPoint pt2[5];
int r1,r2;
r1=6;r2=4;
POINT offsetpt;
offsetpt.x =pt.x+2;
offsetpt.y=pt.y+2;
double r=0-radius*0.7;
if(hour>=12)hour-=12;
int offset=min/15;
int jiaodo=90+30*hour+offset*6;
double b=jiaodo*3.14/180.0;
pt1[0].x =r*cos(b)+offsetpt.x;
pt1[0].y=r*sin(b)+offsetpt.y;
pt2[0].x =r*cos(b)+pt.x;
pt2[0].y=r*sin(b)+pt.y;
//b=(jiaodo+180)*3.14/180;
pt1[2].x=r1*cos(b)+offsetpt.x;
pt1[2].y=r1*sin(b)+offsetpt.y;
pt2[2].x =r1*cos(b)+pt.x;
pt2[2].y=r1*sin(b)+pt.y;
b=(jiaodo+270)*3.14/180;
pt1[3].x=r2*cos(b)+offsetpt.x;
pt1[3].y=r2*sin(b)+offsetpt.y;
pt2[3].x =r2*cos(b)+pt.x;
pt2[3].y=r2*sin(b)+pt.y;
b=(jiaodo+90)*3.14/180;
pt1[1].x=r2*cos(b)+offsetpt.x;
pt1[1].y=r2*sin(b)+offsetpt.y;
pt2[1].x=r2*cos(b)+pt.x;
pt2[1].y=r2*sin(b)+pt.y;
pt1[4].x=pt1[0].x;
pt1[4].y=pt1[0].y;
pt2[4].x=pt2[0].x;
pt2[4].y=pt2[0].y;
MyCanvas->Pen->Color =(TColor)ptrCol2;
MyCanvas->Brush->Color =(TColor)ptrCol2;
MyCanvas->Polygon(pt1,4);
MyCanvas->Pen->Color =(TColor)ptrCol1;
MyCanvas->Brush->Color =(TColor)ptrCol1;
MyCanvas->Polygon(pt2,4);
jiaodo=90+6*min;
r=0-radius*0.8;
b=jiaodo*3.14/180.0;
pt1[0].x =r*cos(b)+offsetpt.x;
pt1[0].y=r*sin(b)+offsetpt.y;
pt2[0].x =r*cos(b)+pt.x;
pt2[0].y=r*sin(b)+pt.y;
//b=(jiaodo+180)*3.14/180;
pt1[2].x=r1*cos(b)+offsetpt.x;
pt1[2].y=r1*sin(b)+offsetpt.y;
pt2[2].x =r1*cos(b)+pt.x;
pt2[2].y=r1*sin(b)+pt.y;
b=(jiaodo+270)*3.14/180;
pt1[3].x=r2*cos(b)+offsetpt.x;
pt1[3].y=r2*sin(b)+offsetpt.y;
pt2[3].x =r2*cos(b)+pt.x;
pt2[3].y=r2*sin(b)+pt.y;
b=(jiaodo+90)*3.14/180;
pt1[1].x=r2*cos(b)+offsetpt.x;
pt1[1].y=r2*sin(b)+offsetpt.y;
pt2[1].x=r2*cos(b)+pt.x;
pt2[1].y=r2*sin(b)+pt.y;
pt1[4].x=pt1[0].x;
pt1[4].y=pt1[0].y;
pt2[4].x=pt2[0].x;
pt2[4].y=pt2[0].y;
MyCanvas->Pen->Color =(TColor)ptrCol2;
MyCanvas->Brush->Color =(TColor)ptrCol2;
MyCanvas->Polygon(pt1,4);
MyCanvas->Pen->Color =(TColor)ptrCol1;
MyCanvas->Brush->Color =(TColor)ptrCol1;
MyCanvas->Polygon(pt2,4);