win32.hpp (2437B)
1 /* ReaPack: Package manager for REAPER 2 * Copyright (C) 2015-2025 Christian Fillion 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU Lesser General Public License for more details. 13 * 14 * You should have received a copy of the GNU Lesser General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 #ifndef REAPACK_WIN32_HPP 19 #define REAPACK_WIN32_HPP 20 21 // Utility wrappers around the Windows Wide API 22 23 #include <string> 24 25 #ifdef _WIN32 26 # define L(str) L##str 27 # include <windows.h> 28 #else 29 # define L(str) str 30 # include <swell/swell-types.h> 31 #endif 32 33 namespace Win32 { 34 #ifdef _WIN32 35 typedef wchar_t char_type; 36 37 std::wstring widen(const char *, UINT codepage = CP_UTF8); 38 inline std::wstring widen(const std::string &str, UINT codepage = CP_UTF8) 39 { return widen(str.c_str(), codepage); } 40 41 std::string narrow(const wchar_t *); 42 inline std::string narrow(const std::wstring &str) { return narrow(str.c_str()); } 43 44 inline std::string ansi2utf8(const char *str) { return narrow(widen(str, CP_ACP)); } 45 inline std::string ansi2utf8(const std::string &str) { return ansi2utf8(str.c_str()); } 46 #else 47 typedef char char_type; 48 49 inline std::string widen(const char *s, UINT = 0) { return s; } 50 inline std::string widen(const std::string &s) { return s; } 51 52 inline std::string narrow(const char *s) { return s; } 53 inline std::string narrow(const std::string &s) { return s; } 54 #endif 55 56 int messageBox(HWND, const char *text, const char *title, unsigned int buttons); 57 void setWindowText(HWND handle, const char *text); 58 std::string getWindowText(HWND handle); 59 void shellExecute(const char *what, const char *arg = nullptr); 60 HANDLE globalCopy(const std::string &); 61 62 bool writePrivateProfileString(const char *g, const char *k, const char *v, const char *p); 63 std::string getPrivateProfileString(const char *g, const char *k, const char *v, const char *p); 64 unsigned int getPrivateProfileInt(const char *g, const char *k, unsigned int f, const char *p); 65 }; 66 67 #endif