Results 1 to 5 of 5

Thread: Sub Classing

  1. #1

    Thread Starter
    Hyperactive Member TiPeRa's Avatar
    Join Date
    Apr 2001
    Location
    In between
    Posts
    464

    Unhappy 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.)

  2. #2
    AIS_DK
    Guest
    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

  3. #3
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    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)

  4. #4
    Megatron
    Guest
    You don't have any of the constants declared either. Add these to your Module.
    Code:
    Const WM_SETFOCUS = &H7
    Const WM_KILLFOCUS = &H8

  5. #5

    Thread Starter
    Hyperactive Member TiPeRa's Avatar
    Join Date
    Apr 2001
    Location
    In between
    Posts
    464
    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
  •  



Click Here to Expand Forum to Full Width