使用前台应用程序捕获屏幕保护程序事件

时间:2013-05-09 07:08:37

标签: c++ windows windows-screensaver

我正在尝试在屏幕保护程序关闭时捕获事件。 实际上,就目前而言,我没有得到屏幕保护程序的任何事件(也不是在它启动时)。 当应用程序处于焦点(前景)时,我正在测试它。

这是我的代码:

#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;
}

有什么建议吗? 谢谢!

0 个答案:

没有答案