我正在尝试捕捉屏幕保护程序事件。这是我的代码:
#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;
}
注册成功。但我没有抓住这个事件。甚至没有进入回调函数。我做错了什么?
答案 0 :(得分:-1)
您是否正在尝试创建屏幕保护程序或程序来截取桌面?如果您正在制作屏幕保护程序,请按照以下步骤进行操作。
屏幕保护程序是具有.scr
扩展名的普通程序。屏幕保护程序应接受以下命令行参数。
- \ S - 以全屏模式运行
- \ P - 在预览对话框中运行
- \ C - 显示配置对话框
然而\P
开关有点不同。接下来是系统对话框的冒号和窗口句柄。例如,它可以是/P:1234567890