|
-
Aug 9th, 2002, 05:15 AM
#1
Thread Starter
Fanatic Member
catch mouse click on a form
how can i tell if user click on the form without using any of the predefined form events.
thnks
-
Aug 9th, 2002, 05:41 AM
#2
Addicted Member
It might help if you explain what you are trying to do - I'm not sure why you want to avoid using the Form events...
But anyway, to detect these clicks before your form does, you'd have to subclass the form's window, and look for the mousedown, mouseup messages - then you could elect to pass them on or not....
Dr Memory
"He's got a B.A. (in be-bop), a Ph.D. (in swing), he's a Master of Rhythm, he's the Rock'n'Roll king"  ("The Rock'n'Roll Doctor", Lowell George)
"If you push something hard enough, it will fall over" (Fudd's Third Law of Opposition)
-
Aug 9th, 2002, 06:27 AM
#3
Thread Starter
Fanatic Member
i m building an activex and i do not want user to put code at form's mousedown event i want my active to detect mouseclick b4 form does can u give an example on how can i subclass form to get the info i want?
-
Aug 9th, 2002, 07:12 AM
#4
Addicted Member
Tina
OK, I have an example for you - I've just got to trim it a bit - watch this space ....
Dr Memory
"He's got a B.A. (in be-bop), a Ph.D. (in swing), he's a Master of Rhythm, he's the Rock'n'Roll king"  ("The Rock'n'Roll Doctor", Lowell George)
"If you push something hard enough, it will fall over" (Fudd's Third Law of Opposition)
-
Aug 9th, 2002, 07:20 AM
#5
Addicted Member
OK, here's a little module:
Code:
Option Explicit
Const WM_LBUTTONDOWN = &H201& ' MouseDown - Left button
Const WM_MBUTTONDOWN = &H207& ' Middle
Const WM_RBUTTONDOWN = &H204& ' Right
Const GWL_WNDPROC = -4
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) 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 Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim OldWindowProc As Long
Public Function SubClass(hWnd As Long)
OldWindowProc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WndProc)
End Function
Public Function UnSubClass(hWnd As Long) As Boolean
Call SetWindowLong(hWnd, GWL_WNDPROC, OldWindowProc)
End Function
Public Function WndProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case uMsg
Case WM_LBUTTONDOWN, WM_MBUTTONDOWN, WM_RBUTTONDOWN
Exit Function ' block these events
End Select
'
' pass along all others
'
WndProc = CallWindowProc(OldWindowProc, hWnd, uMsg, wParam, lParam)
End Function
And here's a little test form:
Code:
Private Sub Form_Load()
Show
mSubclassOn.Enabled = True
mSubclassOff.Enabled = False
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
UnSubClass Me.hWnd
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
MsgBox "Form MouseDown Event", vbInformation
End Sub
Private Sub mSubclassOn_Click()
SubClass Me.hWnd
mSubclassOff.Enabled = True
mSubclassOn.Enabled = False
End Sub
Private Sub mSubclassOff_Click()
UnSubClass Me.hWnd
mSubclassOn.Enabled = True
mSubclassOff.Enabled = False
End Sub
Private Sub Command1_Click()
MsgBox "Button", vbInformation
End Sub
Private Sub Label1_Click()
MsgBox "Label", vbInformation
End Sub
Private Sub Picture1_Click()
MsgBox "PictureBox", vbInformation
End Sub
Notes to follow .....
"He's got a B.A. (in be-bop), a Ph.D. (in swing), he's a Master of Rhythm, he's the Rock'n'Roll king"  ("The Rock'n'Roll Doctor", Lowell George)
"If you push something hard enough, it will fall over" (Fudd's Third Law of Opposition)
-
Aug 9th, 2002, 07:24 AM
#6
Addicted Member
Open a new project and paint a Command Button, a PictureBox, a Label on it.
Create 2 menu options mSubclassOn and mSubClassOff
Load the module
When you run it, if you click mSubClassOn, you'll find that the Form_MouseDown event is disabled, but you can still click on the Button and the PictureBox.
You CAN'T click on the label - it has no window of its own, it's managed by the Form.
PS - don't "break" into the IDE while SubClassing is ON, or you'll crash rather hard!
Dr Memory
"He's got a B.A. (in be-bop), a Ph.D. (in swing), he's a Master of Rhythm, he's the Rock'n'Roll king"  ("The Rock'n'Roll Doctor", Lowell George)
"If you push something hard enough, it will fall over" (Fudd's Third Law of Opposition)
-
Aug 10th, 2002, 06:15 AM
#7
Thread Starter
Fanatic Member
thnks a lot MathImagics i ll try your code and tell you how it went
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
|