473,322 Members | 1,734 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Intercept WndProc (without interrupting it)

HaLo2FrEeEk
404 256MB
I'm trying to watch WndProc as it creates an application window. I want to see all the messages that it sends, but I don't want to interrupt the sending of these messages. This seems to be happening. For example, if I use this code:

Expand|Select|Wrap|Line Numbers
  1.         protected override void WndProc(ref Message m)
  2.         {
  3.             base.WndProc(ref m);
  4.             if (m.Msg == 0x84)
  5.             {
  6.                 backgroundWorker1.RunWorkerAsync(m);
  7.  
  8.             }
  9.         }
  10.  
  11.         private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
  12.         {
  13.             Message m = (Message)e.Argument;
  14.             ListViewItem lvi = new ListViewItem(m.HWnd.ToString());
  15.             lvi.SubItems.Add(m.LParam.ToString());
  16.             lvi.SubItems.Add(m.Msg.ToString());
  17.             lvi.SubItems.Add(m.Result.ToString());
  18.             lvi.SubItems.Add(m.WParam.ToString());
  19.  
  20.             e.Result = lvi;            
  21.         }
That just adds the message's contents to a listview so I can see it, but now it won't let me resize my form. It adds the message to the list, but apparently it doesn't send it to the program. Is there a way I can accomplish this?
Nov 30 '10 #1
4 2972
GaryTexmo
1,501 Expert 1GB
As I understood it, calling the base class WndProc allows it to be processed. I'm not sure why that's stopping it... does taking out the code where you call the background worker make it work again?
Nov 30 '10 #2
GaryTexmo
1,501 Expert 1GB
When I tried your code, I got an exception saying the background worker was too busy. Message 0x84 comes very frequently I guess.

Maybe the list view stuff slows it down too much? I did the following and seemed to have no issues.

Expand|Select|Wrap|Line Numbers
  1.         protected override void WndProc(ref Message m)
  2.         {
  3.             base.WndProc(ref m);
  4.  
  5.             if (m.Msg == 0x84)
  6.             {
  7.                 string output = String.Format("{0} - {1}, {2}, {3}, {4}",
  8.                     m.Msg.ToString("x"),
  9.                     m.HWnd.ToString(),
  10.                     m.LParam.ToString(),
  11.                     m.Result.ToString(),
  12.                     m.WParam.ToString());
  13.  
  14.                 Console.WriteLine(output);
  15.             }
  16.         }
Nov 30 '10 #3
HaLo2FrEeEk
404 256MB
0x84 is only sent when you put your mouse in the sizing area of the form. Left, Right, Top, Bottom, Top-left, Top-right, Bottom-left, and Bottom-right. If your mouse never enters the form (or does so fast enough that it never _technically_ touches the border, then 0x84 is never sent.

And I did remove the background worker and replaced it with just a regular method call and it started to work. Weird...

It's probably because I never handled the RunWorkerComplete event, so the WndProc override never got the Message object back. Maybe...
Dec 1 '10 #4
GaryTexmo
1,501 Expert 1GB
Ah, gotcha. Yea that makes sense now that you point it out...

Yea I can't say, I don't know much about the BackgroundWorker... I haven't had occasion to use it much.
Dec 1 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Larry Woods | last post by:
I have a "homegrown" dll that I am using in IIS (VBScript). I need to replace it on a production server, but I don't want to stop/restart server in order to replace the dll. Possible? TIA,...
3
by: Radovan Radic | last post by:
Hello all, I am new to .NET and a i am moving from Delphi (finally!) to C#. Now, i am trying to develop custom TextBox for numeric input. I have done it almost, now i need to prevent paste so...
8
by: MrNobody | last post by:
How do I change a window's behavior so when someone clicks the little 'X' in the upper right corner it actually hides the dialog, instead of disposing it?
0
by: han.phony | last post by:
Hi, I am trying to intercept the message sent back by winmm.dll's mciSendString method when playback is finished. I tried to override the WndProc in the form but I didn't get/intercept the message,...
2
by: Phuff | last post by:
I have an application that should run in the system tray while open. It is supposed to be open at all times and I need it to dissapear when the "X" button is pushed on the form...but without...
2
by: Derrick | last post by:
Hello all; I'm trying to create a UI that's a little atypical. In the main form's Paint event handler, I draw an image on the form - this is what I want to by my "real" UI. I turned off the...
3
by: Tim | last post by:
Can you show me how to debug a whole vb program without stopping at the end of the first form? I have many vb forms, i.e., 5 forms, that after the first form have done its job, the next form will...
6
by: John Wright | last post by:
First some background: I have been asked to develop a program that access our data warehouse. It requires a login and password to use so we created a custom control that is placed on the form,...
2
vdraceil
by: vdraceil | last post by:
Hi experts,i know that it is possible to intercept windows messages(keyboard events,mouse events etc).is it possible to stop those messages from reaching windows and modify them? I mean can we...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.