如何燮从Windows preSS全球鼠标点击事件?鼠标点击、事件、全球、Windows

由网友(↘拍拍啦何首乌Ψ)分享简介:我正在开发一个基于Windows的应用程序,我想,只要我的应用程序上手应该禁用我的应用程序窗口的形式外鼠标点击事件。 谁能告诉我,我怎么能做到这一点? 在此先感谢。I am developing a windows based application in which i want that whenever m...

   我正在开发一个基于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. Can anyone please tell me, how can i achieve that? Thanks in advance.

编辑: 的形式和SUP pressing点击动作中捕捉鼠标点击事件是容易的,我们只需使用这样的:

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?

推荐答案

这种方式是可以做到的。它使用了胜利API函数 BlockInput 。

This way it can be done. It uses the win API function BlockInput.

注:按CTRL + ALT + DELETE重新启用输入。但是其他的鼠标和键盘输入被阻止。

NOTE: CTRL + ALT + DELETE enables the input again. 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); 
        }
    }
}
阅读全文

相关推荐

最新文章