Microsoft Learn

Current Path: Windows API Reference  >  User32  >  OpenClipboard

OpenClipboard function

Syntax

BOOL OpenClipboard(
  HWND  hWndNewOwner
);

Parameters

Parameter Type and description
hWndNewOwner Handle to the window to be associated with an opened clipboard. This parameter can be NULL.

Return value

If the function succeeds, the return value is nonzero. If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

An application must call OpenClipboard to open the clipboard for access. Once the clipboard is open, it displays the specified window as the current owner of the clipboard.

  • If the clipboard is already open, the function returns zero and GetLastError returns ERROR_ACCESS_DENIED.
  • If hWndNewOwner is NULL, the clipboard is associated with the current task, not a specific window.
  • Only one application at a time can access the clipboard.
  • A call to OpenClipboard will fail if the clipboard is orphaned. The clipboard becomes orphaned if the owner of the clipboard closes its window without calling CloseClipboard.
  • An application should call CloseClipboard to close the clipboard for access when it has finished using the clipboard.

Requirements

Package Value
Minimum supported client Windows 2000 Professional
Minimum supported server Windows 2000 Server
Header winuser.h (include Windows.h)