我自己写一个程序,当关机或在任务管理器中终止进程来杀死程序时,我想写一段程序被关闭的日志。这个代码应该写在哪一部分?finalization里我写过不行。请给出代码例子!谢谢!
解决方案 »
- 将以下C#代码转换为DELPHI的··
- DateTimePicker 的问题
- 皮肤控件(skindata)与opendialog控件有冲突怎么办?一旦有皮肤控件(skindata)那么执行opendialog.Execute就出错!
- 我想知道一些普通加密算法的实现.
- 请问达人们哪里可以下delphi的控件的参考手册的.能否顺便讲讲OleVariant的作用,属性呢?谢谢!
- Dll释放问题
- delphi简单问题
- 紧急求救: 中了恶性病毒,如何手工删除,(斑竹别删啊)
- 帮忙看看下面的程序?为什么查询不出结果呢?
- 大家做程序时,是否都进行了需求分析这一步骤?
- 简单好赚分:updown不起作用,有什么原因吗?
- TTable数据排序的问题。
強制弒死進程, 并不能保證系統會執行相應的清除協作!>>当关机或在任务管理器中终止进程来
應該會發個WM_CLOSE的消息給程度, 如果程序接收處理, 就象你按右上角關閉按鈕一樣!
如果程序沒處理, 超時就會強制結束, 那麼, 應該什麼清除工作的代碼都不會執行的所以,小心使用!
ParametersThis message has no parameters. Return ValuesIf an application processes this message, it should return zero. Default ActionThe DefWindowProc function calls the DestroyWindow function to destroy the window. ResAn application can prompt the user for confirmation, prior to destroying a window, by processing the WM_CLOSE message and calling the DestroyWindow function only if the user confirms the choice.
The WM_QUERYENDSESSION message is sent when the user chooses to end the Windows session or when an application calls the ExitWindows function. If any application returns zero, the Windows session is not ended. Windows stops sending WM_QUERYENDSESSION messages as soon as one application returns zero. After processing this message, Windows sends the WM_ENDSESSION message with the wParam parameter set to the results of the WM_QUERYENDSESSION message. WM_QUERYENDSESSION
nSource = (UINT) wParam; // source of end-session request
fLogOff = lParam // logoff flag
ParametersnSourceReserved for future use. fLogOffValue of lParam. Indicates whether the user is logging off or shutting down the system. Supported values include: ENDSESSION_LOGOFF. Return ValuesIf an application can terminate conveniently, it should return TRUE; otherwise, it should return FALSE. ResBy default, the DefWindowProc function returns TRUE for this message.
Windows NT: When an application returns TRUE for this message, it receives the WM_ENDSESSION message and it is terminated, regardless of how the other applications respond to the WM_QUERYENDSESSION message.
Windows 95: After all applications return TRUE for this message, they receive the WM_ENDSESSION and they are terminated. See AlsoDefWindowProc, ExitWindows, WM_ENDSESSION
private
procedure WMQueryEndSession (var Msg : TWMQueryEndSession); message WM_QueryEndSession;
end; Implementation procedure TForm1.WMQueryEndSession (var Msg : TWMQueryEndSession);
begin
if MessageDlg('Close Windows now/ Windows beenden?',
mtConfirmation,
[mbYes,mbNo], 0) = mrNo then
Msg.Result := 0
else
Msg.Result := 1;
end;
所以建议你做个守护进程,由它来CreateProcess以执行你的程序,并且用WaitForSingleObject函数一直监视获得的进程句柄,当WaitForSingleObject return时采取措施。
http://community.csdn.net/Expert/topic/3240/3240265.xml?temp=.6537744另给分。谢谢帮助!