GetPixel只能对桌面生效 其他任何窗口我试过颜色全是255 不知道是什么原因 我本意是想要 获取窗口内xy处的像素颜色值
相关问题
https://stackoverflow.com/questions/71281011/cant-get-getpixel-from-hwnd
代码
#include <iostream>
#include <Windows.h>
using namespace std;
int main() {
POINT pos;
int R;
int G;
int B;
while (1) {
//HWND hwnd = FindWindow(NULL, L"LDPlayer"); //FindWindow(NULL, windowTitle);
//HWND hwnd_child = FindWindowEx(hwnd, NULL, L"RenderWindow", L"TheRender");
HWND hwnd_child = FindWindowA("Notepad++", "new 2 - Notepad++");
HDC deviceContext1 = GetDC(hwnd_child);//这样就不行全是255
HDC deviceContext1 = GetDC(NULL);//改成这个就可以
GetCursorPos(&pos);
ScreenToClient(hwnd_child, &pos);
COLORREF color = GetPixel(deviceContext1, pos.x, pos.y);
SetPixel(deviceContext1, pos.x, pos.y, RGB(255, 0, 0));
R = GetRValue(color);
G = GetGValue(color);
B = GetBValue(color);
std::cout << "x : " << pos.x << ", y : " << pos.y << ", R : " << R << ", G : " << G << ", B : " << B << endl;
ReleaseDC(hwnd_child, deviceContext1);
Sleep(1000);
}
return 0;
}
相关问题
https://stackoverflow.com/questions/71281011/cant-get-getpixel-from-hwnd
代码
#include <iostream>
#include <Windows.h>
using namespace std;
int main() {
POINT pos;
int R;
int G;
int B;
while (1) {
//HWND hwnd = FindWindow(NULL, L"LDPlayer"); //FindWindow(NULL, windowTitle);
//HWND hwnd_child = FindWindowEx(hwnd, NULL, L"RenderWindow", L"TheRender");
HWND hwnd_child = FindWindowA("Notepad++", "new 2 - Notepad++");
HDC deviceContext1 = GetDC(hwnd_child);//这样就不行全是255
HDC deviceContext1 = GetDC(NULL);//改成这个就可以
GetCursorPos(&pos);
ScreenToClient(hwnd_child, &pos);
COLORREF color = GetPixel(deviceContext1, pos.x, pos.y);
SetPixel(deviceContext1, pos.x, pos.y, RGB(255, 0, 0));
R = GetRValue(color);
G = GetGValue(color);
B = GetBValue(color);
std::cout << "x : " << pos.x << ", y : " << pos.y << ", R : " << R << ", G : " << G << ", B : " << B << endl;
ReleaseDC(hwnd_child, deviceContext1);
Sleep(1000);
}
return 0;
}