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
|
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, StdCtrls, shellapi, Jpeg, Menus, Buttons, ComCtrls;
type
TForm1 = class(TForm)
BTest: TButton;
procedure FormCreate(Sender: TObject);
private
{ Déclarations privées }
public
{ Déclarations publiques }
end;
TMyHintWindow = class(THintWindow)
private
JPG : TJPegImage;
Bmp,bmpbis: Tbitmap;
BMPLoaded : boolean;
NewW, NewH, OldSBM: Integer;
protected
procedure Paint; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure JPEGToBMP(JPG : TJPegImage; BMP : TBitmap);
begin
BMP.Width := JPG.Width;
BMP.Height:= JPG.Height;
BMP.PixelFormat := pf24bit;
BMP.Canvas.Draw(0,0,JPG);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
HintWindowClass := TMyHintWindow;
ShowHint := true;
BTest.Hint := ' ' ;
end;
constructor TMyHintWindow.Create(AOwner: TComponent);
begin
inherited;
BMPLoaded := false;
{ creation du Jpg temporaire }
jpg:= TJPEGImage.Create;
{ creation du bitmap temporaire }
bmp:=Tbitmap.Create;
{ creation du bitmap bis temporaire }
bmpbis:=Tbitmap.Create;
try
{ Chargement de l'image jpg }
jpg.loadFromFile('C:\Hint640x480.jpg');
{ convertion JPG > BMP }
JPEGToBMP(JPG,BMP);
{ BMP est prét }
BMPLoaded := true;
{ si BMP est prét }
if BMPLoaded then
begin
NewW := 160; //Dimensions width du Hint
NewH := 130; //Dimensions height du Hint
end;
{ enfin on va injecter Bmp dans le bitmap de bmpbis}
with bmpbis do
begin
{ on definit les nouvelles dimensions }
width := NewW ;
height := NewH;
{ on travail en couleurs 24bpc }
pixelformat := pf24bit;
{ on sauvegarde l'ancien mode de redimension du canvas }
OldSBM := GetStretchBltMode(Canvas.Handle);
{ et on le definit en mode HALFTONE }
SetStretchBltMode(Canvas.Handle, HALFTONE);
{ on dessine l'image }
StretchBlt( Canvas.Handle, 0, 0, NewW, NewH,
bmp.Canvas.Handle, 0, 0, bmp.Width, bmp.Height,
SRCCOPY);
{ on restaure le mode de redimensionnement du canvas }
SetStretchBltMode(Canvas.Handle, OldSBM);
{ on assigne }
jpg.Assign(bmpbis);
end;
except
FreeAndNil(jpg);
FreeAndNil(bmp);
FreeAndNil(bmpbis);
end;
end;
destructor TMyHintWindow.Destroy;
begin
bmp.Free;
bmpbis.free;
jpg.Free;
inherited;
end;
procedure TMyHintWindow.Paint;
var DC: HDC;
R: TRect;
begin
if Assigned(jpg) then
Canvas.Draw(1, 2, jpg);
inherited;
DC := GetWindowDC(Handle);
try
Height:=jpg.Height;
width:=jpg.width;
R := Rect(0, 0, Width, Height);
DrawEdge(DC, R, EDGE_ETCHED , BF_RECT + BF_MONO);
finally
ReleaseDC(Handle, DC);
end;
end;
end. |
Partager