Click to See Complete Forum and Search --> : Over-ride the events of a control.


saju_peruvachira
June 28th, 2001, 01:59 AM
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

Clearcode
June 28th, 2001, 02:53 AM
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

saju_peruvachira
June 29th, 2001, 12:04 AM
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

Clearcode
June 29th, 2001, 03:03 AM
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