![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2007
Posts: 2
Rep Power: 0
![]() |
How to do this...
Hi, I want to write a program that reads a pixel on the screen and then does A if the pixel is of certain color and B if it's not. So the change of the color of the pixel (x,y) on my screen can trigger things. Can this be done easily? I'm a newbie programmer so I don't really have any idea of where to start. I just really need a program that can do this. Also if you know that it can be done more easily with some other language than C++ then feel free to tell me because I can always learn the language enough to write the effect-part.
|
|
|
|
|
|
#2 |
|
Professional Programmer
|
Re: How to do this...
This is in C# but you should be able to use the information contained in the article to write a similar program in C++
http://sharpinsights.wordpress.com/2...r-under-mouse/
__________________
JG-Webdesign |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Nov 2007
Location: Waterloo, ON
Posts: 20
Rep Power: 0
![]() |
Re: How to do this...
I recently did this in C#, I had to use a pinvoke to use some windows methods.
The only difficulty's i ran into was to read the pixels that were 'outside' of my current program. I cant remember exactly how I did it, ( i think there was a default handle to use ). I will post my code tonight when I have access to it. |
|
|
|
|
|
#4 |
|
Professional Programmer
|
Re: How to do this...
Were you using the DC of the application window?? Try getting the DC of the desktop window instead
![]()
__________________
JG-Webdesign |
|
|
|
|
|
#5 |
|
Professional Programmer
|
Re: How to do this...
__________________
http://www.kevinherron.com/ |
|
|
|
|
|
#6 | |
|
Newbie
Join Date: Nov 2007
Location: Waterloo, ON
Posts: 20
Rep Power: 0
![]() |
Re: How to do this...
Quote:
It's slightly more complicated to do it in c++/c# because of the window handle stuff. |
|
|
|
|
|
|
#7 |
|
Newbie
Join Date: Nov 2007
Location: Waterloo, ON
Posts: 20
Rep Power: 0
![]() |
Re: How to do this...
Here it is in c#, should be easy to convert it to c++.
using System;
using System.Drawing;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
class ScreenReader
{
#region Imported Functions
[DllImport("gdi32.dll")]
public static extern IntPtr CreateDC(string strDriver, string strDevice,
string strOutput, IntPtr pData);
[DllImport("gdi32.dll")]
public static extern bool DeleteDC(IntPtr hdc);
[DllImport("gdi32.dll")]
public static extern int GetPixel(IntPtr hdc, int x, int y);
#endregion
public static Color getColorAt(int x, int y)
{
IntPtr hdcScreen = CreateDC("Display", null, null, IntPtr.Zero);
Color clr = ColorTranslator.FromWin32(GetPixel(hdcScreen, x, y));
DeleteDC(hdcScreen);
return clr;
}
} |
|
|
|
|
|
#8 |
|
Newbie
Join Date: Nov 2007
Posts: 2
Rep Power: 0
![]() |
Re: How to do this...
Thank you, everyone. Great help
I'm gonna try some of this later today or tomorrow, I'm sure I'll get something done. |
|
|
|
|
|
#9 |
|
Professional Programmer
|
Re: How to do this...
Is it a good idea to keep keep on recreating hdcScreen each time you call getColorAt ?
__________________
JG-Webdesign |
|
|
|
|
|
#10 |
|
Newbie
Join Date: Nov 2007
Location: Waterloo, ON
Posts: 20
Rep Power: 0
![]() |
Re: How to do this...
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|