|
-
Feb 4th, 2007, 11:29 PM
#1
Thread Starter
Addicted Member
Right Click Mouse
Hi Currently i'm have Activex Control made by some one else (textbox with some advanced properties and event added). From it documentation, i found it was made based on VB standard Textbox. The problem is, it's mousedown and mouseup event doesn't work (not fire at all, the event does exist). Since i like it and using it a lot in my program, so i want to add event my own mousedown and my own mouseup event by made User Control based on this activex.
My question is how to add event on user control and how to detect mousedown and mouseup using API or whatever it take . Sample attached will be very helpfull.
Thanks.
BA
-
Feb 5th, 2007, 04:34 AM
#2
Thread Starter
Addicted Member
Re: Right Click Mouse
Sorry to "bump" this question up.
Perhaps anyone on different timezone is now already up and online can give me a hands.
Thanks
-
Feb 5th, 2007, 04:49 AM
#3
Re: Right Click Mouse
Create the events yourself. Use the following:
VB Code:
Public Event MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Public Event MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
You can then intercept the messages WM_LBUTTONDOWN and WM_LBUTTONUP and use the RaiseEvent() statement to tell you application to fire the event.
-
Feb 5th, 2007, 05:03 AM
#4
Thread Starter
Addicted Member
Re: Right Click Mouse
Thanks Jenova
After dig the net for while i got almost same with your suggestion, but i still don't know when exact time and how to intercept WM_LBUTTONDOWN and WM_LBUTTONUP on my current user control?
FYI, i'm still novice in VB programming.
Last edited by barianto; Feb 5th, 2007 at 05:06 AM.
-
Feb 5th, 2007, 03:21 PM
#5
Re: Right Click Mouse
Do you have the source code for the ActiveX control? If so, just make sure it exposes the textbox's MouseDown event (as Jenova showed you). If they aren't exposed your program won't see them, so you'll have to subclass the ActiveX control and intercept the messages for any MouseDown or MouseUp on the control.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Feb 5th, 2007, 04:33 PM
#6
Re: Right Click Mouse
You can SubClass the control by using the CallWindowProc() and SetWindowLong() API Statements. Then write your own windowprocedure that intercepts the messages and processes them the way you want to.
Check out the AllApi link in my sig for a definition of these API's and examples on how to use them.
-
Feb 5th, 2007, 07:40 PM
#7
Thread Starter
Addicted Member
Re: Right Click Mouse
Al42:
I don't have source code.
Jenova:
I don't know how to subclass it. Sorry if i'm just to whine but sample from you guys (if you got time) will be very helpful.
Thanks
-
Feb 6th, 2007, 05:56 AM
#8
Re: Right Click Mouse
Here you go, this is how subclassing a text box control would happen, you may need to modify the code slightly, if you don't have the code then we cant ammend it for you. Hope this is of some help:
VB Code:
'
' You will need a project with
' 1 x Form
' 1 x Text Box
' 1 x Module
' *** IN A MODULE ***
Option Explicit
Private Declare Function CallWindowProc _
Lib "user32" _
Alias "CallWindowProcA" ( _
ByVal lpPrevWndFunc As Long, _
ByVal hwnd As Long, _
ByVal Msg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) _
As Long
Private Declare Sub CopyMemory _
Lib "kernel32" _
Alias "RtlMoveMemory" ( _
Destination As Any, _
Source As Any, _
ByVal Length As Long)
Private Declare Function SetWindowLong _
Lib "user32" _
Alias "SetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) _
As Long
Private Const GWL_WNDPROC = (-4)
Private Const WM_RBUTTONDOWN As Long = &H204
Private Const WM_RBUTTONUP As Long = &H205
Private OldWindowProc As Long
Public Sub HookWindow(txtTextBox As TextBox)
' Set the new window procedure to monitor the text boxes message queue. When our
' message is found it is picked out of the queue and proccess by our window
' procedure, any other messages are left alone and are processed by the original
' window procedure.
OldWindowProc = SetWindowLong(txtTextBox.hwnd, GWL_WNDPROC, AddressOf NewWindowProc)
End Sub
Public Sub UnhookWindow(txtTextBox As TextBox)
' Restore the old window procedure and cease monitoring the
' the message queue.
SetWindowLong txtTextBox.hwnd, GWL_WNDPROC, OldWindowProc
If OldWindowProc Then
OldWindowProc = 0
End If
End Sub
Private Function NewWindowProc(ByVal hwnd As Long, ByVal Msg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case Msg
' Intercept the right mouse button being released
Case WM_RBUTTONUP
' Process the message the way we want. If you comment the code in the form and run
' the application, right click on the text box, you will see the default text box
' menu. However now that we have intercepted the message we are altering it to do
' WE want it to do, in this instance, we are generating a message box.
MsgBox "Put the code that you want here when the user right clicks", vbInformation
' MSDN tells us to return 0 when ever we procces a message
NewWindowProc = 0
Case Else
' Restore the default handling for other messages. Remember that the text box
' will be recieving other messages to process. We are not interested in these
' so we let the default window procedure process them, not ours.
NewWindowProc = CallWindowProc(OldWindowProc, hwnd, Msg, wParam, lParam)
End Select
End Function
' *** IN A FORM ***
Option Explicit
Private Sub Form_Load()
' Hook the textbox
HookWindow Text1
End Sub
Private Sub Form_Unload(Cancel As Integer)
' Unhook the textbox
UnhookWindow Text1
End Sub
Last edited by Jenova; Feb 6th, 2007 at 06:00 AM.
-
Feb 6th, 2007, 06:17 AM
#9
Thread Starter
Addicted Member
Re: Right Click Mouse
I will try it.
Will let you know later jenova.
PS: How to put your code above if i made user control based on this control (which doesn't have mousedown and mouseup event). User control doesn't have form, where should i put HookWindow procedure?
-
Feb 6th, 2007, 06:37 AM
#10
Re: Right Click Mouse
I'm not sure, i have never made a User Control before. I would imagine that you would still need to add it to the form that your control is on, either that, i think user controls have 'Initialize' or 'Activate' events. just hook the window from that point in the control.
-
Feb 6th, 2007, 08:52 PM
#11
Thread Starter
Addicted Member
Re: Right Click Mouse
Jenova, it doesnt work. No error produce but it never met this condition
VB Code:
select Case Msg
' Intercept the right mouse button being released
Case WM_RBUTTONUP, WM_RBUTTONDOWN
-
Feb 7th, 2007, 04:03 AM
#12
Re: Right Click Mouse
 Originally Posted by barianto
Jenova, it doesnt work. No error produce but it never met this condition
VB Code:
select Case Msg
' Intercept the right mouse button being released
Case WM_RBUTTONUP, WM_RBUTTONDOWN
If your using it with the control you have then i am ot sure how to get around it. But it should be
VB Code:
Select Case Msg
' Intercept the right mouse button being released
Case WM_RBUTTONUP
' Process message here
End Select
Have you tried searching Google for Subclassing ActiveX Controls in Visual Basic 6
-
Feb 7th, 2007, 05:51 AM
#13
Thread Starter
Addicted Member
Re: Right Click Mouse
I will try searching on goole then 
I add "WM_RBUTTONDOWN" just in case it will hit, but still doesn't wor.
-
Feb 11th, 2007, 05:32 AM
#14
Re: Right Click Mouse
Use Spy++/Classy/WinID to get the handle of the textbox and then subclass it (Classy can actually write code for you).
As it is created with VB, the textbox's class will be ThunderTextBox or ThunderRT6TextBox.
Once you get the handle you can easily subclass it by following previous examples.
-
Feb 11th, 2007, 08:48 AM
#15
Re: Right Click Mouse
He doesn't need to use Spy++ or any other application for that matter, the text box has a .hWnd property.
-
Feb 11th, 2007, 08:58 AM
#16
Re: Right Click Mouse
If I understood correctly, the Custom-TextBox-Control has a VB6 textbox inside it.
In that case the hWnd exposed by the ActiveX control is NOT the handle of the VB6TextBox inside it.
So, directly hooking the VB6Textbox MAY work.
I think, the parent hierarchy is something like this,
Code:
Form (ThunderFormDC)
|__ UserControl (ThunderUserControlDC)
|__TextBox (ThunderTextBox)
(That is what looks like when you create your own usercontrol with a textbox and place it on a form. For an 'external' ActiveX control it should be similar.)
I'm not sure if it will work. But as directly hooking the control isn't working, there is no harm trying this.
-
Feb 11th, 2007, 08:03 PM
#17
Thread Starter
Addicted Member
Re: Right Click Mouse
thanks, jenova, iPrank
will try it (iPrank suggestion)
-
Feb 15th, 2007, 09:48 AM
#18
Re: Right Click Mouse
For the record. This was actually easier than i thought . I'm not sure if you have done this but here you go this is how you subclass the textbox on the ActiveX control. FindWindow was not necesary for the control.
VB Code:
'
' For this application to work you will need
' 1 x Form
' 1 x Module
' 1 x User Control w/ Text Box Control on it
'
' Module Code
Option Explicit
Private Declare Function CallWindowProc _
Lib "user32" _
Alias "CallWindowProcA" ( _
ByVal lpPrevWndFunc As Long, _
ByVal hwnd As Long, _
ByVal Msg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) _
As Long
Private Declare Sub CopyMemory _
Lib "kernel32" _
Alias "RtlMoveMemory" ( _
Destination As Any, _
Source As Any, _
ByVal Length As Long)
Private Declare Function SetWindowLong _
Lib "user32" _
Alias "SetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) _
As Long
Private Const GWL_WNDPROC = (-4)
Private Const WM_RBUTTONUP As Long = &H205
Private OldWindowProc As Long
Public Sub HookWindow(txtTextBox As TextBox)
' Set the new window procedure to monitor the text boxes message queue. When our
' message is found it is picked out of the queue and proccess by our window
' procedure, any other messages are left alone and are processed by the original
' window procedure.
OldWindowProc = SetWindowLong(txtTextBox.hwnd, GWL_WNDPROC, AddressOf NewWindowProc)
End Sub
Public Sub UnhookWindow(txtTextBox As TextBox)
' Restore the old window procedure and cease monitoring the
' the message queue.
SetWindowLong txtTextBox.hwnd, GWL_WNDPROC, OldWindowProc
If OldWindowProc Then
OldWindowProc = 0
End If
End Sub
Private Function NewWindowProc(ByVal hwnd As Long, ByVal Msg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case Msg
' Intercept the right mouse button being released
Case WM_RBUTTONUP
' Process the message the way we want. If you comment the code in the form and run
' the application, right click on the text box, you will see the default text box
' menu. However now that we have intercepted the message we are altering it to do
' WE want it to do, in this instance, we are generating a message box.
MsgBox "Put the code that you want here when the user right clicks", vbInformation
' MSDN tells us to return 0 when ever we procces a message
NewWindowProc = 0
Case Else
' Restore the default handling for other messages. Remember that the text box
' will be recieving other messages to process. We are not interested in these
' so we let the default window procedure process them, not ours.
NewWindowProc = CallWindowProc(OldWindowProc, hwnd, Msg, wParam, lParam)
End Select
End Function
' Form Code
Option Explicit
Private Sub UserControl_Initialize()
HookWindow Text1
End Sub
Private Sub UserControl_Resize()
With Text1
.Height = UserControl.Height
.Width = UserControl.Width
End With
End Sub
Private Sub UserControl_Terminate()
UnhookWindow Text1
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|