Mercurial > minori
comparison dep/animia/src/util/win32.cc @ 156:cdf79282d647
dep/animia: add VERY early x11 window stuff
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Wed, 15 Nov 2023 18:04:04 -0500 |
parents | 8700806c2cc2 |
children |
comparison
equal
deleted
inserted
replaced
155:d2bbb5773616 | 156:cdf79282d647 |
---|---|
1 #include "animia/util/win32.h" | 1 #include "animia/util/win32.h" |
2 | 2 |
3 #include <shlobj.h> /* SHGetKnownFolderPath */ | |
4 #include <subauth.h> /* UNICODE_STRING */ | |
3 #include <windows.h> | 5 #include <windows.h> |
4 #include <shlobj.h> /* SHGetKnownFolderPath */ | |
5 #include <subauth.h> /* UNICODE_STRING */ | |
6 | 6 |
7 namespace animia::internal::win32 { | 7 namespace animia::internal::win32 { |
8 | 8 |
9 std::string ToUtf8String(const std::wstring& string) { | 9 std::string ToUtf8String(const std::wstring& string) { |
10 const auto wctomb = [&string](LPSTR out, int size) -> int { | 10 const auto wctomb = [&string](LPSTR out, int size) -> int { |
11 return ::WideCharToMultiByte(CP_UTF8, 0, string.c_str(), string.length(), out, size, nullptr, nullptr); | 11 return ::WideCharToMultiByte(CP_UTF8, 0, string.c_str(), string.length(), out, size, nullptr, nullptr); |
12 }; | 12 }; |
13 | 13 |
14 if (string.empty()) | 14 if (string.empty()) |
15 return std::string(); | 15 return std::string(); |
16 | |
17 | 16 |
18 long size = ::WideCharToMultiByte(CP_UTF8, 0, string.c_str(), string.length(), nullptr, 0, nullptr, nullptr); | 17 long size = ::WideCharToMultiByte(CP_UTF8, 0, string.c_str(), string.length(), nullptr, 0, nullptr, nullptr); |
19 std::string ret = std::string(size, '\0'); | 18 std::string ret = std::string(size, '\0'); |
20 ::WideCharToMultiByte(CP_UTF8, 0, string.c_str(), string.length(), &ret.front(), ret.length(), nullptr, nullptr); | 19 ::WideCharToMultiByte(CP_UTF8, 0, string.c_str(), string.length(), &ret.front(), ret.length(), nullptr, nullptr); |
21 return ret; | 20 return ret; |
85 ::CharUpperBuffW(&windir.front(), windir.length()); | 84 ::CharUpperBuffW(&windir.front(), windir.length()); |
86 | 85 |
87 return path.find(windir) == 4; | 86 return path.find(windir) == 4; |
88 } | 87 } |
89 | 88 |
90 } | 89 } // namespace animia::internal::win32 |