clipboard delayed rendering problem WM_RENDERFORMAT not sent

35 Views Asked by At

I Created an application with a simple remote desktop ability. I monitor GetKeyboardSequenceCounter() and send the clipboard text contents from computer1 to computer2. Computer2 receives text correctly and activates delayed rendering as follows

/*---------------------------------------------------------*/
ARESULT AminDesk::u_RecvSetClipboardText(
    HWND hDlg, const wchar_t* wszText)
{
    //u_SaveStream(L"recv.log", wszText);
    m_strClipboard = wszText;

#if 00
    if (!OpenClipboard(hDlg))
        return ARESULT::SUCCESS;
    u_RenderFormat(hDlg, CF_UNICODETEXT);
    CloseClipboard();
#else
    return u_DelayRendering(hDlg);
#endif
}

ARESULT AminDesk::u_DelayedRendering(HDLG hDlg, const wchar_t* wszText)
{
    if (!OpenClipboard(hDlg))
        return ARESULT::FAILURE;
    m_dwClipboardSequenceNumber = MAXUINT32;
    SetClipboardData(CF_UNICODETEXT, nullptr); //delayed rendering
    CloseClipboard();
    m_strClipboard = wszText;
    m_dwClipboardSequenceNumber = GetClipboardSequenceNumber();
    u_ShowStatus(hDlg, "delayed rendering activated");
    return ARESULT::SUCCESS;
}

Computer2 receives text and sends wm_renderformat message to window procedure

LRESULT AminDesk::u_MainWndProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
    switch (uMsg)
    {
    case WM_RENDERFORMAT: u_RenderFormat(hDlg, (uint32)wParam); return 0;
    case WM_RENDERALLFORMATS: u_RenderAllFormats(hDlg); return 0;
    case WM_DESTROYCLIPBOARD: m_strClipboard.u_SetEmpty(); break;
    case WM_CLIPBOARDUPDATE: break; //14021130 implement clipboard listen
    //other messages here
    default: break;
    }

    return DefWindowProc(hDlg, uMsg, wParam, lParam);;
}

/*---------------------------------------------------------*/
ARESULT AminDesk::u_RenderFormat(HWND hDlg, uint32 dwFormat)
{
    if (dwFormat != CF_UNICODETEXT)
        return ARESULT::NOTSUPPORTED;
    u_ShowStatus(hDlg, L"WM_RenderFormat called");

    // Allocate a buffer for the text. 
    const uint_t cchLen = a0::str_lenW(m_strClipboard);
    HGLOBAL hgClipboardData = GlobalAlloc(GMEM_MOVEABLE, (cchLen + 1) * sizeof(TCHAR));
    if (hgClipboardData == NULL)
        return ARESULT::MEMORYERROR;

    // get text
    wchar_t* lptstr = (wchar_t*)GlobalLock(hgClipboardData);
    a0::str_copyW(lptstr, cchLen + 1, m_strClipboard);
    GlobalUnlock(hgClipboardData);

    // Place the handle on the clipboard. 
    m_dwClipboardSequenceNumber = MAXUINT32;
    SetClipboardData(CF_UNICODETEXT, hgClipboardData);
    m_dwClipboardSequenceNumber = GetClipboardSequenceNumber();
    
    m_strClipboard.u_SetEmpty();
    return ARESULT::SUCCESS;
}

Every thing works fine and the text is pasted in computer2 control.

Problem occurs here:

In Computer2 I copy text to clipboard. Computer2 sends text to computer1 successfully. Computer1 calls u_DelayedRendring successfully.

But WM_RENDERFORMAT is not sent to window proc.

If I don't use delayed rendering and put text directly to clipboared (change #if 00 to #if !00), The problem is solved and Every thing is fine. but I want to use delayed rendering because I want to add file copy and paste to my application.

I am googling for 3 days with no success. Googling doesn't show any problem with clipboard delayed rendring. Since remote desktop applications like anydesk, teamviewer and microsoft remote desktop work correctly, I think there is a problem with my code but I can't figure out where is the problem.

Any idea, help or link appreciated Thanks in advance abdolazadeh

0

There are 0 best solutions below