Home | Index | Dotnet4all Snippets | Submit resources
About | Mail us 
Project converted from VB6 to VB.Net gets subclassed WndProc -- why? (Monday, January 30, 2006)



Found the following interesting discussion in the Newsgroups:

Project converted from VB6 to VB.Net gets subclassed WndProc -- why?
by: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


 Reply:
by: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



Posted by Xander Zelders



0 Comments:

Post a Comment

<< Home

 
Previous Posts
    - Freeware/shareware Windows controls
    - Combobox in datagrid?
    - To parenthesize or not... Bug in VB.Net?
    - How to change the Color of a Toolbar?
    - How to pass Objects as type System.Object?
    - How to create a Username/Login Page?
    - Suggestions to increase the performance of searchi...
    - Where did my Dataset Go?
    - Password Filter DLL
    - An application framework for VB.NET



Disclaimer & Terms of Use | DotNet4All.Com concept & © 2004 - 2007 by Zelders² - Holland