⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clipboard.c

📁 这是一个开放源代码的与WINNT/WIN2K/WIN2003兼容的操作系统
💻 C
📖 第 1 页 / 共 3 页
字号:
        }
    }
    else
    {

        if (hWnd != NULL)
        {
            Window = UserGetWindowObject(hWnd);

            if (Window != NULL)
            {
                ClipboardWindow =  Window;
                ClipboardThread = PsGetCurrentThreadWin32Thread();
                ret = TRUE;
            }
            else
            {
                ClipboardWindow = NULL;
                ClipboardThread = NULL;
                ClipboardOwnerWindow = NULL;
                ClipboardOwnerThread = NULL;
            }
        }
        else
        {
            ClipboardWindow =  NULL;
            ClipboardThread = PsGetCurrentThreadWin32Thread();
            ret = TRUE;
        }
    }

    UserLeave();

    return ret;
}

BOOL STDCALL
NtUserCloseClipboard(VOID)
{
    BOOL ret = FALSE;

    UserEnterExclusive();

    if (intIsClipboardOpenByMe())
    {
        ClipboardWindow = NULL;
        ClipboardThread = NULL;
        ret = TRUE;
    }
    else
    {
        SetLastWin32Error(ERROR_CLIPBOARD_NOT_OPEN);
    }

    recentlySetClipboard = FALSE;

    UserLeave();

    if (sendDrawClipboardMsg && WindowsChain)
    {
        /* only send message to the first window in the chain, then they'll do the chain */
        /* commented because it makes a crash in co_MsqSendMessage
        ASSERT(WindowsChain->window);
        ASSERT(WindowsChain->window->hSelf);
        DPRINT1("Clipboard: sending WM_DRAWCLIPBOARD to %p\n", WindowsChain->window->hSelf);
        co_IntSendMessage(WindowsChain->window->hSelf, WM_DRAWCLIPBOARD, 0, 0);
        */
    }

    return ret;
}

HWND STDCALL
NtUserGetOpenClipboardWindow(VOID)
{
    HWND ret = NULL;

    UserEnterShared();

    if (ClipboardWindow)
    {
        ret = ClipboardWindow->hSelf;
    }

    UserLeave();

    return ret;
}

BOOL STDCALL
NtUserChangeClipboardChain(HWND hWndRemove, HWND hWndNewNext)
{
    BOOL ret = FALSE;
    PCLIPBOARDCHAINELEMENT w = NULL;
    PWINDOW_OBJECT removeWindow;
    UserEnterExclusive();

    removeWindow = UserGetWindowObject(hWndRemove);

    if (removeWindow)
    {
        if ((ret = !!IntIsWindowInChain(removeWindow)))
        {
            w = IntRemoveWindowFromChain(removeWindow);
            if (w)
            {
                ExFreePool(w);
            }
        }
    }

    if (ret && WindowsChain)
    {
        // only send message to the first window in the chain,
        // then they do the chain
        
        /* WindowsChain->window may be NULL */
        LPARAM lparam = WindowsChain->window == NULL ? 0 : (LPARAM)WindowsChain->window->hSelf;
        DPRINT1("Message: WM_CHANGECBCHAIN to %p", WindowsChain->window->hSelf);
        co_IntSendMessage(WindowsChain->window->hSelf, WM_CHANGECBCHAIN, (WPARAM)hWndRemove, lparam);
    }

    UserLeave();

    return ret;
}

DWORD STDCALL
NtUserCountClipboardFormats(VOID)
{
    DWORD ret = 0;

    if (ClipboardData)
    {
       ret = IntCountClipboardFormats();
    }

    return ret;
}

DWORD STDCALL
NtUserEmptyClipboard(VOID)
{
    BOOL ret = FALSE;

    UserEnterExclusive();

    if (intIsClipboardOpenByMe())
    {
        if (ClipboardData)
        {
            IntEmptyClipboardData();
        }

        ClipboardOwnerWindow = ClipboardWindow;
        ClipboardOwnerThread = ClipboardThread;

        IntIncrementSequenceNumber();

        ret = TRUE;
    }
    else
    {
        SetLastWin32Error(ERROR_CLIPBOARD_NOT_OPEN);
    }

    if (ret && ClipboardOwnerWindow)
    {
        DPRINT1("Clipboard: WM_DESTROYCLIPBOARD to %p", ClipboardOwnerWindow->hSelf);
        co_IntSendMessage( ClipboardOwnerWindow->hSelf, WM_DESTROYCLIPBOARD, 0, 0);
    }

    UserLeave();

    return ret;
}

HANDLE STDCALL
NtUserGetClipboardData(UINT uFormat, DWORD Unknown1)
{
    HANDLE ret = NULL;
    PCHAR buffer;

    UserEnterShared();

    if (intIsClipboardOpenByMe())
    {
        /* when Unknown1 is zero, we returns to user32 the data size */
        if (Unknown1 == 0)
        {
            PCLIPBOARDELEMENT data = intIsFormatAvailable(uFormat);

            if (data)
            {
                /* format exists in clipboard */
                if (data->size == DATA_DELAYED_RENDER)
                {
                    /* tell owner what data needs to be rendered */
                    if (ClipboardOwnerWindow)
                    {
                        ASSERT(ClipboardOwnerWindow->hSelf);
                        co_IntSendMessage(ClipboardOwnerWindow->hSelf, WM_RENDERFORMAT, (WPARAM)uFormat, 0);
                        data = intIsFormatAvailable(uFormat);
                        ASSERT(data->size);
                        ret = (HANDLE)data->size;
                    }
                }
                else
                {
                    if (data->size == DATA_SYNTHESIZED_RENDER)
                    {
                        data->size = synthesizeData(uFormat);
                    }

                }
                ret = (HANDLE)data->size;
            }
            else
            {
                /* there is no data in this format */
                //ret = (HANDLE)FALSE;
            }
        }
        else
        {
            PCLIPBOARDELEMENT data = intIsFormatAvailable(uFormat);

            if (data)
            {
                if (data->size == DATA_DELAYED_RENDER)
                {
                    // we rendered it in 1st call of getclipboard data
                }
                else
                {
                    if (data->size == DATA_SYNTHESIZED_RENDER)
                    {
                        if (uFormat == CF_BITMAP)
                        {
                            /* BITMAP & METAFILEs returns a GDI handle */
                            PCLIPBOARDELEMENT data = intIsFormatAvailable(CF_DIB);
                            if (data)
                            {
                                ret = renderBITMAPfromDIB(data->hData);
                            }
                        }
                        else
                        {
                            buffer = (PCHAR)Unknown1;
                            memcpy(buffer, (PCHAR)synthesizedData, synthesizedDataSize);

                            freeSynthesizedData();

                            ret = (HANDLE)Unknown1;
                        }
                    }
                    else
                    {
                        buffer = (PCHAR)Unknown1;
                        memcpy(buffer, (PCHAR)data->hData, data->size);

                        ret = (HANDLE)Unknown1;
                    }
                }

            }

        }
    }
    else
    {
        SetLastWin32Error(ERROR_CLIPBOARD_NOT_OPEN);
    }

    UserLeave();

    return ret;
}

INT STDCALL
NtUserGetClipboardFormatName(UINT format, PUNICODE_STRING FormatName,
                             INT cchMaxCount)
{
    UNICODE_STRING sFormatName;
    INT ret = 0;

    /* if the format is built-in we fail */
    if (format < 0xc000)
    {
        /* registetrated formats are >= 0xc000 */
        return 0;
    }

    if((cchMaxCount < 1) || !FormatName)
    {
        SetLastWin32Error(ERROR_INVALID_PARAMETER);
        return 0;
    }

    _SEH_TRY
    {
        ProbeForWriteUnicodeString(FormatName);
        sFormatName = *(volatile UNICODE_STRING *)FormatName;
        ProbeForWrite(sFormatName.Buffer, sFormatName.MaximumLength, 1);

        ret = IntGetAtomName((RTL_ATOM)format, sFormatName.Buffer, cchMaxCount * sizeof(WCHAR));

        if (ret >= 0)
        {
            ret = ret / sizeof(WCHAR);
            sFormatName.Length = ret;
        }
        else
        {
            ret = 0;
        }
    }
    _SEH_HANDLE
    {
        SetLastNtError(_SEH_GetExceptionCode());
    }
    _SEH_END;

    return ret;
}

UINT STDCALL
NtUserRegisterClipboardFormat(PUNICODE_STRING FormatName)
{
    UINT ret = 0;
    UNICODE_STRING cFormatName = {0};

    if (FormatName == NULL)
    {
        SetLastWin32Error(ERROR_INVALID_PARAMETER);
        return ret;
    }

    UserEnterExclusive();

    _SEH_TRY
    {
        cFormatName = ProbeForReadUnicodeString(FormatName);

        if (cFormatName.Length > 0)
        {
            ret = (UINT)IntAddAtom(cFormatName.Buffer);
            //RtlFreeUnicodeString(&cFormatName);
        }
        else
        {
            SetLastWin32Error(ERROR_INVALID_NAME);
            _SEH_LEAVE;
        }

    }
    _SEH_HANDLE
    {
        SetLastNtError(_SEH_GetExceptionCode());
    }
    _SEH_END;

    UserLeave();

    return ret;
}


HWND STDCALL
NtUserGetClipboardOwner(VOID)
{
    HWND ret = NULL;

    UserEnterShared();

    if (ClipboardOwnerWindow)
    {
        ret = ClipboardOwnerWindow->hSelf;
    }

    UserLeave();

    return ret;
}

HWND STDCALL
NtUserGetClipboardViewer(VOID)
{
    HWND ret = NULL;

    UserEnterShared();

    if (WindowsChain)
    {
        ret = WindowsChain->window->hSelf;
    }

    UserLeave();

    return ret;
}

INT STDCALL
NtUserGetPriorityClipboardFormat(UINT *paFormatPriorityList, INT cFormats)
{
    INT i;
    UINT *priorityList;
    INT ret = 0;

    UserEnterExclusive();

    _SEH_TRY
    {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -