1
0

MPTrackUtil.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * MPTrackUtil.h
  3. * -------------
  4. * Purpose: Various useful utility functions.
  5. * Notes : (currently none)
  6. * Authors: OpenMPT Devs
  7. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  8. */
  9. #pragma once
  10. #include "openmpt/all/BuildSettings.hpp"
  11. #include <string>
  12. OPENMPT_NAMESPACE_BEGIN
  13. bool CreateShellFolderLink(const mpt::PathString &path, const mpt::PathString &target, const mpt::ustring &description = mpt::ustring());
  14. bool CreateShellFileLink(const mpt::PathString &path, const mpt::PathString &target, const mpt::ustring &description = mpt::ustring());
  15. /*
  16. * Gets resource as raw byte data.
  17. * [in] lpName and lpType: parameters passed to FindResource().
  18. * Return: span representing the resource data, valid as long as hInstance is valid.
  19. */
  20. mpt::const_byte_span GetResource(LPCTSTR lpName, LPCTSTR lpType);
  21. CString LoadResourceString(UINT nID);
  22. namespace Util
  23. {
  24. // Get horizontal DPI resolution
  25. MPT_FORCEINLINE int GetDPIx(HWND hwnd)
  26. {
  27. HDC dc = ::GetDC(hwnd);
  28. int dpi = ::GetDeviceCaps(dc, LOGPIXELSX);
  29. ::ReleaseDC(hwnd, dc);
  30. return dpi;
  31. }
  32. // Get vertical DPI resolution
  33. MPT_FORCEINLINE int GetDPIy(HWND hwnd)
  34. {
  35. HDC dc = ::GetDC(hwnd);
  36. int dpi = ::GetDeviceCaps(dc, LOGPIXELSY);
  37. ::ReleaseDC(hwnd, dc);
  38. return dpi;
  39. }
  40. // Applies DPI scaling factor to some given size
  41. MPT_FORCEINLINE int ScalePixels(int pixels, HWND hwnd)
  42. {
  43. return MulDiv(pixels, GetDPIx(hwnd), 96);
  44. }
  45. // Removes DPI scaling factor from some given size
  46. MPT_FORCEINLINE int ScalePixelsInv(int pixels, HWND hwnd)
  47. {
  48. return MulDiv(pixels, 96, GetDPIx(hwnd));
  49. }
  50. }
  51. namespace Util
  52. {
  53. inline DWORD64 GetTickCount64()
  54. {
  55. #if (_WIN32_WINNT >= _WIN32_WINNT_VISTA)
  56. return ::GetTickCount64();
  57. #else
  58. return ::GetTickCount();
  59. #endif
  60. }
  61. }
  62. OPENMPT_NAMESPACE_END