0

I'm trying to catch the event when screen saver is turned off. Actually, for now, I'm not getting any event of the screen saver (also not when it is launched). I'm testing it when the application is in focus (foreground).

This is my code:

#include "stdafx.h"
#include "windows.h"


LRESULT CALLBACK wndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

static void RegisterWindowClasses() {

    WNDCLASS wndClass;

    memset(&wndClass, 0, sizeof(WNDCLASS));
    wndClass.style = CS_HREDRAW | CS_VREDRAW;
    wndClass.hInstance = NULL;
    wndClass.lpszClassName = _T("Plugin-Video");
    wndClass.hbrBackground = (HBRUSH) GetStockObject (DKGRAY_BRUSH);
    wndClass.lpfnWndProc = wndProc;
    RegisterClass(&wndClass);
}

LRESULT CALLBACK wndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    int wmId, wmEvent;
    PAINTSTRUCT ps;
    HDC hdc;

    switch (msg)
    {
    case WM_SYSCOMMAND:
        {
            switch (LOWORD(wParam))
            {
            case SC_SCREENSAVE:
                {
                    FILE *fl = fopen("this_is_a_event_test.txt","a");
                    fputs("SC_SCREENSAVE\n",fl);
                    fclose(fl);
                }
                break;
            case SC_MONITORPOWER:
                {
                    FILE *fl = fopen("this_is_a_event_test.txt","a");
                    fputs("SC_MONITORPOWER\n",fl);
                    fclose(fl);
                }
                break;
            default:
                {
                }
            }
        }
        break;
    }
    return DefWindowProc(hWnd, msg, wParam, lParam);
}



int _tmain(int argc, _TCHAR* argv[])
{
    RegisterWindowClasses();
    while(1){}
    return 0;
}

Any suggestions? Thanks!

Sanich
  • 1,739
  • 6
  • 25
  • 43
  • I can't see any place in `main()` where you actually create a window. – Roger Rowland May 09 '13 at 08:17
  • @Roger - Right - it was a typo. I've added the registration. – Sanich May 09 '13 at 08:30
  • Ok, but that doesn't create a window. You need `CreateWindow`, `ShowWindow`, `UpdateWindow` etc. and a message loop somewhere. I think you need to brush up on some Windows basics :-( For example, see here - http://www.winprog.org/tutorial/simple_window.html – Roger Rowland May 09 '13 at 08:33

0 Answers0