CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2000
    Posts
    11

    Over-ride the events of a control.

    Hi VB Gurus,
    I want to have a generic implementation of an application and hence I want to override some of the events of a TextBox control. Can any of you provide me with some input on this. Thanking you in advance.
    Saju


  2. #2
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: Over-ride the events of a control.

    You can do this by subclassing the control. What this basically means is intercepting the messages sent to the textbox and overriding them - if you tell me what events you want to override I'll be able to give you more info.

    HTH,
    Duncan

    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

  3. #3
    Join Date
    Jun 2000
    Posts
    11

    Re: Over-ride the events of a control.

    I need to override the click event of a Command Button Control and also to override the lostfocus event of a TextBox Control. It would be real helpful if you could provide me with some more information. Thanks a lot in advance.
    Saju


  4. #4
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: Over-ride the events of a control.

    When a command button receives a WM_LBUTTONDOWN message followed by a WM_LBUTTONUP message it generates a Click() event. If you don't want the button to go down, intercept the WM_LBUTTONDOWN message and don't allow it to be processed by the button.

    When a textbox is about to lose the input focus it recieves a WM_KILLFOCUS message. You can respond to this by calling the SetFocus() routine to set focus back to the textbox.

    Subclassing is a very powerful but also very difficult technique to use. Fortunately there is a dll called the EventVB.dll that we have created that will (hopefully) assist you greatly. It can be downloaded from http://www.merrioncomputing.com/Download/index.htm.

    To use it, the following code is required:

    '\\ Form declarations
    Dim withevents ApiLink as EventVB.ApiFunctions
    Dim withevents wndCommand as EventVB.ApiWindow
    Dim withevents wndTextbox as EventVB.ApiWindow

    '\\ Form load
    private Sub Form_Load()
    set ApiLink = new EventVB.ApiFunctions
    set wndCommand = new EventVB.ApiWindow
    set wndTextBox = new EventVB.ApiWindow

    '\\ Connect the wnd Variables to the actual controls
    wndTextBox.hwnd = Text1.hwnd
    wndCommand.hwnd = Command1.hwnd

    '\\ Start subclassing the events...
    ApiLink.SubclassedWindows.Add wndTextBox
    ApiLink.SubclassedWindows.Add wndCommand

    End Sub

    '\\ Form queryunload
    private Sub Form_QueryUnload(Cancel as Integer, UnloadMode as Integer)
    '\\ Stop subclassing the windows
    ApiLink.SubclassedWindows.Remove wndTextBox
    ApiLink.SubclassedWindows.Remove wndCommand
    End Sub

    '\\ Form terminate
    private Sub Form_Terminate()
    '\\ Free the object variables....
    set wndTextbox = nothing
    set wndCommand = nothing
    set ApiLink = nothing
    End Sub

    '\\ Commandbutton window message
    private Sub wndCommand_WindowMessageFired(byval msg as WindowMessages, byval wParam as Long, byval lParam as Long, Cancel as Boolean, ProcRet as Long)

    If msg = WM_LBUTTONDOWN then
    '\\ Discard the message
    Cancel = true
    End If'\\ Textbox window message
    private Sub wndTextbox_WindowMessageFired(byval msg as WindowMessages, byval wParam as Long, byval lParam as Long, Cancel as Boolean, ProcRet as Long)

    If msg = WM_KILLFOCUS then
    Text1.SetFocus
    End If

    End Sub




    HTH,
    End Sub


    Duncan

    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured