MCPcopy Create free account
hub / github.com/ColorCop/ColorCop / OnCopytoclip

Method OnCopytoclip

ColorCop/ColorCopDlg.cpp:1403–1431  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1401}
1402
1403void CColorCopDlg::OnCopytoclip() {
1404 if (m_Appflags & AutoCopytoClip) {
1405 HWND hWndOwner = ::GetForegroundWindow();
1406
1407 if (::OpenClipboard(hWndOwner)) {
1408 ::EmptyClipboard();
1409
1410 // CString is UTF‑16 in Unicode builds, so copy its raw buffer.
1411 const int len = m_Hexcolor.GetLength();
1412 const SIZE_T bytes = (len + 1) * sizeof(wchar_t);
1413
1414 HGLOBAL hMem = ::GlobalAlloc(GMEM_MOVEABLE, bytes);
1415 if (hMem) {
1416 void* pMem = ::GlobalLock(hMem);
1417 if (pMem) {
1418 std::memcpy(pMem, m_Hexcolor.GetString(), bytes);
1419 ::GlobalUnlock(hMem);
1420
1421 // Correct modern clipboard format
1422 ::SetClipboardData(CF_UNICODETEXT, hMem);
1423 } else {
1424 ::GlobalFree(hMem);
1425 }
1426 }
1427
1428 ::CloseClipboard();
1429 }
1430 }
1431}
1432
1433void CColorCopDlg::StopCapture() {
1434 // we don't want to capture anymore, they let up the left mouse button, or hit ESC

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected