Screen-saver application (Beginner)

Having trouble with windows API: I am attempting to write a program that will do as follows:

Basic:
Detect inactivity on any physical monitor
EDIT: (Clarification) example: Monitor 2 has had the same image for the past 15/30/60 minutes even though monitor 1 is being used.
If inactive switch to screen-saver on that monitor alone
EDIT: (Clarification) whilst keeping the other monitors active and allowing mouse and keyboard movements
Wait until that monitor is reactivated and switch screen-saver off.

Expanded:
Get resolution and work area of each monitor
Poll the colour of nine pixels on each monitor at X individuals
Top, left of work area
Top, right of work area
Bottom, left of work area
Bottom, right of work area
Top/2, left/2 of work area
Top/2, (left/2)-(left/6) of work area
Top/2, (left/2)+(left/6) of work area
(Top/2)-(left/6), left/2 of work area
(Top/2)+(left/6), left/2 of work area

All this information to be stored then checked against the list
(If any pixels hex value has changed replace the first of the list for that monitor)
(If all pixels hex values are the same for X places run screen-saver on display area for that monitor)
screen saver runs on display area of inactive monitor until mouse intersects display area (Possibly also if the pixels notice any change, but this would require constant polling of the pixels and a change to how the list would work)

So far:

All I have is the class I made, but I get very confused with how to do anymore. Use as whether to have a parent or friend class, and whether any of these classes need to see the device handle etc. Whether to have the parent / friend just be an array with the functions determining the X, Y for hexStore. Also I need to be using pointers ideally, but I don't want to confuse myself with them just yet. Should it pass on a reference to a RECT and would that contain the monitor it came from as well, or is that something else that needs to be passed? Anyway confused ramble over...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// Class to store individual X, Y and hex reference
class hexStore /*ERROR: return type may not be specified on constructor*/
	
// Decleration of hexStore
{
    public:
		// Constructor and deconstructor definition
        hexStore(int positionX, int positionY, int r, int g, int b);
		~hexStore();

		// Getters
		int GetX() const;
		int GetY() const;
		unsigned long GetHex() const;

		// Setters
		void SetX(int positionX);
		void SetY(int positionY);
		void SetHex(int r, int g, int b);

		// Functions
		static unsigned long createHex(int r, int g, int b);

	// Member Variables
    private:
	    int x;
	    int y;
	    unsigned long hex;
}

// Constructor of hexStore
hexStore::hexStore(int positionX, int positionY, int r, int g, int b)
{
	x = positionX;
	y = positionY;
	hex = createHex(r, g, b);
}

// Destructor of hexStore
hexStore::~hexStore()
{
	delete(); /*ERROR: expected an expression*/
}

// function createHex to turn RGB value to Hex value
unsigned long createHex(int r, int g, int b){
	return (((r & 0xff) << 16) + ((g & 0xff) << 8) + (b & 0xff));
}

// Gets X value
int hexStore::GetX() const
{
	return x;
}

// Gets Y value
int hexStore::GetY() const
{
	return y;
}

// Gets hex value
unsigned long hexStore::GetHex() const
{
	return hex;
}

// Sets X value
void hexStore::SetX(int positionX)
{
	x = positionX;
}

// Sets Y value
void hexStore::SetY(int positionY)
{
	y = positionY;
}

// Sets hex value
void hexStore::SetHex(int r, int g, int b)
{
	hex = hexStore::createHex(r, g, b);
}
Last edited on
I was thinking along the lines of this for the friendship class, as you can see it is far from finished because I got so confused with how to carry on.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Friendship to hexStore
class hexStore

// Array and group of hexStores
class hexStoreArray(RECT workArea, int r, int g, int b)
{
    public:
        hexStoreArray(int resolutionX, int resolutionY, int r, int g, int b);
        ~hexStoreArray();

    private:
        int x, y, red, green, blue;
        hexStore pixalArray[8];   

}

hexStoreArray::hexStoreArray()
{
    pixalArray[0] = hexStore topLeft(workArea.top, workArea.left, int red, int green, int blue);
    pixalArray[1] = hexStore topLeft(workArea.top, workArea.right, int red, int green, int blue);
    pixalArray[2] = hexStore topLeft(workArea.bottom, workArea.left, int red, int green, int blue);
    pixalArray[3] = hexStore topLeft(workArea.bottom, workArea.right, int red, int green, int blue);
    pixalArray[4] = hexStore topLeft((workArea.top)*.5, (workArea.left)*.5, int red, int green, int blue);
    pixalArray[5] = hexStore topLeft((workArea.top)*.5, (workArea.left)*.3, int red, int green, int blue);
    pixalArray[6] = hexStore topLeft((workArea.top)*.5, (workArea.left)*.6, int red, int green, int blue);
    pixalArray[7] = hexStore topLeft((workArea.top)*.3, (workArea.left)*.5, int red, int green, int blue);
    pixalArray[8] = hexStore topLeft((workArea.top)*.6, (workArea.left)*.5, int red, int green, int blue);
    
}


EDIT: just realised that the multiplications are completely wrong but I am sure you get the idea of what I was trying to accomplish.
Last edited on
A screen saver is just a regular windows EXE renamed to .scr extension. You don't need to derecr when the computer is idle as this is managed automatically by windows.

Read here for a guide to write your own screen saver application:
http://www.codeproject.com/Articles/1551/Creating-a-screen-saver
Yes, but this is a screen-saver on a single monitor or display whilst the computer is active. For example watching a movie on one screen and not having to physical turn the other monitor off, or a game, etc. As far as I know there is no applications that currently do this so I thought I would help teach myself and make one. Also there are applications such as Skype, VLC, etc. that will stop the screen saver turning off even if the computer is idle.

"A screen saver is just a plain Win32 application that will be launched automatically when the mouse and keyboard have been idle for a specified period of time. "

Hence my application designed to look at the activity at each monitor individually.
Last edited on
Registered users can post here. Sign in or register to post.