Sign in to follow this  

Using GetPixel() -problems with output

This topic is 4844 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. I'm using getpixel quite a bit and I'm having problems outputting text to the console window. For example:

HDC hdcDesktop2= GetDC(NULL);
	COLORREF clr,clr2,clr3,clr4,clr5,clr6,clr7,clr8,clr9,clr10,clr11,clr12,
		clr13,clr14,clr15,clr16,clr17,clr18,clr19;




    // Check if your get pixel call will succeed.
    if (GetPixel(hdcDesktop2, 100, 100) == CLR_INVALID) {
        printf("Get pixel error!\n");
        return 0;
    }

    clr = GetPixel(hdcDesktop2, 255+gtrans, 172+htrans); // 
    clr2 = GetPixel(hdcDesktop2, 254+gtrans, 169+htrans);
    clr3 = GetPixel(hdcDesktop2, 252+gtrans, 167+htrans);
    clr4 = GetPixel(hdcDesktop2, 249+gtrans, 166+htrans);
    clr5 = GetPixel(hdcDesktop2, 251+gtrans, 169+htrans);
    clr6 = GetPixel(hdcDesktop2, 249+gtrans, 171+htrans);
    clr7 = GetPixel(hdcDesktop2, 249+gtrans, 175+htrans);
    clr8 = GetPixel(hdcDesktop2, 251+gtrans, 178+htrans);
    clr9 = GetPixel(hdcDesktop2, 252+gtrans, 176+htrans);
   
ReleaseDC(NULL,hdcDesktop2);

cout<<clr9;

cin.get();  ////won't print to screen without this command

Without the cin.get(), I don't get any output to the screen for some reason. This is only one small portion of my code. Is it possible that due to some loops in code above this code I didn't release a device context and so that is why I'm not getting the output ?

Share this post


Link to post
Share on other sites
Nevermind. Got it working thanks to you !!! Thanks man.

This turned out to be the winner for me:

cout <<clr17<<"\n"<< endl;


The endl at the end made it spit the output to the screen. Thanks. I think you gave me some MFC code but its all good thanks dude.

Share this post


Link to post
Share on other sites

This topic is 4844 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this