Solved

VB.net MyBase not valid within module

Posted on 2013-06-04
3
519 Views
Last Modified: 2013-06-17
I have some code I want to reuse in several of my apps written in VB.net. I would like to put them in a module/class so I can reference them from other apps. One sub routine doesn't like being in a class\module and I was wondering how it coud be rewritten:

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        '
        'Have the base class handle all messages.
        MyBase.WndProc(m)
        '
        'Check if a new window has been created.
        If m.Result.ToInt32 = WM_CREATE Then
            '
            'Check the new window to see if it has the charateristics that we are looking for. Namely that is has the Title that we want to find.
            windowHandle = FindWindow(vbNullString, inputTitle)
            '
            'Make sure that the WindowHandle is not 0 which should mean it have a handle to the Inputbox window that we are wanting.
        ElseIf windowHandle > 0 Then
            '
            'Call the code to set the textbox to a password textbox. 
            setPassword()
            '
            'Reset the handle back to 0 since the window handle will be different each time you display Inputbox window.
            windowHandle = 0
        End If
    End Sub

Open in new window


VB doesn't let me put a Protected Overrrides in a module and it also doesn't like MyBase in a class or module. Any suggestions?
0
Comment
Question by:mossmis
  • 2
3 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 39219473
WndProc() is specifically used with windows that have a message pump...so it can't be in a module since a module isn't a window.  You could encapsulate a NativeWindow() instance inside a class if you need to trap windows messages.
0
 

Author Comment

by:mossmis
ID: 39219675
I'm not that saavy in .net. I'm coming from vb6 and never really got that complex for me. I guess I could just paste this code in all my apps as a work around, but it wouldn't be as organized as I'd like. If you can elaborate more on how to use it, I'd like to give it a try.
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 39219808
Well...normally WndProc() would be in a form (or some kind of derived control) right?
Public Class Form1

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        Select Case m.Msg

        End Select
        MyBase.WndProc(m)
    End Sub

End Class

Open in new window


You could instead create a Class to act as a receiver for windows messages like this:
Public Class MyNativeWindow
    Inherits NativeWindow

    Private Const HWND_MESSAGE As Integer = -3

    Public Sub New()
        Dim cp As New CreateParams()
        cp.Parent = HWND_MESSAGE
        Me.CreateHandle(cp)
    End Sub

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        Select Case m.Msg

        End Select
        MyBase.WndProc(m)
    End Sub

End Class

Open in new window


Obviously you'd need to add more code so that it is registered for the kind of messages you want.  You can then simply add a Reference to this class project in new projects so you could you use it.  You'd still have to create an instance of it though.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now