写一个消息函数TForm1 = class(TForm)
private
//...
//...
    procedure WMQueryEndSession(var Msg: TMessage); message WM_QueryEndSession;
//...
//...
procedure TForm1.WMQueryEndSession(var Msg: TMessage); 
begin
  if MessageBox(Handle, '真的要退出吗?', '关闭 Windows', MB_YESNO) = IDYES then
    Msg.Result := 1
  else
    Msg.Result := 0;
end;