我已经为我的应用程序实现了截屏功能,当使用hook时出现警告或错误消息时会截取屏幕截图。
HHOOK hhokCBTProc = 0;
LRESULT CALLBACK pfnCBTMsgBoxHook(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode == HCBT_DESTROYWND)
{
TakeScreenshot(); // function call for screenshot.
}
return (CallNextHookEx(hhokCBTProc, nCode, wParam, lParam));
}
int SVAfxMessageBox(int textCode, UINT nType, UINT nIDHelp)
{
if (IsScreenshotAllowed)
{
// set hook to center the message box that follows))
hhokCBTProc = SetWindowsHookEx(WH_CBT,
pfnCBTMsgBoxHook,
0, GetCurrentThreadId());
}
nType = CheckIfLangIsRTL() ? (MB_RTLREADING | MB_RIGHT | nType) : nType;
int res = AfxMessageBox(textCode, nType, nIDHelp);
if (IsScreenshotAllowed)
{
// remove the hook
UnhookWindowsHookEx(hhokCBTProc);
}
return res;
}
这里的问题是在执行实际操作之前不止一次执行并且拍摄多个屏幕截图(甚至在出现警告消息之前)。我是否需要在此条件“nCode == HCBT_DESTROYWND”中添加更多内容,以便仅截取一次屏幕截图?