禁用鼠标和键盘输入 [英] Disable mouse and keyboard input

查看:201
本文介绍了禁用鼠标和键盘输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何禁用对应用程序的鼠标和键盘输入?我希望鼠标和键盘在指针位于应用程序区域之外时起作用.

How do I disable mouse and keyboard input to an application? I want the mouse and keyboard to work when the pointer is outside the application area.

推荐答案

您可以通过调用方法CWnd::EnableWindow(BOOL bEnable)禁用窗口,方法是您的窗口将不接受任何用户输入,包括鼠标和键盘.
这种方法是最简单的方法,但是它会使您的窗口无法处理任何类型的用户交互:您将无法将窗口最小化到任务栏,无法通过拖动其标题来移动窗口酒吧,等等.
如果您的窗口是基于对话框的,并且您的目标是禁用窗口客户区中的所有控件,则最佳解决方案是将所有控件放在子窗口中(即声明为WS_CHILD且没有标题栏或边框)然后将该子窗口放置在主窗口的客户区域中,然后启用/禁用该子窗口.这样,用户将无法与窗口上的控件进行交互,但是他将能够在屏幕上移动窗口,最小化和最大化窗口,等等.
You can disable the window, by calling the method CWnd::EnableWindow(BOOL bEnable), this way your window will not accept any user input, both mouse and keyboard.
This approach is the easiest one, but it make your window not able to process any kind of user interaction: you will be not able to minimize the window to the taskbar, to move the window by dragging its title bar, and so on.
If your window is dialog based and your target is to disable all the controls on the client area of the window, the best solution is to place all the controls on a child window (i.e. declared as WS_CHILD and without title bar nor border) then place that child window on the client area of your main window and then enable/disable the child window. This way the user will be not able to interact to the controls on the window, but he will be able to move the window on screen, minimize and maximize it, and so on.


上面的陈述似乎相互冲突.如果禁用鼠标和键盘,则无法在内部或外部运行.请尝试重新输入您的问题.
The statements above seem to conflict with each other. If you disable the mouse and keyboard it cannot work inside or outside. Please try and reword your question.


最简单的方法是建立一个以主窗口为父窗口的模态对话框.这将自动禁用主窗口.不过,如何将自己画在这个角落之外...
我在开玩笑...只是自己禁用主窗口,而且我想您有一种可以在需要时重新启用它的机制.
The easiest way is putting up a modal dialog with the main window as it''s parent. This will automatically disable the main window. How you will paint yourself out of this corner, though...
I''m kidding... just disable the main window yourself, and I suppose you have a mechanism for re-enabling it when needed.


这篇关于禁用鼠标和键盘输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆