metrics.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/msw/private/metrics.h
  3. // Purpose: various helper functions to retrieve system metrics
  4. // Author: Vadim Zeitlin
  5. // Created: 2008-09-05
  6. // Copyright: (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
  7. // Licence: wxWindows licence
  8. ///////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_MSW_PRIVATE_METRICS_H_
  10. #define _WX_MSW_PRIVATE_METRICS_H_
  11. namespace wxMSWImpl
  12. {
  13. // return NONCLIENTMETRICS as retrieved by SystemParametersInfo()
  14. //
  15. // currently this is not cached as the values may change when system settings
  16. // do and we don't react to this to invalidate the cache but it could be done
  17. // in the future
  18. //
  19. // MT-safety: this function is only meant to be called from the main thread
  20. inline const NONCLIENTMETRICS& GetNonClientMetrics()
  21. {
  22. static WinStruct<NONCLIENTMETRICS> nm;
  23. if ( !::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &nm, 0) )
  24. {
  25. #if WINVER >= 0x0600
  26. // a new field has been added to NONCLIENTMETRICS under Vista, so
  27. // the call to SystemParametersInfo() fails if we use the struct
  28. // size incorporating this new value on an older system -- retry
  29. // without it
  30. nm.cbSize -= sizeof(int);
  31. if ( !::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &nm, 0) )
  32. #endif // WINVER >= 0x0600
  33. {
  34. // maybe we should initialize the struct with some defaults?
  35. wxLogLastError(wxT("SystemParametersInfo(SPI_GETNONCLIENTMETRICS)"));
  36. }
  37. }
  38. return nm;
  39. }
  40. } // namespace wxMSWImpl
  41. #endif // _WX_MSW_PRIVATE_METRICS_H_