|
-
Aug 3rd, 2000, 10:43 AM
#1
Thread Starter
Member
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
-
Aug 3rd, 2000, 10:55 AM
#2
Is hPrevWndProc a Public/Global variable?
-
Aug 3rd, 2000, 11:05 AM
#3
Thread Starter
Member
Yes, I've declared it:
Code:
Public hPrevWndProc As Long
in the module that has both SubClass and WindowProc.
-
Aug 3rd, 2000, 11:22 AM
#4
Post your SubClass routine up and I'll see if I can find a fault.
-
Aug 3rd, 2000, 11:34 AM
#5
Thread Starter
Member
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]
-
Aug 3rd, 2000, 12:28 PM
#6
Frenzied Member
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
-
Aug 3rd, 2000, 12:36 PM
#7
Thread Starter
Member
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.
-
Aug 3rd, 2000, 01:06 PM
#8
Frenzied Member
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.
-
Aug 3rd, 2000, 01:15 PM
#9
Thread Starter
Member
value of Err.LastDllError after SetWindowLong is 0.
-
Aug 3rd, 2000, 03:42 PM
#10
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/
-
Aug 3rd, 2000, 03:52 PM
#11
Thread Starter
Member
Are there any freeware/GPL subclassing controls out there? I can't afford $200 of extra software for this capability...
-
Aug 3rd, 2000, 03:56 PM
#12
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
-
Aug 3rd, 2000, 03:59 PM
#13
Thread Starter
Member
$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?
-
Aug 3rd, 2000, 08:17 PM
#14
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|