MCPcopy Create free account
hub / github.com/MyGUI/mygui / handleClipboardChanged

Method handleClipboardChanged

MyGUIEngine/src/MyGUI_WindowsClipboardHandler.cpp:87–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85 }
86
87 void WindowsClipboardHandler::handleClipboardChanged(std::string_view _type, std::string_view _data)
88 {
89 if (_type == "Text")
90 {
91 mPutTextInClipboard = TextIterator::getOnlyText(UString(_data));
92 size_t size = (mPutTextInClipboard.size() + 1) * 2;
93 //открываем буфер обмена
94 if (OpenClipboard((HWND)mHwnd))
95 {
96 EmptyClipboard(); //очищаем буфер
97 HGLOBAL hgBuffer = GlobalAlloc(GMEM_DDESHARE, size); //выделяем память
98 wchar_t* chBuffer = hgBuffer ? (wchar_t*)GlobalLock(hgBuffer) : nullptr;
99 if (chBuffer)
100 {
101 memcpy(chBuffer, mPutTextInClipboard.asWStr_c_str(), size);
102 GlobalUnlock(hgBuffer); //разблокируем память
103 SetClipboardData(CF_UNICODETEXT, hgBuffer); //помещаем текст в буфер обмена
104 }
105 CloseClipboard(); //закрываем буфер обмена
106 }
107 }
108 }
109
110 void WindowsClipboardHandler::handleClipboardRequested(std::string_view _type, std::string& _data)
111 {

Callers

nothing calls this directly

Calls 3

UStringFunction · 0.85
asWStr_c_strMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected