[英]How to suppress global mouse click events from windows?
I am developing a windows based application in which i want that whenever my application get started it should disable mouse click events outside the my application window form. 我正在开发一个基于Windows的应用程序,在该应用程序中,我希望每当我的应用程序启动时,它都应在我的应用程序窗口窗体之外禁用鼠标单击事件。
Can anyone please tell me, how can i achieve that? 谁能告诉我,我该如何实现?
Thanks in advance. 提前致谢。
Edit : 编辑:
Catching the mouse click event within the form and suppressing the click action is easy, for that we just use this : 在表单中捕获鼠标单击事件并抑制单击动作很容易,因为我们只使用以下命令:
protected override void WndProc(ref Message m)
{
if (m.Msg == (int)MouseMessages.WM_LBUTTONDOWN || m.Msg == (int)MouseMessages.WM_LBUTTONUP)
MessageBox.Show("Click event caught!"); //return; --for suppress the click event action.
else
base.WndProc(ref m);
}
but how to catch the mouse click event outside of the my app form? 但是如何在我的应用程序表单之外捕获鼠标单击事件?
This way it can be done. 这样就可以做到。 It uses the win API function BlockInput .
它使用win API函数BlockInput 。
NOTE: CTRL + ALT + DELETE enables the input again. 注意:CTRL + ALT + DELETE再次启用输入。 But other mouse and keyboard input is blocked.
但是其他鼠标和键盘输入被阻止。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern void BlockInput([In, MarshalAs(UnmanagedType.Bool)]bool fBlockIt);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.Show();
//Blocks the input
BlockInput(true);
System.Threading.Thread.Sleep(5000);
//Unblocks the input
BlockInput(false);
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.