Hi all,
I would like to know if it is possible to use WndProc in a module instead of using it at a form level.
The following code is functional at form-level but, can we put it somewhere Global like Module etc.
*****************************************
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Static first_time As Boolean = True
Static aspect_ratio As Double
Const WM_SIZING As Long = &H214
Const WMSZ_LEFT As Integer = 1
Const WMSZ_RIGHT As Integer = 2
Const WMSZ_TOP As Integer = 3
Const WMSZ_TOPLEFT As Integer = 4
Const WMSZ_TOPRIGHT As Integer = 5
Const WMSZ_BOTTOM As Integer = 6
Const WMSZ_BOTTOMLEFT As Integer = 7
Const WMSZ_BOTTOMRIGHT As Integer = 8
If m.Msg = WM_SIZING And m.HWnd.Equals(Me.Handle) Then
Dim r As Rect
r = DirectCast(Marshal.PtrToStructure(m.LParam, GetType(Rect)), Rect)
Dim wid As Double = r.right - r.left
Dim hgt As Double = r.bottom - r.top
If first_time Then
first_time = False
aspect_ratio = (r.bottom - r.top) / (r.right - r.left)
prevHt = hgt
prevWid = wid
End If
If prevWid <> wid Then
hgt = wid * aspect_ratio
ElseIf prevHt <> hgt Then
wid = hgt / aspect_ratio
End If
prevHt = hgt
prevWid = wid
If m.WParam.ToInt32 = WMSZ_TOP Or m.WParam.ToInt32 = WMSZ_TOPLEFT Or m.WParam.ToInt32 = WMSZ_TOPRIGHT Then
r.top = r.bottom - CInt(hgt)
Else
r.bottom = r.top + CInt(hgt)
End If
If m.WParam.ToInt32 = WMSZ_LEFT Or m.WParam.ToInt32 = WMSZ_TOPLEFT Or m.WParam.ToInt32 = WMSZ_BOTTOMLEFT Then
r.left = r.right - CInt(wid)
Else
r.right = r.left + CInt(wid)
End If
Marshal.StructureToPtr(r, m.LParam, True)
End If
MyBase.WndProc(m)
End Sub
*****************************************
Thanks in advance
a_k93




Reply With Quote