I am in the middle of reading Steve Romans "Win32 API Programming with Visual Basic 6" and i am on to chapter 18 "Windows Subclassing", at the moment i am reading up on the CalWindowProc. I have come with this so far and it does not seem to be working, it is supposed to be a classic example of restricting the size of the form.

VB Code:
  1. ' Module Code
  2. Option Explicit
  3.  
  4. Declare Function CallWindowProc _
  5.     Lib "user32" _
  6.     Alias "CallWindowProcA" ( _
  7.         ByVal lpPrevWndFunc As Long, _
  8.         ByVal hwnd As Long, _
  9.         ByVal Msg As Long, _
  10.         ByVal wParam As Long, _
  11.         ByVal lParam As Long) _
  12.         As Long
  13.        
  14. ' Allows us to set the window style
  15. ' Returns the Procedure address which will
  16. ' be stored in 'OldWindowProc'
  17. Declare Function SetWindowLong _
  18.     Lib "user32" _
  19.     Alias "SetWindowLongA" ( _
  20.         ByVal hwnd As Long, _
  21.         ByVal nIndex As Long, _
  22.         ByVal dwNewLong As Long) _
  23.         As Long
  24.  
  25. ' Returns the cordinates for the
  26. ' mouse
  27. Public Type POINTAPI
  28.         X               As Long
  29.         Y               As Long
  30. End Type
  31.  
  32. ' Holds the sizing information for
  33. ' the form
  34. Private Type MINMAXINFO
  35.     ptReserved          As POINTAPI
  36.     ptMaxSize           As POINTAPI
  37.     ptMaxPosition       As POINTAPI
  38.     ptMinTrackSize      As POINTAPI
  39.     ptMaxTrackSize      As POINTAPI
  40. End Type
  41.  
  42. Const GWL_WNDPROC = (-4)            ' Sets a new procdure address
  43. Const WM_GETMINMAXINFO = &H24       ' Gets the window size information
  44.  
  45. Public OldWindowProc       As Long  ' Holds thw Old Window Address
  46.  
  47. Public Function NewWindowProc(hwnd As Long, Msg As Long, wParam As Long, lParam As MINMAXINFO) As Long
  48.    
  49.     Dim Point       As POINTAPI
  50.    
  51.     ' Check for any messages
  52.     Select Case Msg
  53.        
  54.         ' If the message is a sizeing message
  55.         Case WM_GETMINMAXINFO
  56.            
  57.             ' Limit the form size to the cursor co-ordinates
  58.             With lParam
  59.                 .ptMaxTrackSize.X = Point.X
  60.                 .ptMaxTrackSize.Y = Point.Y
  61.                 .ptMinTrackSize.X = Point.X
  62.                 .ptMinTrackSize.Y = Point.Y
  63.             End With
  64.            
  65.             NewWindowProc = 0
  66.                
  67.         Case Else
  68.            
  69.             ' Call the new Window Procedure
  70.             NewWindowProc = CallWindowProc(OldWindowProc, hwnd, Msg, wParam, lParam)
  71.                
  72.     End Select
  73. End Function
  74.  
  75. ' Form Code
  76.  
  77. Option Explicit
  78.  
  79. Private Sub Form_Load()
  80.     OldWindowProc = SetWindowLong(Form1.hwnd, GWL_WNDPROC, AddressOf NewWindowProc)
  81. End Sub
  82.  
  83.  
  84. Private Sub Form_Unload(Cancel As Integer)
  85.     OldWindowProc = SetWindowLong(Form1.hwnd, GWL_WNDPROC, OldWindowProc)
  86. End Sub

However, when i run the code it does not seem to work, i have tried other methods such as setting the form size to a specific height and width but it still does not seem to work. From what i have made out so far it it looks as though my application can not process the message and i am quite confident that this is the issue. Can you guys give me any hints as to where the problem lies and how i might be able to fix it?

Regards,

Jenova