我正在尝试捕捉屏幕保护程序事件。这是我的代码:
#include "stdafx.h"
#include <iostream>
#include "stdio.h"
#include <Windows.h>
#include <strsafe.h>
HHOOK _hook;
LRESULT CALLBACK HookCallback(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode >= 0)
{
LPMSG msg = (LPMSG)lParam;
if(msg->message == WM_SYSCOMMAND)
{
if (msg->wParam == SC_SCREENSAVE)
{
std::cout<<"SC_SCREENSAVE\n";
}
}
}
return CallNextHookEx(_hook, nCode, wParam, lParam);
}
void SetHook()
{
HINSTANCE hinstDLL = LoadLibrary(L"user32.dll");
if (!(_hook = SetWindowsHookEx(WH_GETMESSAGE,HookCallback,hinstDLL,0)))
{
std::cout<<"Failed to install hook!\n";
}
}
void ReleaseHook()
{
UnhookWindowsHookEx(_hook);
}
int _tmain(int argc, _TCHAR* argv[])
{
SetHook();
// Don't mind this, it is a meaningless loop to keep a console application running.
// I used this to test the keyboard hook functionality. If you want to test it, keep it in ;)
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
}
ReleaseHook();
return 0;
}
注册成功。但我没有 catch 这个事件。甚至没有进入回调函数。我做错了什么?
最佳答案
您是否正在尝试创建屏幕保护程序或程序来截取桌面?如果您正在制作屏幕保护程序,请遵循这些。
屏幕保护程序是具有 .scr
扩展名的普通程序。屏幕保护程序应接受以下命令行参数。
- \S - Run in the full-screen mode
- \P - Run in the preview dialog box
- \C - Show the configuration dialog
但是 \P
开关有点不同。它后面是一个冒号和系统对话框的窗口句柄。例如,它可以是 /P:1234567890
关于c++ - 无法捕获屏幕保护程序事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16386116/