1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static wchar_t *wText;
wchar_t *wGlobal;
HGLOBAL hGlobal;
HDC hdc;
PAINTSTRUCT ps;
RECT rc;
switch(msg)
{
case WM_CREATE:
OpenClipboard(hWnd);
if(hGlobal = GetClipboardData(CF_UNICODETEXT))
{
wGlobal = (wchar_t*)GlobalLock(hGlobal);
// Allocate memory from the clipboard
wText = new wchar_t[GlobalSize(hGlobal)];
// Make a copy of the text in the clipboard
lstrcpy (wText, wGlobal);
GlobalUnlock (hGlobal);
InvalidateRect (hWnd, NULL, TRUE) ;
}
CloseClipboard();
break;
case WM_CLOSE:
DestroyWindow(hWnd);
break;
case WM_PAINT:
// Draw the text in the clipboard
hdc = BeginPaint(hWnd,&ps);
GetClientRect(hWnd,&rc);
if(wText != NULL) // But only if there is something in the clipboard.
{
DrawText(hdc,wText, -1,&rc,DT_LEFT | DT_WORDBREAK);
}
EndPaint(hWnd,&ps);
break;
case WM_DESTROY:
if(wText) // Deallocate memory if any was allocated.
{
delete[] wText;
}
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, msg, wParam, lParam);
break;
}
return 0;
}
|