- fixed the bug related to the redrawing on resize introduced in 2.3.2
- added static wxFontMapper::Get() accessor (use of wxTheFontMapper is now
deprecated)
+- added wxShutdown() function (Marco Cavallini)
Unix (Base/GUI):
\helpref{wxSetWorkingDirectory}{wxsetworkingdirectory}\\
\helpref{wxShell}{wxshell}\\
\helpref{wxShowTip}{wxshowtip}\\
+\helpref{wxShutdown}{wxshutdown}\\
\helpref{wxSleep}{wxsleep}\\
\helpref{wxSnprintf}{wxsnprintf}\\
\helpref{wxSplitPath}{wxsplitfunction}\\
<wx/utils.h>
+\membersection{::wxShutdown}\label{wxshutdown}
+
+\func{bool}{wxShutdown}{\param{wxShutdownFlags}{flags}}
+
+This function shuts down or reboots the computer depending on the value of the
+{\it flags}. Please notice that doing this requires the corresponding access
+rights (superuser under Unix, {\tt SE\_SHUTDOWN} privelege under Windows NT)
+and that this function is only implemented under Unix and Win32.
+
+\wxheading{Parameters}
+
+\docparam{flags}{Either {\tt wxSHUTDOWN\_POWEROFF} or {\tt wxSHUTDOWN\_REBOOT}}
+
+\wxheading{Returns}
+
+{\tt TRUE} on success, {\tt FALSE} if an error occured.
+
+\wxheading{Include files}
+
+<wx/utils.h>
\section{Thread functions}\label{threadfunctions}
wxKILL_ERROR // another, unspecified error
};
+enum wxShutdownFlags
+{
+ wxSHUTDOWN_POWEROFF, // power off the computer
+ wxSHUTDOWN_REBOOT // shutdown and reboot
+};
+
+// Shutdown or reboot the PC
+WXDLLEXPORT bool wxShutdown(wxShutdownFlags wFlags);
+
// send the given signal to the process (only NONE and KILL are supported under
// Windows, all others mean TERM), return 0 if ok and -1 on error
//
return FALSE;
}
+// Shutdown or reboot the PC
+bool wxShutdown(wxShutdownFlags wFlags)
+{
+ // TODO
+ return FALSE;
+}
+
// Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
long wxGetFreeMemory()
{
return FALSE;
}
+// Shutdown or reboot the PC
+bool wxShutdown(wxShutdownFlags wFlags)
+{
+ // TODO
+ return FALSE;
+}
+
// Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
long wxGetFreeMemory()
{
return 0;
}
}
-#else // Win15
+#else // Win16
wxFAIL_MSG( _T("not implemented") );
#endif // Win32/Win16
return wxExecute(cmd, TRUE /* sync */) != 0;
}
+// Shutdown or reboot the PC
+bool wxShutdown(wxShutdownFlags wFlags)
+{
+#ifdef __WIN32__
+ bool bOK = TRUE;
+
+ if ( wxGetOsVersion(NULL, NULL) == wxWINDOWS_NT ) // if is NT or 2K
+ {
+ // Get a token for this process.
+ HANDLE hToken;
+ bOK = ::OpenProcessToken(GetCurrentProcess(),
+ TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
+ &hToken) != 0;
+ if ( bOK )
+ {
+ TOKEN_PRIVILEGES tkp;
+
+ // Get the LUID for the shutdown privilege.
+ ::LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
+ &tkp.Privileges[0].Luid);
+
+ tkp.PrivilegeCount = 1; // one privilege to set
+ tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
+
+ // Get the shutdown privilege for this process.
+ ::AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
+ (PTOKEN_PRIVILEGES)NULL, 0);
+
+ // Cannot test the return value of AdjustTokenPrivileges.
+ bOK = ::GetLastError() == ERROR_SUCCESS;
+ }
+ }
+
+ if ( bOK )
+ {
+ UINT flags = EWX_SHUTDOWN | EWX_FORCE;
+ switch ( wFlags )
+ {
+ case wxSHUTDOWN_POWEROFF:
+ flags |= EWX_POWEROFF;
+ break;
+
+ case wxSHUTDOWN_REBOOT:
+ flags |= EWX_REBOOT;
+ break;
+
+ default:
+ wxFAIL_MSG( _T("unknown wxShutdown() flag") );
+ return FALSE;
+ }
+
+ bOK = ::ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE | EWX_REBOOT, 0) != 0;
+ }
+
+ return bOK;
+#else // Win16
+ return FALSE;
+#endif // Win32/16
+}
+
// ----------------------------------------------------------------------------
// misc
// ----------------------------------------------------------------------------
static wxChar buffer[512];
if (!wxTheApp->GetWantDebugOutput())
- return ;
+ return;
va_start(ap, fmt);
- wvsprintf(buffer,fmt,ap) ;
- OutputDebugString((LPCTSTR)buffer) ;
+ wvsprintf(buffer,fmt,ap);
+ OutputDebugString((LPCTSTR)buffer);
va_end(ap);
}
return (rc != 0);
}
+// Shutdown or reboot the PC
+bool wxShutdown(wxShutdownFlags wFlags)
+{
+ // TODO
+ return FALSE;
+}
+
// Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
long wxGetFreeMemory()
{
return wxExecute(wxMakeShellCommand(command), output);
}
+// Shutdown or reboot the PC
+bool wxShutdown(wxShutdownFlags wFlags)
+{
+ wxChar level;
+ switch ( wFlags )
+ {
+ case wxSHUTDOWN_POWEROFF:
+ level = _T('0');
+ break;
+
+ case wxSHUTDOWN_REBOOT:
+ level = _T('6');
+ break;
+
+ default:
+ wxFAIL_MSG( _T("unknown wxShutdown() flag") );
+ return FALSE;
+ }
+
+ return system(wxString::Format(_T("init %c"), level).mb_str()) == 0;
+}
+
+
#if wxUSE_GUI
void wxHandleProcessTermination(wxEndProcessData *proc_data)