Robert
8/29/2010 3:51:00 PM
Hi,
Is there a reason why I can't send and receive a messages with a
negative number using SendMessage?
The Windows common controls use negative notification messages and
I've never had a problem receiving those, so the problem has to be
with the Sending side of things.
What am I missing?
Thanks
'**** FORM1 ****'
Option Explicit
Private Declare Function SendMessage Lib "USER32" Alias "SendMessageA"
( _
ByVal hWnd As Long, ByVal Msg As Long, wParam As Any, lParam As Any
_
) As Long
Private Declare Function SetWindowSubclass Lib "comctl32" ( _
ByVal hWnd As Long, ByVal pfnSubclass As Long, _
ByVal uIdSubclass As Long, ByVal dwRefData As Long _
) As Long
Private Declare Function DefSubclassProc Lib "comctl32" ( _
ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long _
) As Long
Private Declare Function RemoveWindowSubclass Lib "comctl32" ( _
ByVal hWnd As Long, ByVal pfnSubclass As Long, _
ByVal uIdSubclass As Long _
) As Long
Friend Function WndProc(ByVal hWnd As Long, ByVal uMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case uMsg
Case -2049
Debug.Print "-2049"
Case Else
WndProc = DefSubclassProc(hWnd, uMsg, wParam, lParam)
End Select
End Function
Private Sub Form_Load()
Call SetWindowSubclass(Me.hWnd, AddressOf Module1.WndProc,
ObjPtr(Me), 0&)
Call SendMessage(Me.hWnd, -2049, ByVal 0&, ByVal 0&)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call RemoveWindowSubclass(Me.hWnd, AddressOf Module1.WndProc, _
ObjPtr(Me))
End Sub
'**** MODULE1 ****'
Option Explicit
Public Function WndProc(ByVal hWnd As Long, ByVal uMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long, _
ByVal uIdSubclass As Form1, ByVal dwRefData As Long _
) As Long
WndProc = uIdSubclass.WndProc(hWnd, uMsg, wParam, lParam)
End Function