Voici un morceau de code qui simule le tremblement de l'ecran
le .cpp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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);
}
le .h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ExtCtrls.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
        TTimer *Timer1;
        void __fastcall Timer1Timer(TObject *Sender);
        void __fastcall FormKeyDown(TObject *Sender, WORD &Key,
          TShiftState Shift);
        void __fastcall FormCreate(TObject *Sender);
private: // User declarations
public:  // User declarations
        __fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
Il me reste un probleme je n'arrive pas a detruire " pBitmap " j'ai systematiquement une erreur