Click here to Skip to main content
15,914,820 members
Home / Discussions / C#
   

C#

 
GeneralDocking Application to the System Pin
Nagendra Kamath K19-Mar-04 7:18
Nagendra Kamath K19-Mar-04 7:18 
GeneralRe: Docking Application to the System Pin
Heath Stewart19-Mar-04 8:11
protectorHeath Stewart19-Mar-04 8:11 
GeneralMasking Keyboard and Mouse Events Pin
Nagendra Kamath K19-Mar-04 7:02
Nagendra Kamath K19-Mar-04 7:02 
GeneralRe: Masking Keyboard and Mouse Events Pin
Judah Gabriel Himango19-Mar-04 7:30
sponsorJudah Gabriel Himango19-Mar-04 7:30 
GeneralRe: Masking Keyboard and Mouse Events Pin
Dave Kreskowiak19-Mar-04 7:30
mveDave Kreskowiak19-Mar-04 7:30 
GeneralRe: Masking Keyboard and Mouse Events Pin
Heath Stewart19-Mar-04 8:04
protectorHeath Stewart19-Mar-04 8:04 
GeneralRe: Masking Keyboard and Mouse Events Pin
Dave Kreskowiak19-Mar-04 9:25
mveDave Kreskowiak19-Mar-04 9:25 
GeneralRe: Masking Keyboard and Mouse Events Pin
Heath Stewart19-Mar-04 8:02
protectorHeath Stewart19-Mar-04 8:02 
A much easier way and more efficient way (without having to P/Invoke native APIs) is to simply add a IMessageFilter to pre-filter any messages sent to ONLY your application (as opposed to using a system-wide, low-level keyboard hook).
using System;
using System.Drawing;
using System.Windows.Forms;

public class Test : Form, IMessageFilter
{
  static void Main(string[] args)
  {
    Test t = new Test();
    Application.AddMessageFilter(t);
    Application.Run(t);
    Application.RemoveMessageFilter(t);
  }

  public Test()
  {
    TextBox tb = new TextBox();
    tb.Location = new Point(8, 8);
    this.Controls.Add(tb);

    tb = new TextBox();
    tb.Location = new Point(8, 30);
    this.Controls.Add(tb);
  }

  private const int WM_KEYDOWN = 0x0100;
  private const int WM_LBUTTONDOWN = 0x0201;
  private const int WM_RBUTTONDOWN = 0x0204;
  private const int WM_XBUTTONDOWN = 0x020b;

  public bool PreFilterMessage(ref Message m)
  {
    if (m.Msg == WM_KEYDOWN ||
      m.Msg == WM_LBUTTONDOWN ||
      m.Msg == WM_RBUTTONDOWN ||
      m.Msg == WM_XBUTTONDOWN)
      return true;

    return false;
  }
}
Pay attention to the PreFilterMessage method, which is the implementation for IMessageFilter.PreFilterMessage. You could filter other application messages this way as well. Anything that goes through the application message pump can be filtered.

 

Microsoft MVP, Visual C#
My Articles
GeneralRe: Masking Keyboard and Mouse Events Pin
m_ramses19-Mar-04 21:16
m_ramses19-Mar-04 21:16 
GeneralRe: Masking Keyboard and Mouse Events Pin
Nick Parker20-Mar-04 6:16
protectorNick Parker20-Mar-04 6:16 
Generalbitmap with scroll Pin
cmarmr19-Mar-04 6:42
cmarmr19-Mar-04 6:42 
GeneralRe: bitmap with scroll Pin
Judah Gabriel Himango19-Mar-04 6:47
sponsorJudah Gabriel Himango19-Mar-04 6:47 
GeneralRe: bitmap with scroll Pin
Heath Stewart19-Mar-04 7:52
protectorHeath Stewart19-Mar-04 7:52 
GeneralRe: bitmap with scroll Pin
Syed Abdul Khader19-Mar-04 22:10
Syed Abdul Khader19-Mar-04 22:10 
GeneralApplication Updater on Apache Pin
bisquic19-Mar-04 6:15
bisquic19-Mar-04 6:15 
GeneralRe: Application Updater on Apache Pin
Heath Stewart19-Mar-04 6:25
protectorHeath Stewart19-Mar-04 6:25 
GeneralRe: Application Updater on Apache Pin
bisquic22-Mar-04 3:03
bisquic22-Mar-04 3:03 
Generaladd reference Pin
yyf19-Mar-04 6:08
yyf19-Mar-04 6:08 
GeneralRe: add reference Pin
Heath Stewart19-Mar-04 6:13
protectorHeath Stewart19-Mar-04 6:13 
GeneralFile segmentation Pin
profoundwhispers19-Mar-04 5:47
profoundwhispers19-Mar-04 5:47 
GeneralRe: File segmentation Pin
Heath Stewart19-Mar-04 6:09
protectorHeath Stewart19-Mar-04 6:09 
GeneralSomething unclear to me about threads... Pin
profoundwhispers19-Mar-04 5:43
profoundwhispers19-Mar-04 5:43 
GeneralRe: Something unclear to me about threads... Pin
Heath Stewart19-Mar-04 6:01
protectorHeath Stewart19-Mar-04 6:01 
GeneralStrong/Shared assemblies Pin
Kant19-Mar-04 4:57
Kant19-Mar-04 4:57 
GeneralRe: Strong/Shared assemblies Pin
Heath Stewart19-Mar-04 5:59
protectorHeath Stewart19-Mar-04 5:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.