Program

Well i have been working on a program for an hour or so, what it does is when i hit the escape key, it starts up the screen saver.. basically right now i have the screensaver in the same Directory, named: scrnsave.scr. i have the program working. here is the code:
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

#include<windows.h>
#include<iostream>
#include <conio.h>

void hide(){
     HWND stealth; //Code to Hide
   AllocConsole();
   stealth=FindWindowA("ConsoleWindowClass",NULL);
   ShowWindow(stealth,0);
     }
 
int main(){
    //hide();
char key;

while (1) {
if (kbhit()) {
key = getch();
if (key == 27){ ShellExecute(NULL, "open", "scrnsave.scr",
                NULL, NULL, SW_SHOWNORMAL);
 
}
}
}
 return 0;
}


i am not a bad programmer i just need to know how i can get it to run in front of the other programs. i know how to hide it but if its running and i have firefox open and hit esc it doesn't start the screen saver.. and i want it to run in front of the other programs. if anyone can help it would be appreciated.

oh BTW it was compiled in Dev-C++
Last edited on
It looks like you've written a Console App rather that a Windows App.

A Console App display a text windows, and Windows App won't. I'm not familiar with Dev-C++, so I help any further.

In Visual Studio you define _WINDOWS or _CONSOLE. I presume that causes the environment to link against different r/t libraries.
The code and method are wrong.
you can ask on news://comp.os.ms-windows.programmer.win32
for the right mehod (KBS)
Sorry i put it in the wrong section, but there is no console App location so i figured i am trying to run this in Windows so i would put it in this section.. and i still need help.. if someone wants to move the post they can.. i would just like to get the code to put the program to run so it doesn't have to be selected. and how is the Code and method wrong.. works fine for me.
Last edited on
What you are trying to do won't work this way. Sorry.

Google around things like "msdn SetWindowsHookEx" and "msdn KeyboardProc". You will need to put the hook procedure in a DLL.

Make sure you screensave on a unique key sequence. Activating the screensaver with just an Esc key press is bound to interact badly. (Many other applications use the Escape key for valid reasons.)

To activate the user's current screensaver (the one he has selected from the Control Panel "Desktop Properties" applet), you should use the following code:
1
2
3
4
5
6
7
8
9
10
#include <windows.h>

bool ActivateScreenSaver()
  {
  BOOL b;
  if (SystemParametersInfo( SPI_GETSCREENSAVEACTIVE, 0, (PVOID)&b, 0 )) return false;
  if (!b) return false;
  PostMessage( GetDesktopWindow(), WM_SYSCOMMAND, SC_SCREENSAVE, 0 );
  return true;
  }
The result is whether or not the screensaver was successfully activated (except for very rare and unlikely failures).

Long ago I wrote a utility (that I still use) called Mr. Sandman that activates the screensaver. (It doesn't use hooks though -- it was purposefully designed to be a 'click-to-activate' function rather than the more common 'move-mouse-to-screen-corner-to-activate' hook type.) PM me if you want the (Delphi) code.

Hope this helps.
Topic archived. No new replies allowed.