X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/04ef50df3a0fa3c343800c554e609f98fc7575cc..cf31a1d7b60feddf23cc30259c6d909d4736ca56:/src/msw/utils.cpp?ds=sidebyside diff --git a/src/msw/utils.cpp b/src/msw/utils.cpp index b117cb09c1..590486daf8 100644 --- a/src/msw/utils.cpp +++ b/src/msw/utils.cpp @@ -31,9 +31,11 @@ #ifndef WX_PRECOMP #include "wx/utils.h" #include "wx/app.h" - #include "wx/cursor.h" #include "wx/intl.h" #include "wx/log.h" +#if wxUSE_GUI + #include "wx/cursor.h" +#endif #endif //WX_PRECOMP // In some mingws there is a missing extern "C" int the winsock header, @@ -103,8 +105,6 @@ extern "C" { #include "wx/ioswrap.h" -#include "wx/ioswrap.h" - /* Need to undef new if including crtdbg.h */ # ifdef new # undef new @@ -449,6 +449,101 @@ bool wxDirExists(const wxString& dir) #endif // Win32/16 } +bool wxGetDiskSpace(const wxString& path, wxLongLong *pTotal, wxLongLong *pFree) +{ + if ( path.empty() ) + return FALSE; + +// old w32api don't have ULARGE_INTEGER +#if defined(__WIN32__) && \ + (!defined(__GNUWIN32__) || wxCHECK_W32API_VERSION( 0, 3 )) + // GetDiskFreeSpaceEx() is not available under original Win95, check for + // it + typedef BOOL (*GetDiskFreeSpaceEx_t)(LPCTSTR, + PULARGE_INTEGER, + PULARGE_INTEGER, + PULARGE_INTEGER); + + GetDiskFreeSpaceEx_t + pGetDiskFreeSpaceEx = (GetDiskFreeSpaceEx_t)::GetProcAddress + ( + ::GetModuleHandle(_T("kernel32.dll")), +#if wxUSE_UNICODE + "GetDiskFreeSpaceExW" +#else + "GetDiskFreeSpaceExA" +#endif + ); + + if ( pGetDiskFreeSpaceEx ) + { + ULARGE_INTEGER bytesFree, bytesTotal; + + // may pass the path as is, GetDiskFreeSpaceEx() is smart enough + if ( !pGetDiskFreeSpaceEx(path, + &bytesFree, + &bytesTotal, + NULL) ) + { + wxLogLastError(_T("GetDiskFreeSpaceEx")); + + return FALSE; + } + + if ( pTotal ) + { + *pTotal = wxLongLong(bytesTotal.HighPart, bytesTotal.LowPart); + } + + if ( pFree ) + { + *pFree = wxLongLong(bytesFree.HighPart, bytesFree.LowPart); + } + } + else +#endif // Win32 + { + // there's a problem with drives larger than 2GB, GetDiskFreeSpaceEx() + // should be used instead - but if it's not available, fall back on + // GetDiskFreeSpace() nevertheless... + + DWORD lSectorsPerCluster, + lBytesPerSector, + lNumberOfFreeClusters, + lTotalNumberOfClusters; + + // FIXME: this is wrong, we should extract the root drive from path + // instead, but this is the job for wxFileName... + if ( !::GetDiskFreeSpace(path, + &lSectorsPerCluster, + &lBytesPerSector, + &lNumberOfFreeClusters, + &lTotalNumberOfClusters) ) + { + wxLogLastError(_T("GetDiskFreeSpace")); + + return FALSE; + } + + wxLongLong lBytesPerCluster = lSectorsPerCluster; + lBytesPerCluster *= lBytesPerSector; + + if ( pTotal ) + { + *pTotal = lBytesPerCluster; + *pTotal *= lTotalNumberOfClusters; + } + + if ( pFree ) + { + *pFree = lBytesPerCluster; + *pFree *= lNumberOfFreeClusters; + } + } + + return TRUE; +} + // ---------------------------------------------------------------------------- // env vars // ---------------------------------------------------------------------------- @@ -1233,8 +1328,12 @@ int wxDisplayDepth() void wxDisplaySize(int *width, int *height) { #ifdef __WXMICROWIN__ - // MICROWIN_TODO - *width = 0; * height = 0; + RECT rect; + HWND hWnd = GetDesktopWindow(); + ::GetWindowRect(hWnd, & rect); + + *width = rect.right - rect.left; + *height = rect.bottom - rect.top; #else ScreenHDC dc; @@ -1282,59 +1381,47 @@ void wxClientDisplayRect(int *x, int *y, int *width, int *height) wxString WXDLLEXPORT wxGetWindowText(WXHWND hWnd) { wxString str; - int len = GetWindowTextLength((HWND)hWnd) + 1; - GetWindowText((HWND)hWnd, str.GetWriteBuf(len), len); - str.UngetWriteBuf(); + + if ( hWnd ) + { + int len = GetWindowTextLength((HWND)hWnd) + 1; + ::GetWindowText((HWND)hWnd, str.GetWriteBuf(len), len); + str.UngetWriteBuf(); + } return str; } wxString WXDLLEXPORT wxGetWindowClass(WXHWND hWnd) { -#ifdef __WXMICROWIN__ - // MICROWIN_TODO - return wxEmptyString; -#else wxString str; - int len = 256; // some starting value - - for ( ;; ) + // MICROWIN_TODO +#ifndef __WXMICROWIN__ + if ( hWnd ) { - // as we've #undefined GetClassName we must now manually choose the - // right function to call - int count = - - #ifndef __WIN32__ - GetClassName - #else // Win32 - #ifdef UNICODE - GetClassNameW - #else // !Unicode - #ifdef __TWIN32__ - GetClassName - #else // !Twin32 - GetClassNameA - #endif // Twin32/!Twin32 - #endif // Unicode/ANSI - #endif // Win16/32 - ((HWND)hWnd, str.GetWriteBuf(len), len); + int len = 256; // some starting value - str.UngetWriteBuf(); - if ( count == len ) - { - // the class name might have been truncated, retry with larger - // buffer - len *= 2; - } - else + for ( ;; ) { - break; + int count = ::GetClassName((HWND)hWnd, str.GetWriteBuf(len), len); + + str.UngetWriteBuf(); + if ( count == len ) + { + // the class name might have been truncated, retry with larger + // buffer + len *= 2; + } + else + { + break; + } } } +#endif // !__WXMICROWIN__ return str; -#endif } WXWORD WXDLLEXPORT wxGetWindowId(WXHWND hWnd)