Intercepting a mouse click from another program

I am trying to capture mouse clicks from another program. Im making a plugin for the program that imposes a transparent form on the program and displays additional information. When I click on the transparent part of the form, I can click on things in the main program. I do not want this to happen (at least not every time - there are some parts where you are allowed to click and some parts where you arent, but this is not a problem).

The way I am doing this now is to use WH_MOUSE_LL , it works fine, and I can hold the mouse click from accessing the program by returning a non-zero value ( http://msdn.microsoft.com/en-gb/library/windows/desktop /ms644988(v=vs.85).aspx ).

The problem is that this makes my main delay in the program, I do not need to receive notifications about all mouse movements, I only want to get a notification if the user really clicked something. Is there a way to limit WH_MOUSE_LL so that it only works when the mouse is clicked? (The disadvantage is not caused by calculations in the MouseHookProc method - it does nothing but call: CallNextHookEx(hHook, nCode, wParam, lParam) .)

Ive tried to fix this using a global hook ( http://www.codeproject.com/Articles/18638/Using-Window-Messages-to-Implement-Global-System-H ) that intercepts the WM_MOUSEACTIVATE message. The idea was to connect WH_MOUSE_LL only when I received the WM_MOUSEACTIVATE notification. Unfortunately, WH_MOUSE_LL notification is sent before WM_MOUSEACTIVATE , so this does not work.

EDIT:

@Nanda uses the proc code:

 public int MouseHookProc(int nCode, IntPtr wParam, IntPtr lParam) { return WindowUtility.CallNextHookEx(hHook, nCode, wParam, lParam); } 

As you can see, Im doesn't work very much with him, but he is already behind ...

@Cody Gray Ive did a very small test for the message processing form:

 public class Form1 : Form { private TrackBar m_Trackbar; static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } public Form1() { m_Trackbar = new System.Windows.Forms.TrackBar(); m_Trackbar.LargeChange = 1; m_Trackbar.Location = new System.Drawing.Point(5, 10); m_Trackbar.Maximum = 100; m_Trackbar.Size = new System.Drawing.Size(280, 40); m_Trackbar.Value = 100; this.Controls.Add(m_Trackbar); m_Trackbar.Scroll += new System.EventHandler(this.m_TrackbarScroll); } private void m_TrackbarScroll(object sender, System.EventArgs e) { this.Opacity = ((Convert.ToDouble(m_Trackbar.Value)) / 100); } protected override void WndProc(ref Message m) { switch (m.Msg) { case 0x201: //WM_LBUTTONDOWN Console.WriteLine("MouseButton Down!"); //I could copy the Message over to the MainProgram with this right? //SendMessage(MainProgramHwnd, m.Msg, m.WParam, m.LParam); //This will also only work on an opacity higher than 0. break; } base.WndProc(ref m); } } 

When you said: "return that it is transparent and let it be directed to the window below it?" Can I do this using SendMessage and basically copy the message I receive in my WndProc method?

To complicate the situation, I also used this form http://www.codeproject.com/Articles/1822/Per-Pixel-Alpha-Blend-in-C . As far as I understand, this allows me to draw bitmap images in a form that is Anti Aliasing in the background. With this form, there seems to be no way to set opacity, as it is just transparent all the time. Is there a better way to draw raster images in a form?

+8
c # winapi hook windows-messages
source share
1 answer

You can look in Easyhook ( http://easyhook.codeplex.com/ ), which allows you to connect Windows API calls from a single process, and not for all processes.

+1
source share

All Articles