From e08a078588b7a139655e55daccd1e11b7ad7a4c2 Mon Sep 17 00:00:00 2001 From: Ludvig Strigeus Date: Tue, 20 Nov 2018 20:25:00 +0100 Subject: [PATCH] Add GetClipboardString() --- util_win32.cpp | 16 ++++++++++++++++ util_win32.h | 3 +++ 2 files changed, 19 insertions(+) diff --git a/util_win32.cpp b/util_win32.cpp index 821372c..cc28898 100644 --- a/util_win32.cpp +++ b/util_win32.cpp @@ -382,6 +382,22 @@ bool SetClipboardString(const char *string) { return ok; } +std::string GetClipboardString() { + std::string rv; + if (OpenClipboard(NULL)) { + HANDLE hData = GetClipboardData(CF_TEXT); + if (hData != NULL) { + char *pszText = static_cast(GlobalLock(hData)); + if (pszText != NULL) + rv = pszText; + GlobalUnlock(hData); + } + CloseClipboard(); + } + return rv; +} + + RECT GetParentRect(HWND wnd) { RECT btrect; GetClientRect(wnd, &btrect); diff --git a/util_win32.h b/util_win32.h index 0ae16ec..c0cde7c 100644 --- a/util_win32.h +++ b/util_win32.h @@ -2,6 +2,7 @@ // Copyright (C) 2018 Ludvig Strigeus . All Rights Reserved. #include "tunsafe_types.h" #include +#include #pragma once const char *FindFilenameComponent(const char *s); @@ -54,6 +55,7 @@ bool EnsureValidConfigPath(const char *path); bool RunProcessAsAdminWithArgs(const char *args, bool wait_for_exit); bool RestartProcessAsAdministrator(); bool SetClipboardString(const char *string); +std::string GetClipboardString(); RECT GetParentRect(HWND wnd); RECT MakeRect(int l, int t, int r, int b); struct GuidAndDevName { @@ -61,3 +63,4 @@ struct GuidAndDevName { char name[64]; }; void GetTapAdapterInfo(std::vector *result); +