Subclassing questions

Unleash

New Member
Joined
Apr 15, 2011
Messages
13
So, as a follow up on my previous thread:

http://www.mrexcel.com/forum/showthread.php?p=2690602#post2690602

Which miserably failed. I have been testing and writing code all day to find out why things are not working.

I now know that the problem lies within the "hooking" of the userform. But I don't know why it keeps terminating when coming there. these are the two parts that do the hooking:

Code:
Private Sub List_Hook()
    'Maakt de Hook alleen als deze nog niet bestaat
    If Not blnHooked Then
        WheelHook FlensDefinitie
        blnHooked = True
    End If
End Sub

Code:
Public Sub WheelHook(ClientForm As UserForm)
    hWnd_UserForm = FindWindow("ThunderDFrame", ClientForm.Caption)
    lngWndProc = SetWindowLong(hWnd_UserForm, GWL_WNDPROC, AddressOf WindowProc)
End Sub

The first one is called by mouseover events from the listboxes and from the Userform itself. Although when the mouseover event for the Userform gets raised, it isnt the hookup but the unhook path that is run. These are the subs for the unhooking:

Code:
Private Sub UserForm_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    LH = 0
    'Vernietigd de hook als de muis niet op de control is.
    Call List_UnHook
End Sub

Code:
 Private Sub List_UnHook()
    'Vernietigd de hook alleen als deze al bestaat
    If blnHooked Then
        WheelUnHook
        blnHooked = False
    End If
End Sub

Code:
Public Sub WheelUnHook()
Dim lRet As Long
    lRet = SetWindowLong(hWnd_UserForm, GWL_WNDPROC, lngWndProc)
End Sub

The code fails the moment that the cursor comes onto the Userform, and the Mousemove event is raised. But since "blnHooked" is "false" from the beginning, nothing should happen.

Any idea on why the MouseMove event causes a crash??

Any help will be greatly appreciated!
 
Yeah, but that's for Access forms which are a totally different beast!
Personally, I'd probably avoid popups in that function - just suppress the errors.
 
Upvote 0

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,224,587
Messages
6,179,738
Members
452,940
Latest member
Lawrenceiow

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top