Or if you want to stick with your current method I've got the API working that disables the maximise function.

Here is a full example, including your original code (which I had to edit slightly because you have not got Option Strict turned on - I would recommend you turn it on) :

vb Code:
  1. Public Class Form1
  2.  
  3.     Const WS_MAXIMIZEBOX As Integer = &H10000
  4.     Const GWL_STYLE As Integer = -16
  5.     Const WM_NCHITTEST As Integer = &H84
  6.     Const HTCLIENT As Integer = &H1
  7.     Const HTCAPTION As Integer = &H2
  8.  
  9.     <System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint:="SetWindowLong")> _
  10.     Public Shared Function SetWindowLong(<System.Runtime.InteropServices.InAttribute()> ByVal hWnd As System.IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As UInt64) As Integer
  11.     End Function
  12.  
  13.     <System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint:="GetWindowLong")> _
  14.     Public Shared Function GetWindowLong(<System.Runtime.InteropServices.InAttribute()> ByVal hWnd As System.IntPtr, ByVal nIndex As Integer) As UInt64
  15.     End Function
  16.  
  17.     'Example in a button click event - form load event may be more appropriate
  18.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  19.         'Get the current window settings
  20.         Dim Result As UInt64 = GetWindowLong(Me.Handle, GWL_STYLE)
  21.         'Specify that we do not want the maximize box
  22.         Result = (Result And Not CULng(WS_MAXIMIZEBOX))
  23.         'Apply the new settings to the window
  24.         SetWindowLong(Me.Handle, GWL_STYLE, Result)
  25.  
  26.     End Sub
  27.  
  28.     Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
  29.         Select Case m.Msg
  30.             Case WM_NCHITTEST
  31.                 MyBase.WndProc(m)
  32.                 If CInt(m.Result) = HTCLIENT Then
  33.                     m.Result = New IntPtr(HTCAPTION)
  34.                 End If
  35.             Case Else
  36.                 'Make sure you pass unhandled messages back to the default message handler.
  37.                 MyBase.WndProc(m)
  38.         End Select
  39.     End Sub
  40.  
  41. End Class