I have a form and if it is closed, I do some cleaning up.
I have that 'cleaning up' function stored under the forms WM_CLOSE message handler.
It worked fine when the form was/is closed using the standard "X" in the upper right hand corner of the window.
Now I added an extra 'Close' button on the form to close it and put the FF_CloseForm function under the button, since this is the recommended FF way to close a form.
To my surprise, when pressing the 'Close' button, the cleaning up function is not executed.
Apparantly, FF_CloseForm does not generate a WM_CLOSE message.
No big deal, I generate it myself (see code below), but you just have to know it ... :)
Function TBSTOCKS_CMDCLOSE_BN_CLICKED ( _
ControlIndex As Long, _ ' index in Control Array
hWndForm As Dword, _ ' handle of Form
hWndControl As Dword, _ ' handle of Control
idButtonControl As Long _ ' identifier of button
) As Long
'FF_CloseForm does not send a wm_close message to the form, so I send it myself
SendMessage hWndForm, %WM_CLOSE, 0, 0
FF_CloseForm hWndForm, %TRUE
End Function
On the other hand. Only sending the WM_CLOSE (without using FF_CloseForm) also works.
Would that be safe..?
FF_CloseForm uses DestroyWindow, which sends the WM_DESTROY message. Therefore, if you use it, move the cleaning code to the WM_DESTROY message processing instead of WM_CLOSE.
Thanks Jose
:-)
Thanks, Jose, but I need to fetch the window position and size to restore it later.
WM_DESTROY message is generated when the window is already removed, so I cannot fetch pos. and size anymore.
Maybe I should put
My_Cleanup_function
FF_CloseForm
under my 'Close' button.
And put
My_Cleanup_function
under the WM_CLOSE message.
That said, when a child form is closed by clicking the standard "X" button (or by ALT-F4), is the FF_CloseForm function then executed?
> WM_DESTROY message is generated when the window is already removed, so I cannot fetch pos. and size anymore.
Wrong assumption. The window and the child controls still exist, otherwise you could not receive the message. In my editor, I save the size and placement during WM_DESTROY.
Jose, you are right.
I did this:
Function TBSTOCKS_CUSTOM ( _
hWndForm As Dword, _ ' handle of Form
wMsg As Long, _ ' type of message
wParam As Dword, _ ' first message parameter
lParam As Long _ ' second message parameter
) As Long
Local iX, iY, iW, iH As Long
Select Case wMsg
Case %WM_DESTROY
FF_Control_GetLoc( hWndForm, iX, iY )
FF_Control_GetSize( hWndForm, iW, iH )
MsgBox Str$(iX) + Str$(iY) + Str$(iW) + Str$(iH)
End Select
End Functionand the coordinates are displayed when the window is closed.
I was misled by this description in the
Win32 Programmer's Reference help file:
QuoteThe WM_DESTROY message is sent when a window is being destroyed. It is sent to the window procedure of the window being destroyed after the window is removed from the screen.