C++ 无法获取窗口c的像素颜色++;

C++ 无法获取窗口c的像素颜色++;,c++,winapi,C++,Winapi,我是使用windows.h库和从windows获取信息等方面的初学者。 我已经写了一个代码来查找任何窗口的像素颜色。我不确定我做错了什么 #include <iostream> #include <windows.h> using namespace std; COLORREF centerColor; POINT cent; int main() { HWND hd = FindWindow(NULL, L"Untitled - Notepad");

我是使用windows.h库和从windows获取信息等方面的初学者。 我已经写了一个代码来查找任何窗口的像素颜色。我不确定我做错了什么

#include <iostream>
#include <windows.h>

using namespace std;
COLORREF centerColor;
POINT cent;
int main()
{
    HWND hd = FindWindow(NULL, L"Untitled - Notepad");
    HDC hdc_ = GetDC(hd); 
    cent.x = 0;
    cent.y = 0;
    centerColor = GetPixel(hdc_, cent.x, cent.y);
    cout << centerColor;
}
#包括
#包括
使用名称空间std;
COLORREF中心色;
点分;
int main()
{
HWND hd=FindWindow(NULL,L“无标题记事本”);
HDC HDC_uu=GetDC(hd);
分x=0;
分y=0;
centerColor=GetPixel(hdc_u2;,cent.x,cent.y);
cout您的代码可能正在工作(假设您具有正确的窗口名称格式);只是您可能不理解
COLORREF
对象的格式。请尝试以下操作:

#include <iostream>
#include <windows.h>

using namespace std;
COLORREF centerColor;
POINT cent;
int main()
{
    HWND hd = FindWindow(NULL, L"Untitled - Notepad");
//  HWND hd = FindWindow(NULL, "Untitled - Notepad"); // Use this version if you are NOT using a Unicode build!
    HDC hdc_ = GetDC(hd);
    cent.x = 0;
    cent.y = 0;
    centerColor = GetPixel(hdc_, cent.x, cent.y);
//  cout << centerColor;
    cout << int(GetRValue(centerColor)) << " " << int(GetGValue(centerColor)) << " " << int(GetBValue(centerColor)) << endl;
    ReleaseDC(hd, hdc_); // You should call this when you've finised with the DC!
}
#包括
#包括
使用名称空间std;
COLORREF中心色;
点分;
int main()
{
HWND hd=FindWindow(NULL,L“无标题记事本”);
//HWND hd=FindWindow(NULL,“Untitled-Notepad”);//如果不使用Unicode构建,请使用此版本!
HDC HDC_uu=GetDC(hd);
分x=0;
分y=0;
centerColor=GetPixel(hdc_u2;,cent.x,cent.y);
//库特