fbalien
Messages postés251Date d'inscriptiondimanche 7 décembre 2003StatutMembreDernière intervention11 novembre 2016
-
28 août 2007 à 11:21
fbalien
Messages postés251Date d'inscriptiondimanche 7 décembre 2003StatutMembreDernière intervention11 novembre 2016
-
28 août 2007 à 22:23
Bonjour
j'utilise le code suivant pour faire une capture de la souris
procedure TForm1.affichesouris;
var
infoCurseur: TCursorInfo;
fIcon: TIcon;
infoIcon: TIconInfo;
begin
infocurseur.hCursor := 0;
infoCurseur.cbSize := SizeOf(infoCurseur);
fIcon := TIcon.Create;
if GetCursorInfo(infoCurseur) then
if infoCurseur.Flags = CURSOR_SHOWING then
begin
fIcon.Handle := CopyIcon(infocurseur.hCursor );
if ficon.Handle = 0 then caption := (SysErrorMessage(GetLastError )) + inttostr(infocurseur.hCursor );
if GetIconInfo(fIcon.Handle, infoIcon) then
begin
DrawIcon(DCcompatible,infoCurseur.ptScreenPos.x-Integer(infoIcon.xHotspot),
infoCurseur.ptScreenPos.y-Integer(infoIcon.yHotspot),fIcon.Handle);
end;
DestroyIcon(icon.Handle );
end;
fIcon.free;
end;
mais au bout d'un certain temps çà ne marche plus ( plantage au bout de 9964 exécutions)
cela semble planter à la ligne fIcon.Handle := CopyIcon(infocurseur.hCursor );
où CopyIcon me renvoie un "paramètre incorrecte"
WhiteHippo
Messages postés1154Date d'inscriptionsamedi 14 août 2004StatutMembreDernière intervention 5 avril 20123 28 août 2007 à 18:24
Bonsoir
Ton problème vient du fait que des ressources ne sont pas désallouées. Il est dit dans la doc windows :
"GetIconInfo creates bitmaps for the hbmMask and hbmColor members of ICONINFO. The calling application must manage these bitmaps and delete them when they are no longer necessary. "
En clair, il ne faut pas oublier de les libérer à la fin de ta fonction. Donc en ajoutant un
DeleteObject(infoIcon.hbmMask);
DeleteObject(infoIcon.hbmColor);
avant le
DestroyIcon(ficon.Handle);
cela devrait solutionner ton problème.
Cordialement. <hr />"L'imagination est plus importante que le savoir." Albert Einstein