#endif
#endif
-// 260 was taken from windef.h
-#ifndef MAX_PATH
- #define MAX_PATH 260
-#endif
+// For wxKillAllChildren
+#include <tlhelp32.h>
// ----------------------------------------------------------------------------
// constants
bool wxGetHostName(wxChar *buf, int maxSize)
{
#if defined(__WXWINCE__)
- return FALSE;
+ return false;
#elif defined(__WIN32__) && !defined(__WXMICROWIN__)
DWORD nSize = maxSize;
if ( !::GetComputerName(buf, &nSize) )
{
wxLogLastError(wxT("GetComputerName"));
- return FALSE;
+ return false;
}
- return TRUE;
+ return true;
#else
wxChar *sysname;
const wxChar *default_host = wxT("noname");
} else
wxStrncpy(buf, sysname, maxSize - 1);
buf[maxSize] = wxT('\0');
- return *buf ? TRUE : FALSE;
+ return *buf ? true : false;
#endif
}
{
wxStrncpy(buf, host, maxSize);
- return TRUE;
+ return true;
}
}
}
bool wxGetUserId(wxChar *buf, int maxSize)
{
#if defined(__WXWINCE__)
- return FALSE;
+ return false;
#elif defined(__WIN32__) && !defined(__WXMICROWIN__)
DWORD nSize = maxSize;
if ( ::GetUserName(buf, &nSize) == 0 )
if ( res == 0 )
{
// not found
- return FALSE;
+ return false;
}
}
- return TRUE;
+ return true;
#else // __WXMICROWIN__
wxChar *user;
const wxChar *default_id = wxT("anonymous");
wxStrncpy(buf, user, maxSize - 1);
}
- return *buf ? TRUE : FALSE;
+ return *buf ? true : false;
#endif
}
bool wxGetUserName(wxChar *buf, int maxSize)
{
#if defined(__WXWINCE__)
- return FALSE;
+ return false;
#elif defined(USE_NET_API)
CHAR szUserName[256];
if ( !wxGetUserId(szUserName, WXSIZEOF(szUserName)) )
- return FALSE;
+ return false;
// TODO how to get the domain name?
CHAR *szDomain = "";
WideCharToMultiByte( CP_ACP, 0, ui2->usri2_full_name, -1,
buf, maxSize, NULL, NULL );
- return TRUE;
+ return true;
error:
wxLogError(wxT("Couldn't look up full user name."));
- return FALSE;
+ return false;
#else // !USE_NET_API
// Could use NIS, MS-Mail or other site specific programs
// Use wxWidgets configuration data
}
#endif // Win32/16
- return TRUE;
+ return true;
}
const wxChar* wxGetHomeDir(wxString *pstr)
}
else // fall back to the program directory
{
- wxString strPath;
- ::GetModuleFileName(::GetModuleHandle(NULL),
- wxStringBuffer(strPath, MAX_PATH), MAX_PATH);
-
- // extract the dir name
- wxSplitPath(strPath, &strDir, NULL, NULL);
+ // extract the directory component of the program file name
+ wxSplitPath(wxGetFullModuleName(), &strDir, NULL, NULL);
}
#endif // UNIX/Win
bool wxGetDiskSpace(const wxString& path, wxLongLong *pTotal, wxLongLong *pFree)
{
#ifdef __WXWINCE__
- return FALSE;
+ return false;
#else
if ( path.empty() )
- return FALSE;
+ return false;
// old w32api don't have ULARGE_INTEGER
#if defined(__WIN32__) && \
{
wxLogLastError(_T("GetDiskFreeSpaceEx"));
- return FALSE;
+ return false;
}
// ULARGE_INTEGER is a union of a 64 bit value and a struct containing
{
wxLogLastError(_T("GetDiskFreeSpace"));
- return FALSE;
+ return false;
}
wxLongLong lBytesPerCluster = lSectorsPerCluster;
}
}
- return TRUE;
+ return true;
#endif
// __WXWINCE__
}
bool wxGetEnv(const wxString& var, wxString *value)
{
#ifdef __WXWINCE__
- return FALSE;
+ return false;
#else // Win32
// first get the size of the buffer
DWORD dwRet = ::GetEnvironmentVariable(var, NULL, 0);
if ( !dwRet )
{
// this means that there is no such variable
- return FALSE;
+ return false;
}
if ( value )
dwRet);
}
- return TRUE;
+ return true;
#endif // WinCE/32
}
{
wxLogLastError(_T("SetEnvironmentVariable"));
- return FALSE;
+ return false;
}
- return TRUE;
+ return true;
#else // no way to set env vars
- return FALSE;
+ return false;
#endif
}
return TRUE;
}
-int wxKill(long pid, wxSignal sig, wxKillError *krc)
+int wxKillAllChildren(long pid, wxSignal sig, wxKillError *krc);
+
+int wxKill(long pid, wxSignal sig, wxKillError *krc, int flags)
{
+ if (flags & wxKILL_CHILDREN)
+ wxKillAllChildren(pid, sig, krc);
+
// get the process handle to operate on
HANDLE hProcess = ::OpenProcess(SYNCHRONIZE |
PROCESS_TERMINATE |
return -1;
}
- bool ok = TRUE;
+ bool ok = true;
switch ( sig )
{
case wxSIGKILL:
*krc = wxKILL_ERROR;
}
- ok = FALSE;
+ ok = false;
}
break;
{
wxLogLastError(_T("EnumWindows"));
- ok = FALSE;
+ ok = false;
}
}
else // no windows for this PID
*krc = wxKILL_ERROR;
}
- ok = FALSE;
+ ok = false;
}
}
}
return -1;
}
+HANDLE (WINAPI *lpfCreateToolhelp32Snapshot)(DWORD,DWORD) ;
+BOOL (WINAPI *lpfProcess32First)(HANDLE,LPPROCESSENTRY32) ;
+BOOL (WINAPI *lpfProcess32Next)(HANDLE,LPPROCESSENTRY32) ;
+
+static void InitToolHelp32()
+{
+ static bool s_initToolHelpDone = false;
+
+ if (s_initToolHelpDone)
+ return;
+
+ s_initToolHelpDone = true;
+
+ lpfCreateToolhelp32Snapshot = NULL;
+ lpfProcess32First = NULL;
+ lpfProcess32Next = NULL;
+
+ HINSTANCE hInstLib = LoadLibrary( wxT("Kernel32.DLL") ) ;
+ if( hInstLib == NULL )
+ return ;
+
+ // Get procedure addresses.
+ // We are linking to these functions of Kernel32
+ // explicitly, because otherwise a module using
+ // this code would fail to load under Windows NT,
+ // which does not have the Toolhelp32
+ // functions in the Kernel 32.
+ lpfCreateToolhelp32Snapshot=
+ (HANDLE(WINAPI *)(DWORD,DWORD))
+ GetProcAddress( hInstLib,
+#ifdef __WXWINCE__
+ wxT("CreateToolhelp32Snapshot")
+#else
+ "CreateToolhelp32Snapshot"
+#endif
+ ) ;
+
+ lpfProcess32First=
+ (BOOL(WINAPI *)(HANDLE,LPPROCESSENTRY32))
+ GetProcAddress( hInstLib,
+#ifdef __WXWINCE__
+ wxT("Process32First")
+#else
+ "Process32First"
+#endif
+ ) ;
+
+ lpfProcess32Next=
+ (BOOL(WINAPI *)(HANDLE,LPPROCESSENTRY32))
+ GetProcAddress( hInstLib,
+#ifdef __WXWINCE__
+ wxT("Process32Next")
+#else
+ "Process32Next"
+#endif
+ ) ;
+
+ FreeLibrary( hInstLib ) ;
+}
+
+// By John Skiff
+int wxKillAllChildren(long pid, wxSignal sig, wxKillError *krc)
+{
+ InitToolHelp32();
+
+ if (krc)
+ *krc = wxKILL_OK;
+
+ // If not implemented for this platform (e.g. NT 4.0), silently ignore
+ if (!lpfCreateToolhelp32Snapshot || !lpfProcess32First || !lpfProcess32Next)
+ return 0;
+
+ // Take a snapshot of all processes in the system.
+ HANDLE hProcessSnap = lpfCreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
+ if (hProcessSnap == INVALID_HANDLE_VALUE) {
+ if (krc)
+ *krc = wxKILL_ERROR;
+ return -1;
+ }
+
+ //Fill in the size of the structure before using it.
+ PROCESSENTRY32 pe = {0};
+ pe.dwSize = sizeof(PROCESSENTRY32);
+
+ // Walk the snapshot of the processes, and for each process,
+ // kill it if its parent is pid.
+ if (!lpfProcess32First(hProcessSnap, &pe)) {
+ // Can't get first process.
+ if (krc)
+ *krc = wxKILL_ERROR;
+ CloseHandle (hProcessSnap);
+ return -1;
+ }
+
+ do {
+ if (pe.th32ParentProcessID == (DWORD) pid) {
+ if (wxKill(pe.th32ProcessID, sig, krc))
+ return -1;
+ }
+ } while (lpfProcess32Next (hProcessSnap, &pe));
+
+
+ return 0;
+}
+
// Execute a program in an Interactive Shell
bool wxShell(const wxString& command)
{
+ wxString cmd;
+
#ifdef __WXWINCE__
- return FALSE;
+ cmd = command;
#else
wxChar *shell = wxGetenv(wxT("COMSPEC"));
if ( !shell )
shell = (wxChar*) wxT("\\COMMAND.COM");
- wxString cmd;
if ( !command )
{
// just the shell
// pass the command to execute to the command processor
cmd.Printf(wxT("%s /c %s"), shell, command.c_str());
}
+#endif
return wxExecute(cmd, wxEXEC_SYNC) == 0;
-#endif
}
// Shutdown or reboot the PC
bool wxShutdown(wxShutdownFlags wFlags)
{
#ifdef __WXWINCE__
- return FALSE;
+ return false;
#elif defined(__WIN32__)
- bool bOK = TRUE;
+ bool bOK = true;
if ( wxGetOsVersion(NULL, NULL) == wxWINDOWS_NT ) // if is NT or 2K
{
default:
wxFAIL_MSG( _T("unknown wxShutdown() flag") );
- return FALSE;
+ return false;
}
bOK = ::ExitWindowsEx(flags, 0) != 0;
break;
case VER_PLATFORM_WIN32_WINDOWS:
- str.Printf(_("Windows 9%c"),
- info.dwMinorVersion == 0 ? _T('5') : _T('8'));
+ switch (info.dwMinorVersion)
+ {
+ case 0:
+ if ( info.szCSDVersion[1] == 'B' ||
+ info.szCSDVersion[1] == 'C' )
+ {
+ str = _("Windows 95 OSR2");
+ }
+ else
+ {
+ str = _("Windows 95");
+ }
+ break;
+ case 10:
+ if ( info.szCSDVersion[1] == 'B' ||
+ info.szCSDVersion[1] == 'C' )
+ {
+ str = _("Windows 98 SE");
+ }
+ else
+ {
+ str = _("Windows 98");
+ }
+ break;
+ case 90:
+ str = _("Windows ME");
+ break;
+ default:
+ str.Printf(_("Windows 9x (%d.%d)"),
+ info.dwMajorVersion,
+ info.dwMinorVersion);
+ break;
+ }
if ( !wxIsEmpty(info.szCSDVersion) )
{
str << _T(" (") << info.szCSDVersion << _T(')');
break;
case VER_PLATFORM_WIN32_NT:
- str.Printf(_T("Windows NT %lu.%lu (build %lu"),
+ if ( info.dwMajorVersion == 5 )
+ {
+ switch ( info.dwMinorVersion )
+ {
+ case 0:
+ str.Printf(_("Windows 2000 (build %lu"),
+ info.dwBuildNumber);
+ break;
+ case 1:
+ str.Printf(_("Windows XP (build %lu"),
+ info.dwBuildNumber);
+ break;
+ case 2:
+ str.Printf(_("Windows Server 2003 (build %lu"),
+ info.dwBuildNumber);
+ break;
+ }
+ }
+ if ( wxIsEmpty(str) )
+ {
+ str.Printf(_("Windows NT %lu.%lu (build %lu"),
info.dwMajorVersion,
info.dwMinorVersion,
info.dwBuildNumber);
+ }
if ( !wxIsEmpty(info.szCSDVersion) )
{
str << _T(", ") << info.szCSDVersion;
if ( !name )
return -1;
- wxFontEncoding enc = wxFontMapper::Get()->CharsetToEncoding(name, FALSE);
+ wxFontEncoding enc = wxFontMapper::Get()->CharsetToEncoding(name, false);
if ( enc == wxFONTENCODING_SYSTEM )
return -1;