GetClipboardData on a delay rendered data inside a

2019-08-28 02:19发布

When some other program puts a delay rendered data to clipboard (by calling SetClipboardData(fmt, NULL)), my clipboard viewer gets WM_DRAWCLIPBOARD.
When my viewer calls GetClipboardData(), my window proc is called recursively with another WM_DRAWCLIPBOARD.
I can't find any description of that.

#define MY_CF CF_RIFF

LRESULT CALLBACK WindowProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
{
    switch (uMsg) {
        case WM_DRAWCLIPBOARD:
            OpenClipboard(hwnd);
            HGLOBAL hglob = GetClipboardData(MY_CF); // Sends recursive WM_DRAWCLIPBOARD
            break;
        default:
            return DefWindowProc( hwnd,uMsg,wParam,lParam);
    }
    return 0;
}

1条回答
爷、活的狠高调
2楼-- · 2019-08-28 02:53

First, you don't handle WM_DRAWCLIPBOARD properly you should let the message forward to other windows

http://msdn.microsoft.com/en-us/library/windows/desktop/ms649025%28v=vs.85%29.aspx
Each window that receives the WM_DRAWCLIPBOARD message must call the SendMessage function to pass the message on to the next window in the clipboard viewer chain. The handle to the next window in the chain is returned by SetClipboardViewer, and may change in response to a WM_CHANGECBCHAIN message.

Second, unfortunately receiving many WM_DRAWCLIPBOARD is common. By experience it's common to receive between 0 and 4.
The ugly trick (which works) is to get timestamps on each call, and if it's too close to the previous one simply ignore.

查看更多
登录 后发表回答