opps lol didnt see that thanks ill try that
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
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
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
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.
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
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
And your question is...?
CProgramming FAQ
Caution: this person may be a carrier of the misinformation virus.
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.
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
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.
Originally Posted by asbo60Taking some of these points into consideration:
- 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.
orCode://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 }I think for future reference it would also be useful for you to read this.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 }
CProgramming FAQ
Caution: this person may be a carrier of the misinformation virus.