?
Solved

VB.net MyBase not valid within module

Posted on 2013-06-04
3
Medium Priority
?
595 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
[X]
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
3 Comments
 
LVL 86

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 86

Accepted Solution

by:
Mike Tomlinson earned 1500 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

770 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