gpt4 book ai didi

c - 如何在 Windows 文本编辑器上阻止打印功能(CTRL + P)?

转载 作者:太空宇宙 更新时间:2023-11-03 23:37:10 24 4
gpt4 key购买 nike

我想在 Windows 平台上针对特定应用程序阻止打印功能 (CTRL + P)。我正在使用键盘钩子(Hook)来做。我能够检测到 CTRL + P 但我无法阻止它。在 CTRL + P 的情况下,我从 Hook 程序返回,但应用程序仍然收到此消息并处理打印。

LRESULT __declspec(dllexport)__stdcall  CALLBACK KeyboardProc(
int nCode,
WPARAM wParam,
LPARAM lParam)
{
FILE* f1;
static WPARAM wPrevParam;

if (((DWORD)lParam & 0x40000000) && (HC_ACTION == nCode))
{
if ((wParam == VK_SPACE) || (wParam == VK_RETURN) || (wParam == VK_CONTROL) || (wParam >= 0x2f) && (wParam <= 0x100))
{
char ch;
f1 = fopen("d:\\report.txt", "a+");
if (wParam == VK_CONTROL)
{
if (wPrevParam == 0x50)// 0x50 = P
{
const char* text = "CTRL-P detected.";
fwrite(text, strlen(text), 1, f1);
fclose(f1);
wParam = 0;
lParam = 0;
return 1;
}

const char *text = "CTRL";
fwrite(text, strlen(text), 1, f1);
fprintf(f1, "%02X\n", (unsigned char)wParam);
}
else
{
wPrevParam = wParam;
}

fclose(f1);
}

}

LRESULT RetVal = CallNextHookEx(hkb, nCode, wParam, lParam);

return RetVal;

}

最佳答案

I want to block printing functionality(CTRL + P) on windows platform for specific applications. I am doing it using keyboard hook. I am able to detect CTRL + P but I am not able to stop it.

这会在 WH_KEYBOARD_LL Hook 中阻止 [Ctrl] + "P"... 但不会阻止通过 [File] [Print] 或其他方式打印当然... =>/p>

    LRESULT CALLBACK LowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
DWORD dwKey = 0;
if (HC_ACTION == nCode)
{
KBDLLHOOKSTRUCT *pkbdll = (KBDLLHOOKSTRUCT*)lParam;
dwKey = pkbdll->vkCode;
BOOL bCtlDown = GetKeyState(VK_CONTROL) < 0;
if (bCtlDown && dwKey == 'P')
{
Beep(6000, 10);
return 1;
}
}
return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam);
}

关于c - 如何在 Windows 文本编辑器上阻止打印功能(CTRL + P)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56966165/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com