Jump to content
  • Advertisement
Sign in to follow this  
theredpill99

Using GetPixel() -problems with output

This topic is 5153 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
Advertisement
I would guess that the cin.get( ) call causes an output buffer flush. Thus to get things working how you want you need to use std::endl like so:

std::cout << clr9 << std::endl;

Share this post


Link to post
Share on other sites
Thanks. Do you know what Include I use or what I put at the top? I'm getting errors using MSVC++ 6.0 . It says:


error C2653: 'std' : is not a class or namespace name

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!