You need to add a WM_INITMENU case to your window function to prepare the Edit menu for pasting. In general, the Paste command should not be available unless there is selected text in the clipboard to paste. Add the following statements to the window function:
case WM_INITMENU:
if (wParam == GetMenu(hWnd)) {
if (OpenClipboard(hWnd)) {
if (IsClipboardFormatAvailable(CF_TEXT)
|| IsClipboardFormatAvailable(CF_OEMTEXT))
EnableMenuItem(wParam, IDM_PASTE, MF_ENABLED);
else
EnableMenuItem(wParam, IDM_PASTE, MF_GRAYED);
CloseClipboard();
return (TRUE);
}
else /* Clipboard is not available */
return (FALSE);
}
These statements process the WM_INITMENU message only if the specified menu is the menu bar. The IsClipboardFormatAvailable function determines whether text data is present on the clipboard. If it is, the EnableMenuItem function enables the Paste command. Otherwise, the Paste command is disabled.