How do I use a delegate for WndProc?

G

Guest

How do I use a delegate for WndProc?
I have a form that processes (intercepts) some windows messages only when a
particular command button is pressed. How do I use a delegate for WndProc so
that I can override the WndProc Sub only when the button is clicked and
restore the original WndProc when I am done?
 
B

Bob Powell [MVP]

I think that's not a good idea.

Just set a flag if the command button is pressed and handle the messages in
a WndProc override as normal.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
G

Guest

That's what I'm doing now. I have a class that handles the WindProc and it
looks like this:
Protected Overrides Sub WndProc(ByRef m As Message)
MyBase.WndProc(m)
fdx.WndProc(m)
End Sub

//fdx.WndProc
public void WndProc(ref Message m) {
if (!_enabled)
return;
...
} // public void WndProc(ref Message m)

However, I thought I could improve performance if I was able to turn on/off
the override using a delegate. This may be helpful for overrides in general.
 
B

Bob Powell [MVP]

For a start, if you call the base-class wndproc before you call your own
handlers messages that ought to be sending back signals to indicate they've
been handled will be getting the default treatment.

If you're going to override WndProc you should trap out all your stuff
first, return the appropriate response and then call the base class or
DefWndProc when you're supposed to.

The examiniation of a boolean or two in the message handler case isn't going
to be a performance problem.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
G

Guest

Well I was able to use a delegate IN WndProc but I haven't figuredout to use
a deleagte in PLACE of WndProc. I looked at the docs for Message.Result and
there is nothing there. I assume that they mean it to be the same as LRESULT
but it returns an IntPtr, so I am not sure about the return value from
Mybase.WndProc. Do you know?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top