VB Code:
  1. '************************************************************************************************
  2. '* Name             Function SubClass
  3. '*
  4. '* Author          
  5. '*
  6. '* Purpose          This function instructs Windows to redirect the Window Procedure of a
  7. '*                  given control to a custom procedure.
  8. '*
  9. '*                  The function creates (sets) a property of the given Wnd called 'OldWndProc'
  10. '*                  This ensures that the window retains it's own state with regard to its
  11. '*                  original Window Procedure.
  12. '*
  13. '* Parameters       --> hWnd        LONG       The handle of the window to be subclassed
  14. '*                  --> lpfnNew     LONG       Address of function of which to redirect the
  15. '*                                             the standard WndProc too.
  16. '*
  17. '* Version  14/02/2002          Created
  18. '*
  19. '************************************************************************************************
  20. Public Function SubClass(hwnd As Long, lpfnNew As Long) As Boolean
  21.  
  22.     Dim lpfnOld As Long
  23.     Dim fSuccess As Boolean
  24.    
  25.     '*************************************************************
  26.     '* If we haven't set the property for this window before . . .
  27.     '*************************************************************
  28.     If (GetProp(hwnd, OLDWNDPROC) = 0) Then
  29.    
  30.         '*****************************************
  31.         '* Redirect Windows Proc to New Proc . . .
  32.         '*****************************************
  33.         lpfnOld = SetWindowLong(hwnd, GWL_WNDPROC, lpfnNew)
  34.        
  35.         '**********************************************************
  36.         '* Set Old Proc Address to the property of the window . . .
  37.         '**********************************************************
  38.         If lpfnOld Then
  39.             fSuccess = SetProp(hwnd, OLDWNDPROC, lpfnOld)
  40.         End If
  41.        
  42.     End If
  43.  
  44.     '*************************************
  45.     '* Did we subclass successfully . . .
  46.     '*************************************
  47.     If fSuccess Then
  48.         SubClass = True
  49.     Else
  50.         '*************************************************
  51.         '* If we have the old proc address,
  52.         '* and still have failed, remove redirection . . .
  53.         '*************************************************
  54.         If lpfnOld Then
  55.             Call UnSubClass(hwnd)
  56.         End If
  57.        
  58.         '* Oh **** !!
  59.         MsgBox "Unable to successfully subclass " & hwnd, vbCritical
  60.        
  61.     End If
  62.  
  63. End Function
  64.  
  65.  
  66. '************************************************************************************************
  67. '* Name             Function UnSubClass
  68. '*
  69. '* Author          
  70. '*
  71. '* Purpose          This function removes the OldWndProc property of the hWnd, and resets the
  72. '*                  Window Procedure back to the original.
  73. '*
  74. '*                  See Function SubClass
  75. '*
  76. '* Parameters       --> hWnd        LONG       The handle of the window to be subclassed
  77. '*
  78. '* Version  14/02/2002           Created
  79. '*
  80. '************************************************************************************************
  81. Public Function UnSubClass(hwnd As Long) As Boolean
  82.  
  83.     Dim lpfnOld As Long
  84.  
  85.     '**********************************
  86.     '* Can we get Window property . . .
  87.     '**********************************
  88.     lpfnOld = GetProp(hwnd, OLDWNDPROC)
  89.    
  90.     '*************************************************************
  91.     '* If we have property, remove it, and return Window Proc to
  92.     '* original . . .
  93.     '*************************************************************
  94.     If lpfnOld Then
  95.         If RemoveProp(hwnd, OLDWNDPROC) Then
  96.             UnSubClass = SetWindowLong(hwnd, GWL_WNDPROC, lpfnOld)
  97.         End If
  98.     End If
  99.  
  100. End Function
  101.  
  102.  
  103. '************************************************************************************************
  104. '* Name             Function GridWndProc
  105. '*
  106. '* Author          
  107. '*
  108. '* Purpose          SubClass function for Windows Procedure redirection. Use only for the
  109. '*                  FlexGrid.
  110. '*
  111. '*                  See Function SubClass
  112. '*
  113. '* Parameters       --> See MSDN Documentation
  114. '*
  115. '* Version  14/02/2002           Created
  116. '*
  117. '************************************************************************************************
  118. Public Function NewWndProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
  119.    
  120.     Dim uCDS As COPYDATASTRUCT
  121.     Dim uData() As Byte
  122.     Dim oPb As PropertyBag
  123.    
  124.     Select Case uMsg
  125.        
  126.         Case WM_COPYDATA
  127.            
  128.             '*************************************
  129.             '* Retrieve Copy Data Structure . . .
  130.             '*************************************
  131.             CopyMemory uCDS, ByVal lParam, Len(uCDS)
  132.             ReDim uData(uCDS.cbData)
  133.             CopyMemory uData(0), ByVal uCDS.lpData, uCDS.cbData
  134.            
  135.             Set oPb = New PropertyBag
  136.             oPb.Contents = uData
  137.            
  138.             Select Case uCDS.dwData
  139.                 Case BM_CURRENCY
  140.                     gEnv.CurrencyCode = oPb.ReadProperty("Code")
  141.                     gEnv.CurrencyExchange = oPb.ReadProperty("ExchangeRate")
  142.                    
  143.             End Select
  144.            
  145.             Set oPb = Nothing
  146.            
  147.     End Select
  148.  
  149.     '************************************************************
  150.     '* Carry on processing in the original Window Procedure . . .
  151.     '************************************************************
  152.     NewWndProc = CallWindowProc(GetProp(hwnd, OLDWNDPROC), hwnd, uMsg, wParam, lParam)
  153.  
  154.    
  155. End Function

and an example of how to send . . .

VB Code:
  1. Private Sub SendCurrency(lHWnd As Long, uCurrency As CURRENCY_EX)
  2.  
  3.     On Error GoTo ERR_SendCurrency
  4.    
  5.     Dim oPacket As PropertyBag
  6.     Dim uCopyData As COPYDATASTRUCT
  7.     Dim Stream() As Byte
  8.    
  9.     Set oPacket = New PropertyBag
  10.    
  11.     With oPacket
  12.    
  13.         .WriteProperty ("Code"), uCurrency.Code
  14.         .WriteProperty ("Description"), uCurrency.Description
  15.         .WriteProperty ("ExchangeRate"), uCurrency.ExchangeRate
  16.         .WriteProperty ("Format"), uCurrency.Format
  17.         .WriteProperty ("IsValid"), uCurrency.IsValid
  18.        
  19.         Stream = .Contents
  20.        
  21.     End With
  22.    
  23.     With uCopyData
  24.         .dwData = BM_CURRENCY
  25.         .cbData = UBound(Stream) - LBound(Stream) + 1
  26.         .lpData = VarPtr(Stream(LBound(Stream)))
  27.     End With
  28.    
  29.     SendMessageA lHWnd, WM_COPYDATA, 0&, uCopyData
  30.    
  31.     Set oPacket = Nothing
  32.     Exit Sub
  33.    
  34. ERR_SendCurrency:
  35.     Set oPacket = Nothing
  36. End Sub