Pixel eines Fensters an bestimmter Position
-
Hallihallo Gemeinde,
Bin schon ganz verzweifelt auf der Suche nach einer passenden Lösung
für mein Problem. Und zwar will ich die Farbe eines bestimmten Pixels
an einer bestimmten Position ermitteln.Hier der Text:
int main() { HWND myhwnd = FindWindowA(NULL, "AB CD"); if (IsWindow(myhwnd) != FALSE) { HDC mydc = GetDC(myhwnd); COLORREF color = GetPixel(mydc, 747, 617); cout << color; } system ("Pause"); return 0; }Das Problem ist folgendes:
Die Ausgabe ist jedes mal 4294967295, egal welche Koordinaten ich angebe.
Da er ja etwas ausgibt muss er das Fenster doch gefunden haben, oder?Ich weiß im Moment gar nicht mehr weiter.
PS: Muss das Fenster aktiv oder eingeblendet sein (denn es ist minimiert) ?
-
Habe vergessen das Fenster vorher mit
ShowWindow(myhwnd, SW_SHOW);wieder aufpoppen zu lassen.
-
ok, scheint doch noch nicht so ganz zu funktionieren...
kann es sein, dass getpixel für bestimmte bereiche immer den gleichen wert zurueckgibt ?
-
habe grad geschaut wie groß COLORREF maximal ist, nämlich: 4294967295
kann es sein... dass der Wert außerhalb der für COLORREF bestimmten Range von
-2147483648 bis +2147483647 liegt ?Achja diese Zahl taucht aber nur auf für einen bestimmten Bereich innerhalb des Fensters myhwnd, andere bereiche lassen sich einwandfrei auslesen. Woran kann das liegen?
-
The return value is the RGB value of the pixel. If the pixel is outside of the current clipping region, the return value is CLR_INVALID.
-
Hm... sieht wohl os aus, als würde ich hängenbleiben...
Ähm gibts irgendwie ne Möglichkeit vom kompletten Screen ein Bild zu erzeugen und dann davon an selbiger Position die Pixelfarbe abzulesen?
-
So konnte dank Schritt-für-Schritt rausfinden, wo genau der Fehler liegt.
Also es liegt an der y-Koordinate...
für werte < 600 (z.B.: 599) funktioniert GetPixel
für werte >= 600 bekomm ich wieder 4294967295...Ich überlege grad ob es mit dem Fenster zusammenhängen kann.
-
If the pixel is outside of the current clipping region, the return value is CLR_INVALID. If the pixel is outside of the current clipping region, the return value is CLR_INVALID. If the pixel is outside of the current clipping region, the return value is CLR_INVALID. If the pixel is outside of the current clipping region, the return value is CLR_INVALID. If the pixel is outside of the current clipping region, the return value is CLR_INVALID. If the pixel is outside of the current clipping region, the return value is CLR_INVALID.
-
At which point the clipping region will be set?
-
If the pixel is inside the current clipping region as defined by the device context.
sincerely,
Wilhelm
-

-
alles klar, habs eben selbst rausgefunden...
Habe ZeileHDC mydc = GetDC(myhwnd);durch
HDC mydc = GetWindowDC(myhwnd);ersetzt.
Special THX to Wilhelm for his endurance
