Paul, im trying to intercept and cancel the %WM_QUERYENDSESSION, i want to restrict who shuts
down the PC. Unfortunately seems like Firefly doesnt allow me to return a null value, it seems like
it gets overwritten with DefWindowProc() with a %TRUE value...
Any ideas?
Hi Elias,
This is a problem message because of the return values that the message returns is opposite to the logic that FireFly employs in the generated code to signify that the code has been processed by the user and therefore bypass the default Windows processing.
Having said that, the message can be dealt with correctly but you need to do a little bit more work. Essentially, you need to subclass the main Form of your application and handle the WM_QUERYENDSESSION in the subclassed procedure. All other messages are sent to FireFly's Form procedure.
Here is the code you need to do the job. Notice that I am using three subclass helper functions (they are part of FireFly 3). :)
'------------------------------------------------------------------------------------------------------------------------
Function FRMQUERYEND_WM_CREATE ( _
hWndForm As Dword, _ ' handle of Form
ByVal UserData As Long _ 'optional user defined Long value
) As Long
' Subclass the main form of the application
FF_SubClassStart hWndForm, CodePtr(NewFormProc)
End Function
'------------------------------------------------------------------------------------------------------------------------
Function FRMQUERYEND_WM_DESTROY ( _
hWndForm As Dword _ ' handle of Form
) As Long
' Reset the original windows procedure
FF_SubClassEnd hWndForm
End Function
'------------------------------------------------------------------------------------------------------------------------
Function NewFormProc( ByVal hWndForm As Dword, _
ByVal wMsg As Dword, _
ByVal wParam As Dword, _
ByVal lParam As Long _
) As Long
' Only handle the one message that we are interested in and
' send all other messages to FireFly's code generated window procedure.
Select Case wMsg
Case %WM_QUERYENDSESSION
Function = %FALSE ' prevent application from closing when Windows ends
Exit Function
Case Else
Function = FF_SubClassOrig( hWndForm, wMsg, wParam, lParam )
End Select
End Function
'------------------------------------------------------------------------------------------------------------------------
Function FF_SubClassStart( ByVal hWndControl As Dword, _
ByVal hNewProc As Dword _
) As Long
Local hOrigProc As Dword
hOrigProc = SetWindowLong( hWndControl, %GWL_WNDPROC, hNewProc )
SetWindowLong hWndControl, %GWL_USERDATA, hOrigProc
End Function
'------------------------------------------------------------------------------------------------------------------------
Function FF_SubClassEnd( ByVal hWndControl As Dword ) As Long
Local hOrigProc As Dword
hOrigProc = GetWindowLong( hWndControl, %GWL_USERDATA )
SetWindowLong hWndControl, %GWL_WNDPROC, hOrigProc
End Function
'------------------------------------------------------------------------------------------------------------------------
Function FF_SubClassOrig( ByVal hWndControl As Dword, _
ByVal wMsg As Dword, _
ByVal wParam As Long, _
ByVal lParam As Long _
) As Long
Local hOrigProc As Dword
hOrigProc = GetWindowLong( hWndControl, %GWL_USERDATA )
Function = CallWindowProc( hOrigProc, hWndControl, wMsg, wParam, lParam )
End Function
Thank you very much Paul!
Looking forward testing Firefly 3. :)
In one of my apps I think I handled it in PumpHook Special function. DDT in Forms has the same issue. This is one of the few API calls that expects a backwards return value and most designers are coded to see 0 as pass to DefProc.