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:
Public Class Form1 Const WS_MAXIMIZEBOX As Integer = &H10000 Const GWL_STYLE As Integer = -16 Const WM_NCHITTEST As Integer = &H84 Const HTCLIENT As Integer = &H1 Const HTCAPTION As Integer = &H2 <System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint:="SetWindowLong")> _ Public Shared Function SetWindowLong(<System.Runtime.InteropServices.InAttribute()> ByVal hWnd As System.IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As UInt64) As Integer End Function <System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint:="GetWindowLong")> _ Public Shared Function GetWindowLong(<System.Runtime.InteropServices.InAttribute()> ByVal hWnd As System.IntPtr, ByVal nIndex As Integer) As UInt64 End Function 'Example in a button click event - form load event may be more appropriate Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Get the current window settings Dim Result As UInt64 = GetWindowLong(Me.Handle, GWL_STYLE) 'Specify that we do not want the maximize box Result = (Result And Not CULng(WS_MAXIMIZEBOX)) 'Apply the new settings to the window SetWindowLong(Me.Handle, GWL_STYLE, Result) End Sub Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message) Select Case m.Msg Case WM_NCHITTEST MyBase.WndProc(m) If CInt(m.Result) = HTCLIENT Then m.Result = New IntPtr(HTCAPTION) End If Case Else 'Make sure you pass unhandled messages back to the default message handler. MyBase.WndProc(m) End Select End Sub End Class





Reply With Quote