Thread: Just wondering

  1. #16
    Registered User asbo60's Avatar
    Join Date
    Jan 2006
    Posts
    38
    opps lol didnt see that thanks ill try that
    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. #17
    Registered User asbo60's Avatar
    Join Date
    Jan 2006
    Posts
    38
    I tried some more stuff and it still didnt do anything.... heres the code i came up with.

    Code:
    	for (int x=0;x<1152;x++)
    	{
    		for(int y=0;y<864;y++)
    		{
    		Find = GetPixel( hdc, x, y );	// sets the color variable to the cursor position.
    		if (Find == 16777215)
    		{
    			cout<<"Found it";
    			Sleep(5000);
    		}
    		}
    	}
    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

  3. #18
    Registered User asbo60's Avatar
    Join Date
    Jan 2006
    Posts
    38
    i tryed making a giant block of code that would row by row check the screen but in the end all it did was freeze my comp and i would like any sugestions on how to do this?
    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

  4. #19
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Keep in mind that Windows desktop stores colors in a very odd fashion.

    Normally you have this in 32 bit color.

    R G B

    However, Windows does not store it this way. It stores it the way the hardware wants:

    B G R


    So instead of this standard XRGB format:

    #define XRGB(x,r,g,b) (DWORD)( (x<<24) + (r<<16) + (g<<8) + (b) )

    You get this:

    #define XRGB(x,r,g,b) (DWORD)( ((x<<24) + (b<<16) + (g<<8) + (r) )

    So testing for transparent colors become interesting.
    Last edited by VirtualAce; 05-26-2006 at 11:57 PM.

  5. #20
    Registered User asbo60's Avatar
    Join Date
    Jan 2006
    Posts
    38
    Where did that come from...i mean that was a big jump, i have no clue wat your talking about sorry
    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. #21
    Registered User asbo60's Avatar
    Join Date
    Jan 2006
    Posts
    38
    ive made some updates to that code i tryed befor so now at least it will say found it when i move the cruser over the colour heres the code

    Code:
    #include "stdafx.h"
    
    int main()
    {
    	int w;
    
    	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<<"       \rThe color of Position ("<< Pos2.x << ',' << Pos2.y << "), is " << Col << "\t\t";
    
    			for (int x=0;x<1152;x++)
    			{
    				for(int y=0;y<864;y++)
    				{
    					if (Col == 22243)
    					{
    						w=1;						
    					}
    				}		
    			}
    			if ( w >= 1)
    			{
    				cout<<"found it";
    			}
    		}
    	}
    
    
    
    	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

  7. #22
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    And your question is...?
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  8. #23
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Well you can either use GetPixel() to get colors and then use GetR(), GetG() and GetB() to get the RGB values, or you can do it yourself.

    Inside of a loop, GetPixel followed by Get this or that is going to be slow.

  9. #24
    Registered User asbo60's Avatar
    Join Date
    Jan 2006
    Posts
    38
    o ok, and my question was is there any way to improve it
    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. #25
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Maybe. But one thing. I don't think your loop will ever exit. I know I gave you the code as an example, but that was just to show how one can get the color at a specific position in the screen. I would recommend getting rid of the while() loop in the code ... I think.

  11. #26
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Quote Originally Posted by asbo60
    o ok, and my question was is there any way to improve it
    • Give a brief description (comment) of what you intend the program to do. Given your original question this would seem to be to obtain the colour of a pixel at the current mouse position. However, from your code it seems you're trying to search the desktop for a specific colour...
    • Lose the ms-specific header (stdafx.h) - explicitly use what you need and that way your code will compile on other compilers, too.
    • Use std namespace qualifier explicitly, eg. std::cout
    • Give a means to escape from the infinite loop when the user presses, for example, the 'escape' key. see GetAsyncKeyState.
    • If you need to use the desktop dimensions get the user's actual desktop resolution, rather than hard-coding your own, personal values. see GetSystemMetrics.
    • Re-read and try to understand the suggestions already given to you by others in this thread. For example, the information provided by Bubba is very useful if you want to get specific red, green and blue data from the COLORREF values while Quantum1024's suggestion specifically addresses the issue of trying to match a colour with that of a screen pixel.
    Taking some of these points into consideration:
    Code:
    //Get and display colour of pixel at current mouse position
    
    #include <windows.h>
    #include <iostream>
    
    int main()
    {
    HDC hdcScrn = CreateDC( "DISPLAY", 0, 0, 0 ); //screen device context
    
    COLORREF Col=0;
    POINT pt={0};
    
    //enter infinite loop which user can break from by pressing 'escape' key
    while ((GetAsyncKeyState(VK_ESCAPE) & 0x8000)==false) 
      {
      GetCursorPos(&pt);
      Col=GetPixel(hdcScrn,pt.x,pt.y);
      
      std::cout<<"       \rThe color of Position ("<< pt.x << ',' << pt.y <<
                 "), is " << Col << "\t\t";
      }
      
    std::cout<<std::flush;
    
    DeleteDC(hdcScrn);  //free system resources
    }
    or
    Code:
    //search screen pixels for a known colour value
    #include <windows.h>
    #include <iostream>
    
    bool LookForMatch(const HDC hdcScrn,const COLORREF clr)
    {
    //get desktop dimensions - assume they don't change while program is running
    static const int SCREEN_WIDTH=GetSystemMetrics(SM_CXSCREEN);
    static const int SCREEN_HEIGHT=GetSystemMetrics(SM_CYSCREEN);
    
    int x,y;
    for (x=0;x<SCREEN_WIDTH;++x)
      {
      for (y=0;y<SCREEN_HEIGHT;++y)
        {
        if (GetPixel(hdcScrn,x,y)==clr)
          {
          std::cout<<"Match found at "<<x<<","<<y<<std::endl;
          return true;
          }
        }
      }
      
    std::cout<<"Match not found"<<std::endl;
    return false;
    }
    
    int main()
    {
    HDC hdcScrn = CreateDC( "DISPLAY", 0, 0, 0 ); //screen device context
    
    std::cout<<"Searching, please wait...\n";
    
    LookForMatch(hdcScrn,22243);
      
    std::cout<<"Done"<<std::endl;
    
    DeleteDC(hdcScrn);  //free system resources
    }
    I think for future reference it would also be useful for you to read this.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

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