Frage zu GetPixel();
-
Hallo,
The GetPixel function retrieves the red, green, blue (RGB) color value of the pixel at the specified coordinates.
COLORREF GetPixel(
HDC hdc, // handle of device context
int XPos, // x-coordinate of pixel
int nYPos // y-coordinate of pixel
);Parameters
hdc
Identifies the device context.
Wie bekomm ich den hdc von meinem Desktop?
Geht das mit CreateDC(); ?
The CreateDC function creates a device context (DC) for a device by using the specified name.
HDC CreateDC(
LPCTSTR lpszDriver, // pointer to string specifying driver name
LPCTSTR lpszDevice, // pointer to string specifying device name
LPCTSTR lpszOutput, // do not use; set to NULL
CONST DEVMODE *lpInitData // pointer to optional printer data
);Und wenn ja was für einen Treiber Namen muss ich dann da nehmen bei lpszDriver?
-
Habs gerade gefunden ^^
Aber jetzt hab ich ein neues Problem

#include <windows> #include <iostream> using namespace std; int main(int argc, char* argv[]) { COLORREF farbe; HDC desktop; desktop = GetDC(0) ; farbe = GetPixel(desktop, 100 , 100); if (farbe == CLR_INVALID) { cout<<"error"; } cout<< farbe <<endl; return 0; }Aber wieso bekomme ich nicht den RGB Farb Wert was mach ich da falsch ?

The GetPixel function retrieves the red, green, blue (RGB) color value of the pixel at the specified coordinates.
COLORREF GetPixel(
HDC hdc, // handle of device context
int XPos, // x-coordinate of pixel
int nYPos // y-coordinate of pixel
);Parameters
hdc
Identifies the device context.
nXPos
Specifies the logical x-coordinate of the pixel to be examined.
nYPos
Specifies the logical y-coordinate of the pixel to be examined.
Return Values
If the function succeeds, the return value is an RGB value. If the pixel is outside of the current clipping region, the return value is CLR_INVALID.
Remarks
The pixel must be within the boundaries of the current clipping region.
Not all devices support GetPixel. An application should call GetDeviceCaps to determine whether a specified device supports this function.See Also
GetDeviceCaps, SetPixel
-
Ach nochwas.
Das Programm gibt mir immer nur eine 0 aus.
-
Jetzt funktioniert es auf einmal o_O mhhm.
-
wieso bekommt es nie einer gebacken seine Lösung zu senden, wenn er nen Problem gelöst hat? ... >_>
-
Ich habe mel eine Frage zu dem C++ Quellcode.
#include <windows> #include <iostream> using namespace std; int main(int argc, char* argv[]) { COLORREF farbe; HDC desktop; desktop = GetDC(0) ; farbe = GetPixel(desktop, 100 , 100); if (farbe == CLR_INVALID) { cout<<"error"; } cout<< farbe <<endl; return 0; }Wenn ich versuche das Programm nach dem kompilieren zu starten, bricht das programm mit einer Fehlermeldung ab. Kann mir einer sagen woran das liegen könnte

mfg