get/set clipboard, color hex value

This commit is contained in:
2019-06-24 23:46:55 +02:00
parent 2782d864ed
commit f9cf452af2
7 changed files with 129 additions and 0 deletions

View File

@@ -180,6 +180,47 @@ void win32_show_cursor(bool visible)
});
}
std::string win32_clipboard_get_text()
{
std::string ret;
if (OpenClipboard(hWnd))
{
if (HANDLE h = GetClipboardData(CF_TEXT))
{
if (char* s = (char*)GlobalLock(h))
{
ret = s;
GlobalUnlock(h);
}
}
CloseClipboard();
}
return ret;
}
bool win32_clipboard_set_text(const std::string& s)
{
bool success = false;
if (OpenClipboard(hWnd))
{
// owned by SetClipboardData
if (HGLOBAL h = GlobalAlloc(GMEM_MOVEABLE, s.size() + 1))
{
if (char* p = (char*)GlobalLock(h))
{
std::copy(s.begin(), s.end(), p);
p[s.size()] = 0; // string null-termination
GlobalUnlock(h);
success = true;
}
EmptyClipboard();
SetClipboardData(CF_TEXT, h);
}
CloseClipboard();
}
return success;
}
std::string win32_open_file(const char* filter)
{
OPENFILENAMEA ofn;