유용한 정보

[C++]클립보드 Copy & Paste

DevReff 2024. 12. 25. 12:13
728x90
SMALL
반응형

<클립보드에 복사>

HGLOBAL hGlobal = GlobalAlloc(GHND | GMEM_SHARE, (lstrlen(pText) + 1)*sizeof(TCHAR));

 

PTSTR pGlobal = GlobalLock(hGlobal);

 

lstrcpy(pGlobal, TEXT("Hello"));

GlobalUnlock(hGlobal);

 

OpenClipboard(윈도우 핸들);

EmptyClipboard();

SetClipboardData(CF_TCHAR, hGlobal);

CloseClipboard();

 

 

<클립보드에서 가져오기>

OpenClipboard(윈도우 핸들);

HGLOBAL hGlobal = GetClipboardData(CF_TEXT);

 

char a[1024];

if(hGlobal) {

PTSTR pGlobal (char*)GlobalLock(hGlobal);

lstrcpy( a,pGlobal);

GlobalUnlock(hGlobal);

}

CloseClipboard();

 

출처: https://use1348.tistory.com/51 [유용한 정보:티스토리]