1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
// initialisation du Timer
Timer1->Enabled = true;
Timer1->Interval = 10;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
// si on press [ESC] on quitte
if(Key == 27)
{
Form1->Close();
// arret du Timer
Timer1->Enabled = false;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
int x;
int y;
// on donne des valeurs aléatoire à x et y, max 10
randomize;
x = random(10);
y = random(10);
// on repositione la fenêtre
Form1->Left = x;
Form1->Top = y;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
HDC ScreenSrc;
Graphics::TBitmap *pBitmap = new Graphics::TBitmap;
ScreenSrc = GetWindowDC(HWND_DESKTOP);
if (ScreenSrc == NULL) return;
Form1->Height = Screen->Height;
Form1->Width = Screen->Width;
pBitmap->Height = Screen->Height;
pBitmap->Width = Screen->Width;
BitBlt(pBitmap->Canvas->Handle, 0, 0, pBitmap->Width, pBitmap->Height, ScreenSrc, 0, 0, SRCCOPY);
Form1->Brush->Bitmap = pBitmap;
Form1->Repaint();
ReleaseDC(HWND_DESKTOP, ScreenSrc);
} |
Partager