473,503 Members | 2,157 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trapping Windows Messages from other applications

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
2 11483
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2190
by: Brad Jones | last post by:
Hello, I'm hoping someone can give me some help or guidance here. I'm not sure if this is even the best group to post to for this. Our OEM equipment's software architecture relies heavily on a...
6
4712
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
1
8536
by: timtos | last post by:
When I am looking at custom drawing of controls I often see somthing like this: public enum ReflectedMessages { OCM__BASE = (Msg.WM_USER+0x1c00), OCM_COMMAND = (OCM__BASE + Msg.WM_COMMAND),...
2
4916
by: Mr Sparkles | last post by:
Heya Everyone, I am currently creating an application audit system that will log how much use an application will be used by employees of my company, and the type of features they use...so I...
1
5657
by: Artur Kowalski | last post by:
I have a NotifyIcon in my Windows Service project and I am trying to add a ContextMenu to this NotifyIcon or use some of the mouse events. Everything isn't working. I think so base class of the...
14
4893
by: Brian Keating EI9FXB | last post by:
I wonder can anyone reccomment a solution to this problem. Let me explain, I've services running on my system, my application receives diagnostic messages from these services, what i want to do...
14
4073
by: | last post by:
Hi All, I am little confused here, hope you can help me. While processing WM_POWERBROADCAST (wParam=PBT_APMQUERYSUSPEND), I MUST to do some lengthy operation(30 sec) before system Suspends or...
3
7470
by: Chris Paul | last post by:
I'm having trouble with PHP & PostgreSQL/OpenLDAP/Apache on Windows. I've set this up countless times on BSD (piece of cake) but I'm trying to do this on Windows now so that my developer can work...
4
10486
by: Peter Nimmo | last post by:
Hi, I am writting a windows application that I want to be able to act as if it where a Console application in certain circumstances, such as error logging. Whilst I have nearly got it, it...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
5022
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4688
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3168
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
399
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.