Znikajace zasoby systemu

0

Siema :)
Mam maly (w zasadzie duzy) problem, ktory wystepuje pod win 98 (na xp cos takiego mi sie nie zdarza)
A mianowicie, gdy wiele razy wywolam taka funkcje:

function GetPixelColor(const X, Y: Integer): TColor;
var DesktopCanvas: TCanvas;
begin
DesktopCanvas := TCanvas.Create;
DesktopCanvas.Handle := GetWindowDC(GetDesktopWindow);
Result := GetPixel(DesktopCanvas.Handle, X, Y);
DesktopCanvas.Free
end;

w celu sprawdzenia koloru jakiegos pixela, drastycznie spadaja mi zasoby systemowe... po jakims czasie wszystko zaczyna sie wieszac (nie tylko moj program) W zwiazku z tym mam przeczucie ze nalezy jakos "czyscic" pamiec programu czy cos w tym stylu :P
Jak to robic? :)

0

hej.
wydaje się, że trzeba zwolnić te zasoby poprzez wywołanie funkcji ReleaseDC.
Wg helpa:
<cytat>
The GetWindowDC function retrieves the device context (DC) for the entire window, including title bar, menus, and scroll bars. A window device context permits painting anywhere in a window, because the origin of the device context is the upper-left corner of the window instead of the client area.

GetWindowDC assigns default attributes to the window device context each time it retrieves the device context. Previous attributes are lost.

HDC GetWindowDC(

HWND hWnd 	// handle of window  

);

Parameters

hWnd

Identifies the window with a device context that is to be retrieved.

Return Values

If the function succeeds, the return value is the handle of a device context for the specified window.
If the function fails, the return value is NULL, indicating an error or an invalid hWnd parameter.

Remarks

GetWindowDC is intended for special painting effects within a window's nonclient area. Painting in nonclient areas of any window is not recommended.
The GetSystemMetrics function can be used to retrieve the dimensions of various parts of the nonclient area, such as the title bar, menu, and scroll bars.
After painting is complete, the ReleaseDC function must be called to release the device context. Not releasing the window device context has serious effects on painting requested by applications.

int ReleaseDC(

HWND hWnd,	// handle of window 
HDC hDC 	// handle of device context  

);

Parameters

hWnd

Identifies the window whose device context is to be released.

hDC

Identifies the device context to be released.

Return Values

The return value specifies whether the device context is released. If the device context is released, the return value is 1.
If the device context is not released, the return value is zero.

Pozdr, pepe

0

No niestety kiszka :( Nie pomogło... caly czas po uruchomieniu programu i wielokrotnym uzyciu wspomnianej funkcji badania koloru zasoby systemowe spadaja w zastraszajacym tempie :/ (i nawet nie powracaja do normalnego stanu po wylaczeniu progsa :P )
Moze ktos ma na to inna rade?
Albo dobry, sprawdzony sposob na okreslenie wspolrzednych pixela jesli zna sie jego kolor - RGB?

0

Moze raz wez, i operuj na tym co wziales... no tak jakos mi sie skojarzylo :)

0

Nie do konca skumalem o co chodzi :P
A ja robie tak: biore pixel (1,1) i porownuje ze wzorcem za pomoca GetPixelColor, jesli kolor jest identyczny to koncze, a jesli nie to program przechodzi do nastepnego. I tak po kolei (1,2) (1,3) itd :P
Gdy dochodzi do konca linijki to wraca na poczatek, ale linijke nizej... (2,1) no i tak przez caly ekran. Cos w stylu wyszukiwania jakiegos elementu w macierzy :) Przy rozdzielce 800x600 juz troche tych pixeli jest do przebadania...
Juz nie wspomne ze jesli pixel jest daleko np. (500,400) to znalezienie go zajmuje kilka - kilkanascie sekund :/ (na Athlonie 1700XP)
Mowilem juz ze pod win xp program dziala bez zarzutu... widocznie ten system ma inne (lepsze) przydzielanie zasobow... no ja sie na tym tak dobrze nie znam, ale mysle ze to o to chodzi. Ale przeciez nie bede instalowal nowego systemu tylko po to aby program dzialal :P

0

sprawdzaj za pomoca scanline, dzialo to duzo szybciej

1 użytkowników online, w tym zalogowanych: 0, gości: 1