GetClipboardData on a delay rendered data inside a clipboard viewer causes recursive WM_DRAWCLIPBOARD

醉酒当歌 提交于 2019-12-12 01:54:31

问题


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:


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.



来源:https://stackoverflow.com/questions/18895865/getclipboarddata-on-a-delay-rendered-data-inside-a-clipboard-viewer-causes-recur

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!