Results 1 to 14 of 14

Thread: Subclassing again...

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2000
    Location
    NYC
    Posts
    52
    Something is amiss... When I do SetWindowLong it fails, and I can't figure out why.

    Here is the relevant code:
    Code:
    Sub SubClass(hWnd As Long)
        hPrevWndProc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WindowProc)
        If hPrevWndProc <> 0 Then
            bIsSubclassed = True
        End If
    End Sub
    Except hPrevWndProc always ends up as zero.

    What is happening here?

    Thanks,
    --Josh

  2. #2
    Guest
    Is hPrevWndProc a Public/Global variable?

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2000
    Location
    NYC
    Posts
    52
    Yes, I've declared it:

    Code:
    Public hPrevWndProc As Long
    in the module that has both SubClass and WindowProc.


  4. #4
    Guest
    Post your SubClass routine up and I'll see if I can find a fault.

  5. #5

    Thread Starter
    Member
    Join Date
    Aug 2000
    Location
    NYC
    Posts
    52
    Code:
    ' ************module1.bas ****************
    
    Declare Function GetLastError Lib "kernel32" () As Long
    Declare Sub SetLastError Lib "kernel32" (ByVal dwErrCode As Long)
    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
    Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" ( _
      ByVal hwnd As Long, _
      ByVal nIndex As Long, _
      ByVal dwNewLong As Long) As Long
    Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" ( _
      ByVal hWnd1 As Long, _ 
      ByVal hWnd2 As Long, _
      ByVal lpsz1 As String, _
      ByVal lpsz2 As String) As Long
    Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
      ByVal hwnd As Long, _
      ByVal wMsg As Long, _
      ByVal wParam As Long, _
      lParam As Any) As Long
    Public Const WM_WINDOWPOSCHANGING = &H46
    Public Const GWL_WNDPROC = (-4)
    Public bIsSubclassed As Boolean
    Public hPrevWndProc As Long
      
      
    Public Function GetMonitor(Who As String)
      Dim sWho As String
      Dim IM_Top As Long
      sWho = Who & " - Instant Message"
      IM_Top = FindWindow(vbNullString, sWho)
      GetMonitor = FindWindowEx(IM_Top, 0, "_Oscar_Static", vbNullString)
    End Function
    
    
    Sub SubClass(hwnd As Long)
        SetLastError (0)
        hPrevWndProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindowProc)
        frmDebug.rtfDebug.TextRTF = hPrevWndProc
        If hPrevWndProc <> 0 Then
            bIsSubclassed = True
            
        End If
    End Sub
    
    Sub UnSubClass(hwnd As Long)
        Dim lRet As Long
        If bIsSubclassed Then
            lRet = SetWindowLong(hwnd, GWL_WNDPROC, hPrevWndProc)
            bIsSubclassed = False
        End If
    End Sub
    
    Public Function WindowProc( _
      ByVal hwnd As Long, _
      ByVal iMsg As Long, _
      ByVal wParam As Long, _
      ByVal lParam As Long)
    
        Select Case iMsg
            Case WM_WINDOWPOSCHANGING
                frmDebug.rtfDebug.TextRTF = "IM Transmitted or Recieved!"
        End Select
        
        WindowProc = CallWindowProc(hPrevWndProc, hwnd, iMsg, wParam, lParam)
    End Function
    
    
    ' *************** frmDebug ************************
    
     Public lMonitor As Long
     Const GWL_WNDPROC = (-4)
     Option Explicit
     
    
    Private Sub Form_Load()
        lMonitor = GetMonitor("JoshWand1")
        rtfDebug.TextRTF = ""
        Call SubClass(lMonitor)
    End Sub
    
    
    Private Sub Form_Unload(Cancel As Integer)
        UnSubClass (lMonitor)
    End Sub



    [Edited by Joshwa on 08-03-2000 at 01:40 PM]

  6. #6
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    you are trying to subclass a monitor, I've never used monitors, so don't know what they are but when you subclass you have to subclass a window, the hWnd parameter has to be a valid Window Handle, otherwise the function will just return 0, like it's doing

  7. #7

    Thread Starter
    Member
    Join Date
    Aug 2000
    Location
    NYC
    Posts
    52
    the "monitor" is just my name for the child window that recieves messages when an IM comes in (class _Oscar_Static).

    If you look at the GetMonitor function it just finds the window of that class and returns the handle. This part of the program works fine and always returns a handle.

  8. #8
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    oh yes, a monitor is also something else in the API, I'm not sure what though, The only reason that SetwindowLong would return Zero is if a bad window function is used, Check the value of Err.LastDllError on the line after setwindowlong, tell me what it is.

  9. #9

    Thread Starter
    Member
    Join Date
    Aug 2000
    Location
    NYC
    Posts
    52
    value of Err.LastDllError after SetWindowLong is 0.

  10. #10
    Guest
    It looks to me like your trying to subclass an AIM window. You can't do this using vb alone. You'll need to use a 3rd party control to subclass outside your own process, or learn the necessary C++ in order to accomplish this. Desaware has outstanding components for global subclassing (as well as a bunch of other goodies), and I highly recommend you check them out at www.desaware.com

    -Joe Jordan
    Ignite Software
    http://www.IgniteSoft.com/

  11. #11

    Thread Starter
    Member
    Join Date
    Aug 2000
    Location
    NYC
    Posts
    52
    Are there any freeware/GPL subclassing controls out there? I can't afford $200 of extra software for this capability...

  12. #12
    Guest
    I don't know of any freeware global subclassing controls... but if your a student you can fax them a copy of your student id and get it for $100 instead of $200

  13. #13

    Thread Starter
    Member
    Join Date
    Aug 2000
    Location
    NYC
    Posts
    52
    $100 is still not cheap by any means... I'll do a little research now that I know what I'm looking for...

    Could I accomplish this in VB using hooks?

  14. #14

    Thread Starter
    Member
    Join Date
    Aug 2000
    Location
    NYC
    Posts
    52
    After a bit of research it appears I can't do it with hooks; I'd still need the C++ DLL (I don't have VC++) to be able to do anything.

    I've been looking for the custom controls, but all I can find is SpyWorks ($$) and MsgBlast.VBX (written for VB 2.0).

    Does anyone know of any other (free!) cross-process subclassing DLL's/Controls?

    It'd be nice to do this the right way (subclassing) instead of lamely polling the window on a timer (resource-hog).

    Thanks a million,
    --Josh

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