私は、キーボード フックを含む c++ win32 プログラムに取り組んでいます。アプリケーションは、ユーザー インターフェイスがまったくない win32 プロジェクトです。フックが機能しなくなったり、大量のシステム リソースを使い果たしたりすることなく、アプリケーションが閉じないようにする必要があります。以前はメッセージ ボックスを使用していましたが、アプリケーションを完全に非表示にする必要があります。
どんな助けでも大歓迎です!
ご不明な点がございましたら、お気軽にお問い合わせください。
I think what you need is message only window
(MSDN says) A message-only window enables you to send and receive messages. It is not visible, has no z-order, cannot be enumerated, and does not receive broadcast messages. The window simply dispatches messages.
窓は本当に必要ですか?MSDNのLowLevelKeyboardProc ページでは、単純なメッセージ ループを使用することを推奨しています。フック呼び出しの後にこのスニペットを挿入するだけです。
// message loop to keep the keyboard hook running
MSG msg;
while(GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
より良い方法は、回り続けるループを追加することです。
bool shouldExit = false;
do
{
//some code to handle events
shouldExit = handleEvents();
//sleep for a small bit so we dont take up 100% cpu
sleep(500);
}
while (!shouldExit);