Project converted from VB6 to VB.Net gets subclassed WndProc -- why?

R

Rob Richardson

Greetings!

I have a VB.Net 2003 project that was originally written in VB6, converted
to VB.Net 2002, and then converted to VB.Net 2003. I am trying to handle a
form's Resize event. I put a breakpoint in it and saw that that event got
fired four times before the form's Load event got fired! I then saw that I
have the following routine in the form's code:

Private Const WM_SHOWWINDOW = &H18
Private m_loaded As Boolean
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
If m.Msg = WM_SHOWWINDOW Then
If Not m_loaded Then
MyBase.OnLoad(New System.EventArgs())
End If
End If
MyBase.WndProc(m)
End Sub

And my form's Load event sets the m_loaded flag to true.

I never put that routine in. I presume it was added at some point in one of
those conversions. Why is it here?

Thanks!

Rob
 
T

Tom Spink

It's because of the legacy way VB6 handled forms... VB6 was not
Object-Oriented, not even Object-Based.... At a push, I'd call it
Object-Aware....

Stepping off the Soap Box, The code is designed to emulate the functionality
of the 'Load' keyword in '6:

<VB6>
Form1.Show()
</VB6>

This will load the form, if not already loaded then show it. So, provided
the Form hasn't been 'Load'ed yet, showing the window will cause the 'Load'
event to occur. Whether you keep it or not is a personal decision... do you
need the functionality that comes with this?

--
HTH,
-- Tom Spink, Über Geek

Woe be the day VBC.EXE says, "OrElse what?"

Please respond to the newsgroup,
so all can benefit
 
R

Rob Richardson

Thanks, Tom. That gives me enough to decide whether or not I want it. More
accurately, it gives me enough to understand what's likely to happen after I
rip it out.

Rob
 

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