By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,758 Members | 1,286 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,758 IT Pros & Developers. It's quick & easy.

Trapping Windows Messages from other applications

P: n/a
Okay I'm trying to write an application to monitor a running process. Right
now I have a front end which allows the user to pick the programs they want
to monitor. The interval between how often I information for this process,
things like CPU usage, peak memory, virtual memory, etc... All this I get
from System.Diagnostics.Process. I display this information in a listview and
things are working fine. The user can then select one of these processes
being monitored and "I'll display modules in a treeview to them.

Now the thing I want to also do is display windows messages in a listbox. So
for example say I'm monitoring a program called MyApp.exe. I want to select
this program and then go back to this program and contiue working in it.
Clicking command buttons, entering data, selecting menu options. But I want
all these message to be captured by this monitoring program in that listbox
so when I return to it I would see a windows message for
WM_MOUSEMOVE
WM_LBUTTONDOWN
WM_LBUTTONUP
WM_LBUTTONDBLCLK
WM_RBUTTONDOWN
WM_RBUTTONUP
WM_RBUTTONDBLCLK
WM_MBUTTONDOWN
WM_MBUTTONUP
WM_MBUTTONDBLCLK
etc...

I will also create another list of what messages I want to capture but first
I need to capture them and can't figure this part out.

--
Joe Pacelli
jo********@earthlink.net
Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,

For that you will have to P/invoke the win32 API, IIRC the function is
called SetWinEventHook, you will need either the hWnd of the main window or
the process ID of the target process.
Take a look at google groups you will find the answer there,

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Joe Pacelli" <Jo********@discussions.microsoft.com> wrote in message
news:16**********************************@microsof t.com...
Okay I'm trying to write an application to monitor a running process.
Right
now I have a front end which allows the user to pick the programs they
want
to monitor. The interval between how often I information for this process,
things like CPU usage, peak memory, virtual memory, etc... All this I get
from System.Diagnostics.Process. I display this information in a listview
and
things are working fine. The user can then select one of these processes
being monitored and "I'll display modules in a treeview to them.

Now the thing I want to also do is display windows messages in a listbox.
So
for example say I'm monitoring a program called MyApp.exe. I want to
select
this program and then go back to this program and contiue working in it.
Clicking command buttons, entering data, selecting menu options. But I
want
all these message to be captured by this monitoring program in that
listbox
so when I return to it I would see a windows message for
WM_MOUSEMOVE
WM_LBUTTONDOWN
WM_LBUTTONUP
WM_LBUTTONDBLCLK
WM_RBUTTONDOWN
WM_RBUTTONUP
WM_RBUTTONDBLCLK
WM_MBUTTONDOWN
WM_MBUTTONUP
WM_MBUTTONDBLCLK
etc...

I will also create another list of what messages I want to capture but
first
I need to capture them and can't figure this part out.

--
Joe Pacelli
jo********@earthlink.net

Nov 17 '05 #2

P: n/a
Joe,

This can be accomplished using the System.Windows.Forms.NativeWindow
class. See the following example.
using System;
using System.Windows.Forms;

namespace WindowsApplication
{
public class MyHookClass : NativeWindow
{
public MyHookClass(IntPtr hWnd)
{
// Assign the handle from the source window to this class.
this.AssignHandle(hWnd);
}

protected override void WndProc(ref Message m)
{
const int WM_MOUSEMOVE = 0x0200;

switch (m.Msg)
{
case WM_MOUSEMOVE:
// Do what you need to do.
break;
}

base.WndProc (ref m);
}
}
}
Jason

Joe Pacelli wrote:
Okay I'm trying to write an application to monitor a running process. Right
now I have a front end which allows the user to pick the programs they want
to monitor. The interval between how often I information for this process,
things like CPU usage, peak memory, virtual memory, etc... All this I get
from System.Diagnostics.Process. I display this information in a listview and
things are working fine. The user can then select one of these processes
being monitored and "I'll display modules in a treeview to them.

Now the thing I want to also do is display windows messages in a listbox. So
for example say I'm monitoring a program called MyApp.exe. I want to select
this program and then go back to this program and contiue working in it.
Clicking command buttons, entering data, selecting menu options. But I want
all these message to be captured by this monitoring program in that listbox
so when I return to it I would see a windows message for
WM_MOUSEMOVE
WM_LBUTTONDOWN
WM_LBUTTONUP
WM_LBUTTONDBLCLK
WM_RBUTTONDOWN
WM_RBUTTONUP
WM_RBUTTONDBLCLK
WM_MBUTTONDOWN
WM_MBUTTONUP
WM_MBUTTONDBLCLK
etc...

I will also create another list of what messages I want to capture but first
I need to capture them and can't figure this part out.

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.