Using GetPixel Function

I'm trying to make a program that will detect the pixel color in the center of the screen. This is what I have:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <windows.h>

using namespace std;
COLORREF centerColor;
POINT cent;
int main()
{
HDC hdc_ = GetDC(GetDesktopWindow()) ;  //I'm not sure if this is right or what exactly it does.
cent.x = 640;
cent.y = 512;
centerColor = GetPixel(hdc_, cent.x, cent.y);
}


Codeblocks gives me this error when I try to compile:
undefined reference to `_GetPixel@12'


I think the problem might be that I don't understand what to put in the "hdc_" variable.
Last edited on
You are not linking to the Windows library
Where can I find the windows library?
If I'm using codeblocks is it already included?
Which compiler are you using from codeblocks?
Which project template did you start from?
I used the console application template with c++.
When I made the project the default compiler was set to "GNU GCC Compiler".
I tried compiling it with it set to Microsoft Visual C++ 2005/2008, but I got the same error (maybe I only set the default compiler to a different one, and not the compiler it uses on this project?).

Thanks for helping.
Try starting from a Win32 GUI project, it should link to GDI
Yes, it worked, thank you.
Topic archived. No new replies allowed.