Hello everyone. This is my first post on this forum, please don't go hard on me if I didn't post it in the right place or if I did something wrong, I don't post in forums very much. So, I have this problem with GetPixel fuction. Basically, it should return the color decimal at x, y. The code I am about to post works perfectly on windows 7 32bit, but recently I bought a new laptop y50-70 with windows 8.1 64bit and the same code works completely different. I can't find any solution to the problem, can't even describe it. I think it could have something to do with desktop handle, HDC, GetDC(), GetPixel(), maybe even with my computer resolution, refresh rate or something like that... I have even recorded some videos which could help you understand the problem I am having because I can't even describe it correctly. It is like the real color is x = 219, y = 407 away from the place, where my mouse is pointing.
Feel free to use this code, hope it will work fine for you:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
#include <iostream>
#include <Windows.h>
using namespace std;
void Detect();
int main()
{
Detect();
return 0;
}
void Detect()
{
POINT p;
HDC hDC = GetDC(0);
int x, y;
while (!GetAsyncKeyState(VK_INSERT)) // Press insert to stop
{
GetCursorPos(&p);
x = p.x;
y = p.y;
hDC = GetDC(0);
cout << x << " " << y << " " << GetPixel(hDC, x, y) << endl;
Sleep(50);
}
ReleaseDC(0, hDC);
}
|
Links to the problem below:
https://youtu.be/q2H2M8WLHVI
https://youtu.be/UcneHwXaGoM
If anyone could at least help somehow or tell what to do, where to go, I would very, very much appreaciate it. One of the main reasons why I started programming is because something like this, working with colours, conditions, etc... and now I can't advance further which is really sad. Hope to hear a reply. Thank you.