2.1.25.13 GetClipboardData


Description

Retrieves data from the clipboard in a specified format.

Syntax

HANDLE GetClipboardData( UINT uFormat )

Parameters

uFormat
[input] Specifies a standard or registered clipboard format, like CF_TEXT, CF_DIB etc

Return

If the function succeeds, the return value is the handle to a clipboard object in the specified format.

If the function fails, the return value is NULL.

Examples

EX1

int GetClipboardData_ex1()
{
    if(!OpenClipboard(NULL))
        return 0;
    
    if(IsClipboardFormatAvailable(CF_TEXT))
    {
        HANDLE hData = GetClipboardData(CF_TEXT);
        LPCSTR lpData = (LPCSTR)GlobalLock(hData);
        string str = lpData;
        GlobalUnlock(hData);
        out_str(str);
    }
    else
        out_str("No Text in clipboard");
    
    CloseClipboard();
    return 1;
}

Remark

This function retrieves data from the clipboard in a specified format. The clipboard must have been opened previously.

The clipboard controls the handle that the GetClipboardData function returns, not the application.

The application should copy the data immediately. The application must not free the handle nor leave it locked.

The application must not use the handle after the EmptyClipboard or CloseClipboard function is called,

or after the SetClipboardData function is called with the same clipboard format.

The system performs implicit data format conversions between certain clipboard formats when an application calls the

GetClipboardData function. For example, if the CF_OEMTEXT format is on the clipboard, a window can retrieve data in the CF_TEXT format.

The format on the clipboard is converted to the requested format on demand.

See Also

SetClipboardData

Header to Include

origin.h

Reference