Thread: Just wondering

  1. #1
    Registered User asbo60's Avatar
    Join Date
    Jan 2006
    Posts
    38

    Question Just wondering

    Hi is there any way that you could detect colours? i mean like say you had the mouse pointer over a red bit on screen, how you make it tell you wat colour it was? I was thinking the only way you could do this was by setting up a mouse hook, and a little widow that follows the pointer. that may sound a little strange but thats all i could come up with.
    Come give my Website a visit and try my new program, all you gamers will love it!
    www.AzA-Productions.com
    Click on applications and download Key Control!

    Also I have tons of extra space available so, if you have a project or application you want the world to see just give me an email at [email protected] and ill see what i can do for you.

    Asbo60

  2. #2
    Registered User
    Join Date
    May 2006
    Location
    Berkshire, UK
    Posts
    29
    I can only think that this must be a low-level, os-specific call... the worst case I can think of is that you have to capture the screen image and work from that and the absolute mouse position... really horrible!

  3. #3
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Code:
    # include<iostream>
    # include<windows.h>
    
    using namespace std;
    
    int main( void )
    {
    
    	HDC		hdcScrn;	// Handle on accessing screen parameters. 
    	hdcScrn	= CreateDC( "DISPLAY", 0, 0, 0 );
    
    	COLORREF Col;		// a Color type
    
    	POINT Pos1, Pos2;	// cursor positions
    
    	while ( true )
    	{
    		GetCursorPos( &Pos1 );	// get cursor position
    
    		if ( (Pos1.x != Pos2.x) ||
    			 (Pos1.y != Pos2.y) )	// sees if the cursor has moved
    		{
    			GetCursorPos( &Pos2 );
    
    			Col = GetPixel( hdcScrn, Pos2.x, Pos2.y );	// sets the color variable to the cursor position. 
    
    			cout<< '\r' << "The color of Position ("<< Pos2.x << ',' << Pos2.y << "), is " << Col << "\t\t";
    		}
    	}
    
    	DeleteDC( hdcScrn );	// deletes the handle
    
    	return 0;
    }
    Try that

  4. #4
    Registered User asbo60's Avatar
    Join Date
    Jan 2006
    Posts
    38
    Thanks that worked perfectly.
    Come give my Website a visit and try my new program, all you gamers will love it!
    www.AzA-Productions.com
    Click on applications and download Key Control!

    Also I have tons of extra space available so, if you have a project or application you want the world to see just give me an email at [email protected] and ill see what i can do for you.

    Asbo60

  5. #5
    Registered User asbo60's Avatar
    Join Date
    Jan 2006
    Posts
    38
    I having a problem with putting that into a windows program it comes up with an error when i try to put it into a static box.

    Error:

    error C2664: 'SetDlgItemTextA' : cannot convert parameter 3 from 'unsigned long' to 'const char *'
    Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
    Come give my Website a visit and try my new program, all you gamers will love it!
    www.AzA-Productions.com
    Click on applications and download Key Control!

    Also I have tons of extra space available so, if you have a project or application you want the world to see just give me an email at [email protected] and ill see what i can do for you.

    Asbo60

  6. #6
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Try taking it to the windows board then - I, at least, don't know much about windows programming - just started it yesterday.

  7. #7
    Registered User asbo60's Avatar
    Join Date
    Jan 2006
    Posts
    38
    k Ill Mave it to Windows
    Come give my Website a visit and try my new program, all you gamers will love it!
    www.AzA-Productions.com
    Click on applications and download Key Control!

    Also I have tons of extra space available so, if you have a project or application you want the world to see just give me an email at [email protected] and ill see what i can do for you.

    Asbo60

  8. #8
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    error C2664: 'SetDlgItemTextA' : cannot convert parameter 3 from 'unsigned long' to 'const char *'
    Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
    An integer is not a string and requires conversion first. Use, for example wsprintf, sprintf for c (wsprintf is a cut-down, winapi sprintf unicode compatible function) or std::ostringstream for c++:

    FAQ > How do I... (Level 1) > Convert an int to a string (char array) (C).

    FAQ > How do I... (Level 1) > Convert an int to a string (C++).
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  9. #9
    Registered User asbo60's Avatar
    Join Date
    Jan 2006
    Posts
    38
    Those tutorials are good but i have decided to make my program a console again...But i am having another problem, is there a way to make my program search the screen for a certain colour?
    Come give my Website a visit and try my new program, all you gamers will love it!
    www.AzA-Productions.com
    Click on applications and download Key Control!

    Also I have tons of extra space available so, if you have a project or application you want the world to see just give me an email at [email protected] and ill see what i can do for you.

    Asbo60

  10. #10
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    OK, I'm not going to do this one for you, but ...

    If you know the color (the COLORREF type in the snippet), and you know the resolution of your screen (1024, 768 or something), and you can get the Pixel Details (from the earlier program), all you have to do is do a nested for loop, and have an if statement saying if the received color is the one you have saved, do something with it.

    Just play around with the code I sent you earlier.

  11. #11
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    If you want to search the entire screen then I would sugest you capture the screen as a bitmap first it would be more efficient then lots of GetPixel calls.

  12. #12
    Registered User asbo60's Avatar
    Join Date
    Jan 2006
    Posts
    38
    k i will experiment for a little thanks
    Come give my Website a visit and try my new program, all you gamers will love it!
    www.AzA-Productions.com
    Click on applications and download Key Control!

    Also I have tons of extra space available so, if you have a project or application you want the world to see just give me an email at [email protected] and ill see what i can do for you.

    Asbo60

  13. #13
    Registered User asbo60's Avatar
    Join Date
    Jan 2006
    Posts
    38
    k i have done a little experiment and come up with this but it dosnt work. please take a look at it.

    Code:
    #include "stdafx.h"
    
    int main()
    {
    
    	HDC		hdcScrn;	// Handle on accessing screen parameters.
    	HDC		hdc;
    	hdcScrn	= CreateDC( "DISPLAY", 0, 0, 0 );
    	hdc	= CreateDC( "DISPLAY", 0, 0, 0 );
    
    	COLORREF Col;		// a Color type
    	COLORREF Find;
    
    	POINT Pos1, Pos2;	// cursor positions
    
    
    	for (;;)
    	{
    		int x;
    		int y;
    		x++;
    		y++;
    		Find = GetPixel( hdc, x, y );	// sets the color variable to the cursor position.
    		if (Find == 1976248)
    		{
    			cout<<"Found it";
    			Sleep(5000);
    		}
    	}
    
    	while ( true )
    	{
    		GetCursorPos( &Pos1 );	// get cursor position
    
    		if ( (Pos1.x != Pos2.x) ||
    			 (Pos1.y != Pos2.y) )	// sees if the cursor has moved
    		{
    			GetCursorPos( &Pos2 );
    
    			Col = GetPixel( hdcScrn, Pos2.x, Pos2.y );	// sets the color variable to the cursor position. 
    			
    			cout<<"       \rThe color of Position ("<< Pos2.x << ',' << Pos2.y << "), is " << Col << "\t\t";
    		}
    	}
    
    
    
    	DeleteDC( hdcScrn );	// deletes the handle
    
    	return 0;
    }
    Come give my Website a visit and try my new program, all you gamers will love it!
    www.AzA-Productions.com
    Click on applications and download Key Control!

    Also I have tons of extra space available so, if you have a project or application you want the world to see just give me an email at [email protected] and ill see what i can do for you.

    Asbo60

  14. #14
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>but it dosnt work<<

    This is vague - help us to help you by describing explicitly what you think the problem is, including any compiler errors or warnings you may get.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  15. #15
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Code:
    for (;;)
    	{
    		int x;
    		int y;
    		x++;
    		y++;
    What this is doing is searching in a diagonal line from top left to bottom right or rather it would if you'd initialized the variables to zero. And it looks like an infinate loop.

    If you want to do it like that with GetPixel then you would need to do something like this
    Code:
    for (int x=0;x<SCREENWIDTH;x++)
    {
       for(int y=0;y<SCREENHEIGHT;y++)
       {
        ...
       }
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Just wondering.
    By Aliaks in forum C++ Programming
    Replies: 5
    Last Post: 06-12-2009, 09:48 PM
  2. wondering about people here
    By moemen ahmed in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 07-08-2002, 09:33 PM
  3. wondering
    By xlordt in forum A Brief History of Cprogramming.com
    Replies: 35
    Last Post: 03-01-2002, 07:05 AM