get/set clipboard, color hex value
This commit is contained in:
41
src/main.cpp
41
src/main.cpp
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user