Hello,
I am trying to subclass a form in order to catch the event that occurs when the caption bar of the form is double clicked. The reason for this is that I want to maximize the form when double clicking the caption bar but within the confines of the client area of the main Access window.
In order to achieve this I have a standard module with the following code:
Within the code moule of the form I use the Form_Load and Form_Unload
events as follows:
The problem is that when I open the form, the application freezes
and becomes unresponsive.
Could you please tell me what is it that I am doing wrong?
I am using the attached mdb file with MS Access 2003.
Thank you very much in advance!
Best Regards
I am trying to subclass a form in order to catch the event that occurs when the caption bar of the form is double clicked. The reason for this is that I want to maximize the form when double clicking the caption bar but within the confines of the client area of the main Access window.
In order to achieve this I have a standard module with the following code:
Code:
Type Trect
left As Long
top As Long
Right As Long
Bottom As Long
End Type
Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Declare Function GetClientRect Lib "user32.dll" (ByVal HWindow As Long, lpRect As Trect) As Boolean
Declare Function MoveWindow Lib "user32.dll" (ByVal HWindow As Long, ByVal X As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Boolean) As Boolean
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Global Const WM_NCLBUTTONDBLCLK = &HA3
Global Const HTCAPTION = 2
Global Const GWL_WNDPROC = (-4&)
Public lngDefaultProc As Long
Public Function MyProc(ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim lngParent As Long
Dim lngReturn As Long
Dim lngWidth As Long
Dim lngHeight As Long
Dim rct As Trect
On Error Resume Next
If msg = WM_NCLBUTTONDBLCLK And wParam = HTCAPTION Then
lngParent = GetParent(hwnd)
If lngParent <> 0 Then
lngReturn = GetClientRect(lngParent, rct)
If lngReturn <> 0 Then
lngWidth = rct.Right - rct.left
lngHeight = rct.Bottom - rct.top
lngReturn = MoveWindow(hwnd, rct.left, rct.top, lngWidth, lngHeight, -1)
MyProc = 0
Exit Function
End If
End If
End If
MyProc = CallWindowProc(lngDefaultProc, hwnd, msg, wParam, lParam)
End Function
Within the code moule of the form I use the Form_Load and Form_Unload
events as follows:
Code:
Private Sub Form_Load()
lngDefaultProc = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf MyProc)
DoEvents
End Sub
Private Sub Form_Unload(Cancel As Integer)
If lngDefaultProc <> 0 Then
Call SetWindowLong(Me.hwnd, GWL_WNDPROC, lngDefaultProc)
lngDefaultProc = 0
End If
End Sub
The problem is that when I open the form, the application freezes
and becomes unresponsive.
Could you please tell me what is it that I am doing wrong?
I am using the attached mdb file with MS Access 2003.
Thank you very much in advance!
Best Regards