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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
//---------------------------------------------------------------------------
#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::FormCreate(TObject *Sender)
{
RectTray;
HWND hwndTray = FindWindow("Shell_TrayWnd", NULL);
// on recupere les dimensions de la barre de tache
GetWindowRect(hwndTray, &RectTray);
// on recupere le Handle de la fenetre du bureau par son nom
HWND hwndBureau1 = FindWindow("Progman", "Program Manager");
HWND hwndBureau2 = FindWindowEx(hwndBureau1, NULL, "SHELLDLL_DefView", NULL);
hwndBureau3 = FindWindowEx(hwndBureau2, NULL,
"SysListView32", "FolderView");
// on positionne le curseur sur la barre de titre
// a 10 du bord gauche et 10 du bord haut
Pt.x = 10;
Pt.y = 10;
// parametree des dimensions de la (des) fenetre(s) que l'on va redimensionner
fX = 0;
fY = 50;
fWidth = Screen->Width;
fHeight = Screen->Height - 85;
// on recupere le Handle de la fenetre affichee sous le curseur
hwndAppli = WindowFromPoint(Pt);
// Si la (les) fenetre(s) au dessous est != du bureau
// on la (les) redimensionne
while(WindowFromPoint(Pt) != hwndBureau3)
{
hwndAppli = WindowFromPoint(Pt);
MoveWindow
(
hwndAppli, // handle of window
fX, // horizontal position
fY, // vertical position
fWidth, // width
RectTray.Top - 50, // height
true // repaint flag
);
}
// on affiche la fenetre de Zoom sans barre de titre en haut de l'ecran
Form1->BorderStyle = bsNone;
Form1->FormStyle = fsStayOnTop; // mettre la Form toujours au premier plan
Form1->Left = 0;
Form1->Top = 0;
Form1->Width = Screen->Width;
Form1->Height = 50;
Form1->Color = clSkyBlue;
Form1->Caption = "LoupePremierPlanEnHaut";
// on dimensionne le PaintBox pour qu'il s'inscrit dans la Form
// en laissant la place pour le Panel
PaintBox1->Top = 5;
PaintBox1->Left = 5;
PaintBox1->Height = Form1->Height - 10;
PaintBox1->Width = Form1->Width - 50;
PaintBox1->Visible = true;
// on positionne le TPanel sur la Form
Form1->Panel1->Top = 5;
Form1->Panel1->Left = Form1->Width - 40;
Form1->Panel1->Width = 37;
Form1->Panel1->Height = 37;
Form1->Panel1->Caption = "";
Application->Title = "Loupe";
// valeur de l'agrandissement par default au demarrage
Zoom = 2;
// initialisation Timer
Timer1->Interval = 150;
Timer1->Enabled = true;
flag = true;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::PaintBox1MouseUp(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
if(Button == mbRight)
{
// Femeture de la fenêtre sur un click droit sur le PaintBox.
Close();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormMouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
if(Button == mbRight)
{
// Femeture de la fenêtre sur un click droit sur la Form.
Close();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
if(flag == true)
{
// on cree un Canvas pour peindre sur le TPanel
// une croix blanche sur fond rouge
TControlCanvas *pCn;
pCn = new TControlCanvas();
pCn->Control = Form1->Panel1;
pCn->Brush->Color = clRed;
pCn->FillRect(Rect(2, 2, 35, 35));
pCn->Pen->Width = 5;
pCn->Pen->Color = clWhite;
pCn->MoveTo(10, 10);
pCn->LineTo(27, 27);
pCn->MoveTo(27, 10);
pCn->LineTo(10, 27);
delete pCn;
flag = false;
}
// on positionne le curseur sur la barre de titre
// a 10 du bord gauche et 51 du bord haut
Pt.x = 500;
Pt.y = 50;
HDC DC;
int zx;
int zy;
TRect Rect;
// on recupere le Handle de la fenetre sous la fenetre Zoom
hwndZoom = WindowFromPoint(Pt);
// on recupere les dimensions de la fenetre partiellement masquee
GetWindowRect(hwndZoom, &Rect);
// si la position Top de la fenetre est inf a 50 on redimensionne la fenetre
if(Rect.Top <= 50 && hwndZoom != hwndBureau3)
{
hwndAppli = WindowFromPoint(Pt);
MoveWindow
(
hwndAppli, // handle of window
fX, // horizontal position
fY, // vertical position
fWidth, // width
RectTray.Top - 50, // height
true // repaint flag
);
}
// Création d'un contexte d'affichage non lié à une fenêtre
// donc permet d'accéder à l'écran entier
DC = CreateDC("DISPLAY", NULL, NULL, NULL);
// prise des coordonnees de la souris
zx = Mouse->CursorPos.x;
zy = Mouse->CursorPos.y;
// limitations de la zone pour ne pas sortir de l'écran
if(zx >= (Screen->Width - ClientWidth / Zoom))
{
zx = (Screen->Width - ClientWidth / Zoom) - 1;
}
if(zy >= (Screen->Height - ClientHeight / Zoom))
{
zy = (Screen->Height - ClientHeight / Zoom) - 1;
}
// Copie d'une partie de l'écran dans la boite à peindre
StretchBlt(PaintBox1->Canvas->Handle // Copie vers le Canvas du PaintBox1
, 0 // vers X=0
, 0 // et Y=0
,(ClientWidth * Zoom) - 1 // en multipliant par Zoom la largeur
,(ClientHeight * Zoom) - 1 // en multipliant par Zoom la hauteur
,DC // Copie à partir du canevas global
,zx - 5 // de la position de la souris
,zy - 10 // ...
,ClientWidth // sur la taille de la boite
,ClientHeight //
,SRCCOPY); // Simple copie sans autre effet.
// ne pas oublier de libérer le contexte, c'est une ressource rare.
DeleteDC (DC);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Panel1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
// Femeture de la fenêtre sur un click sur le Panel.
Close();
}
//--------------------------------------------------------------------------- |