Solved MyBase not valid within module

Posted on 2013-06-04
Last Modified: 2013-06-17
I have some code I want to reuse in several of my apps written in 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.
        '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. 
            '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?
Question by:mossmis
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 39219473
WndProc() is specifically used with windows that have a message 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.

Author Comment

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.
LVL 86

Accepted Solution

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
    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
    End Sub

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

        End Select
    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.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASP.NET Calendar Control 5 53
Best book for Internet security 4 52
How to call new form in VB2013? 4 34
Javascript function 3 19
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…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below.…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

734 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