 |
|
 |
Vpa Level: Sage

 Registered: 14-03-2004 Posts: 66
|
Detecting Unload
The most dull question ever, you may think. But I do have problems with it.
How do you detect when your program unloads?
In my case it is closed using Taskmanager, the other ways work fine with Form_Unload. The form is not visible
The Form_Unload event isn't fired , and when I'm subclassing my form I only get one event, And that one is in the beginning. 
I believe I'm doing something wrong with the Subclassing, here's my code:
Private 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
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Const GWL_WNDPROC = (-4)
Dim m_Hwnd As Long
Dim PrevProc As Long
Public Sub Hook(ByVal hWnd As Long)
If m_Hwnd <> 0 Then Unhook
m_Hwnd = hWnd
PrevProc = SetWindowLong(m_Hwnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
Public Sub Unhook()
SetWindowLong m_Hwnd, GWL_WNDPROC, PrevProc
m_Hwnd = 0
End Sub
Private Function WindowProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Open "tmp.txt" For Append As #1
Print #1, uMsg
Close #1
WindowProc = CallWindowProc(PrevProc, hWnd, uMsg, wParam, lParam)
End Function
|
|
|
16-11-2005 at 11:31 AM |
|
|
JLRodgers Level: Moderator
 Registered: 04-04-2002 Posts: 1658
|
Re: Detecting Unload
If you actually "terminate the process" then I don't think you will be notified in-program (the purpose for the most part is to kill a non-responsive program, in a worst-case-senario).
If you really want to know if that happens... I think you'd have to have 2 programs running, both monitoring if the other's closed, and if so do whatever's needed (like a virus does).
____________________________
Everywhere's Local (classifieds, job postings, & more for everycity in the world - user entered)
|
|
16-11-2005 at 08:12 PM |
|
|
|
|
 |
 |