In VB there is a QueryUnload event on forms that I can place code in to see how the app is being closed (ie - Windows is closing it, application menu is closing it, etc...). It also allows you to Cancel the shutdown.
I need something like this in FF for an app I am working on. I don't want the user clicking the X button on the caption bar while my app is in the middle of an operation. How do I prevent a user from shutting down my app when I don't want them to?
TIA
Paul has all the messages going through WM_CLOSE, that way you don't need to catch Alt+F4 or the Menu in two different messages, so if they push Alt+F4 or close it through any system menu you will get that message. As for windows closing it...not sure which method you mean there. If you mean like End Tasking something, there is no message sent for that, hence why it tells you there is a chance of data loss, etc. You app is just killed, end of story. If you mean when Windows is shutting down there are EndSession and QueryEndSession messages there, but depending on the OS you either can, cannot, or might stop the Shutdown.
In my own Apps I use the following code in the Form WM_CLOSE command to check if the X has been clicked.
Hope it is relavent.
Select Case wMsg
Case %WM_SYSCOMMAND
If (wParam And %SC_CLOSE) = %SC_CLOSE Then
'Place your own code here
'If Ok to exit then Function = 0
'If not Ok to exit then Function = 1
End If
End Select
Gian Young
Dataman Australia
Paul uses this:
Case %WM_SYSCOMMAND
If (wParam And &HFFF0) = %SC_CLOSE Then
SendMessage hWndForm, %WM_CLOSE, wParam, lParam
Exit Function
End If
That way it all goes through one message. And &HFFF0 is needed cause Windows uses the lower bits for something.
Returning True would normally be needed, but the call to the DefProc is at the end of the function, so Exiting blocks calling it.
Hi Gian,
That looks like what I am looking for except for one problem... When I look at the WM_CLOSE event on the form there is no message parameter being passed in. Here's what my WM_CLOSE looks like in FF:
FUNCTION FRMMAIN_WM_CLOSE ( _
hWndForm AS DWORD _ ' handle of Form
) AS LONG
END FUNCTION
The only passed in value is the form handle. What am I missing? Sorry if this is really obvious but when you're a newbie coming from the VB world, everything seems so strange and different.
TIA
Gian must be processing the close through the CUSTOM handler. You see, all messages flow through the CUSTOM handler and it allows you to select whatever message you want to respond to. That is why you would use a Select Case to filter out the message that you want.
In addition, FireFly presents you with separate message handlers (i.e WM_CLOSE) for some messages, not alll messages. This is done merely for convenience and ease of separating your code.
Actually, there is no reason why you could not process everything through the CUSTOM handler. I believe that Roger uses that approach a fair amount.
Thanks all for your replies. The solution involved borrowing a little from several of your responses. Works great now. Thanks!
Hi Art,
My apologies for the lack of clarity of my earlier response. I am placing this code in the Forms Custom Handler.
Paul fortunately filled in the missing information correctly.
Regards
Gian
Australia