Using GetPixel Function

Jan 4, 2010 at 9:18pm
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 Jan 4, 2010 at 10:27pm
Jan 4, 2010 at 9:47pm
You are not linking to the Windows library
Jan 4, 2010 at 10:19pm
Where can I find the windows library?
If I'm using codeblocks is it already included?
Jan 4, 2010 at 10:23pm
Which compiler are you using from codeblocks?
Which project template did you start from?
Jan 4, 2010 at 10:38pm
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.
Jan 4, 2010 at 10:51pm
Try starting from a Win32 GUI project, it should link to GDI
Jan 4, 2010 at 10:56pm
Yes, it worked, thank you.
Topic archived. No new replies allowed.