|
-
May 6th, 2001, 08:52 AM
#1
Thread Starter
Hyperactive Member
Sub Classing
Why doesn't this do anything?
Form1
-----------------
Dim lpfnOld As Long
Private Sub Form_Load()
lpfnOld = SetWindowLong(Form1.hwnd, GWL_WNDPROC, AddressOf FrmWndProc)
End Sub
Private Sub Form_Unload(Cancel As Integer)
SetWindowLong Form1.hwnd, GWL_WNDPROC, lpfnOld
End Sub
Module1
-----------------
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Function FrmWndProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
MsgBox "hello"
Select Case uMsg
Case WM_SETFOCUS
Form1.Caption = "Subclassed Form - Has Focus"
FrmWndProc = 0
Exit Function
Case WM_KILLFOCUS
Form1.Caption = "Subclassed Form - Lost Focus"
FrmWndProc = 0
Exit Function
End Select
FrmWndProc = CallWindowProc(lpfnOld, hwnd, uMsg, wParam, lParam)
End Function
This is the very first time I have tried this so I haven't got a clue.
-Thanks
W#Ć€V€® W¦|| ߀ W¦|| ߀, ÄÑÐ †#€®€ ¦§ ÑÖ†#¦Ñ6 ¥Öµ ©ÄÑ ÐÖ ÄßÖµ† ¦†, §Ö §¦† ßÄ©K, ®€|ÄX ÄÑÐ |€† ¦† #ÄÞÞ€Ñ.
(Whatever will be will be, and there is nothing you can do about it, so sit back, relax and let it happen.)
-
May 6th, 2001, 09:06 AM
#2
First of all never use msgbox or any other flow breaking calls like doevents when you are subclassing. It's very unhealthy, use Debug.print instead.
I think that might fix it
-
May 6th, 2001, 11:12 AM
#3
Fanatic Member
From vbAccelerator:
When a form in your application is deactivated, Windows fires a WM_ACTIVATE message to the form. The wParam of this message tells you the reason the message has been fired:
wParam Meaning
0 Form deactivated
1 Form activated
2 Form activated by a mouse click
So try subclassing the WM_ACTIVATE instead of WM_SETFOCUS and WM_KILLFOCUS, AFAIK they won't work properly...
Teaudirenopossum.Musasapientumfixaestinaure.
(I can't hear you. There's a banana in my ear)
-
May 6th, 2001, 11:16 AM
#4
You don't have any of the constants declared either. Add these to your Module.
Code:
Const WM_SETFOCUS = &H7
Const WM_KILLFOCUS = &H8
-
May 6th, 2001, 11:34 AM
#5
Thread Starter
Hyperactive Member
I should have noticed that! Anyway, it works now. Thanks all.
W#Ć€V€® W¦|| ߀ W¦|| ߀, ÄÑÐ †#€®€ ¦§ ÑÖ†#¦Ñ6 ¥Öµ ©ÄÑ ÐÖ ÄßÖµ† ¦†, §Ö §¦† ßÄ©K, ®€|ÄX ÄÑÐ |€† ¦† #ÄÞÞ€Ñ.
(Whatever will be will be, and there is nothing you can do about it, so sit back, relax and let it happen.)
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
|