WinPhoneUtil.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #include <wrl.h>
  2. #include <string>
  3. #include <DXGI.h>
  4. //#include <stdio.h>
  5. //#include <share.h>
  6. //static const char *
  7. //GetRootPath()
  8. //{
  9. // static char buf[1024] = "";
  10. // if (buf[0] == '\0')
  11. // {
  12. // Platform::String^ localfolder = Windows::Storage::ApplicationData::Current->LocalFolder->Path;
  13. // const char16 *begin = localfolder->Begin();
  14. // WideCharToMultiByte(CP_ACP, 0, begin, -1, buf, 1024, NULL, FALSE);
  15. // }
  16. // return buf;
  17. //}
  18. //
  19. //static const char *
  20. //GetInstallPath()
  21. //{
  22. // static char buf[1024] = "";
  23. // if (buf[0] == '\0')
  24. // {
  25. // Platform::String^ installfolder = Windows::ApplicationModel::Package::Current->InstalledLocation->Path;
  26. // const char16 *begin = installfolder->Begin();
  27. // WideCharToMultiByte(CP_ACP, 0, begin, -1, buf, 1024, NULL, FALSE);
  28. // }
  29. // return buf;
  30. //}
  31. //
  32. //extern "C" FILE *
  33. //MY_fopen(const char *path, const char *mode)
  34. //{
  35. // return fopen(path, mode);
  36. //
  37. // const char *p = GetRootPath();
  38. // char buf[1024];
  39. // _snprintf_s(buf, 1024, "%s\\%s", p, path);
  40. // FILE *fp = _fsopen(buf, mode, _SH_DENYNO);
  41. // if (fp == NULL)
  42. // {
  43. // p = GetInstallPath();
  44. // _snprintf_s(buf, 1024, "%s\\%s", p, path);
  45. // fp = _fsopen(buf, mode, _SH_DENYNO);
  46. // }
  47. // if (fp == NULL)
  48. // {
  49. // p = GetRootPath();
  50. // _snprintf_s(buf, 1024, "%s\\Shared\\%s", p, path);
  51. // fp = _fsopen(buf, mode, _SH_DENYNO);
  52. // }
  53. // return fp;
  54. //}
  55. static std::string g_savepath;
  56. extern "C"
  57. LPCSTR UTIL_WP_SavePath(VOID)
  58. {
  59. auto localfolder = Windows::Storage::ApplicationData::Current->LocalFolder->Path;
  60. int len = WideCharToMultiByte(CP_ACP, 0, localfolder->Begin(), -1, nullptr, 0, nullptr, nullptr);
  61. g_savepath.resize(len);
  62. WideCharToMultiByte(CP_ACP, 0, localfolder->Begin(), -1, (char*)g_savepath.data(), len, nullptr, nullptr);
  63. const_cast<char*>(g_savepath.data())[len - 1] = '\\';
  64. return g_savepath.c_str();
  65. }
  66. extern "C"
  67. BOOL UTIL_WP_GetScreenSize(DWORD *pdwScreenWidth, DWORD *pdwScreenHeight)
  68. {
  69. DXGI_OUTPUT_DESC desc;
  70. IDXGIFactory1* pFactory = nullptr;
  71. IDXGIAdapter1* pAdapter = nullptr;
  72. IDXGIOutput* pOutput = nullptr;
  73. DWORD retval = FALSE;
  74. if (!pdwScreenWidth || !pdwScreenHeight) return FALSE;
  75. if (FAILED(CreateDXGIFactory1(IID_IDXGIFactory1, (void**)&pFactory))) goto UTIL_WP_GetScreenSize_exit;
  76. if (FAILED(pFactory->EnumAdapters1(0, &pAdapter))) goto UTIL_WP_GetScreenSize_exit;
  77. if (FAILED(pAdapter->EnumOutputs(0, &pOutput))) goto UTIL_WP_GetScreenSize_exit;
  78. if (SUCCEEDED(pOutput->GetDesc(&desc)))
  79. {
  80. *pdwScreenWidth = (desc.DesktopCoordinates.bottom - desc.DesktopCoordinates.top);
  81. *pdwScreenHeight = (desc.DesktopCoordinates.right - desc.DesktopCoordinates.left);
  82. retval = TRUE;
  83. }
  84. UTIL_WP_GetScreenSize_exit:
  85. if (pOutput) pOutput->Release();
  86. if (pAdapter) pAdapter->Release();
  87. if (pFactory) pFactory->Release();
  88. return retval;
  89. }