case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDM_EXIT:
DestroyWindow(hWnd);
break;
// {
case ID_BTN_COPY: { // Copy
HGLOBAL hmem;
TCHAR *ptr;
hmem = GlobalAlloc(GHND, lstrlen(g_str)+1);
ptr = (TCHAR *)GlobalLock(hmem);
memcpy(ptr, g_str, lstrlen(g_str) + 1);
GlobalUnlock(hmem);
if (OpenClipboard(hWnd)) {
EmptyClipboard();
SetClipboardData(CF_TEXT, hmem);
CloseClipboard();
} else {
GlobalFree(hmem);
}
}
break;
case ID_BTN_PASTE: { // Paste
HGLOBAL hmem;
TCHAR *ptr;
if (IsClipboardFormatAvailable(CF_TEXT)) {
OpenClipboard(hWnd);
hmem = GetClipboardData(CF_TEXT);
ptr = (TCHAR *)GlobalLock(hmem);
...
GlobalUnlock(hmem);
CloseClipboard();
}
}
break;
// }
...
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
void CopyToClipboard(HWND hWnd, HANDLE hDIB)
{
if (::OpenClipboard(hWnd)) {
if(::EmptyClipboard()) {
if (::SetClipboardData(CF_DIB, hDIB) == NULL ) {
::CloseClipboard();
throw "CopyToClipboard error";
}
}
}
::CloseClipboard();
}
if (IsClipboardFormatAvailable(CF_DIB)) {
//if (!IsClipboardFormatAvailable(CF_DIB)) {
HANDLE hBitmap=NULL;
// 클립보드에서 데이터 가져오기
if (::OpenClipboard(AfxGetMainWnd()->GetSafeHwnd()))
hBitmap = ::GetClipboardData(CF_DIB);
if (hBitmap){
...
}
// 클립보드 닫기
::CloseClipboard();
}