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

📄 tbsite.c

📁 ReactOS是一些高手根据Windows XP的内核编写出的类XP。内核实现机理和API函数调用几乎相同。甚至可以兼容XP的程序。喜欢研究系统内核的人可以看一看。
💻 C
📖 第 1 页 / 共 3 页
字号:
                                          const GUID *pguidCmdGroup,
                                          DWORD nCmdID,
                                          DWORD nCmdExecOpt,
                                          VARIANTARG *pvaIn,
                                          VARIANTARG *pvaOut)
{
    IOleCommandTarget *pOct;
    DWORD dwBandID;
    UINT uBand = 0;

    /* Enumerate all bands */
    while (SUCCEEDED(IBandSite_EnumBands(This->BandSite,
                                         uBand,
                                         &dwBandID)))
    {
        if (SUCCEEDED(IBandSite_GetBandObject(This->BandSite,
                                              uBand,
                                              &IID_IOleCommandTarget,
                                              (PVOID*)&pOct)))
        {
            /* Execute the command */
            IOleCommandTarget_Exec(pOct,
                                   pguidCmdGroup,
                                   nCmdID,
                                   nCmdExecOpt,
                                   pvaIn,
                                   pvaOut);

            IOleCommandTarget_Release(pOct);
        }

        uBand++;
    }
}

static HRESULT
ITrayBandSiteImpl_FinishInit(IN OUT ITrayBandSiteImpl *This)
{
    /* Broadcast the DBID_FINISHINIT command */
    ITrayBandSiteImpl_BroadcastOleCommandExec(This,
                                              &IID_IDeskBand,
                                              DBID_FINISHINIT,
                                              0,
                                              NULL,
                                              NULL);

    return S_OK;
}

static HRESULT
ITrayBandSiteImpl_Show(IN OUT ITrayBandSiteImpl *This,
                       IN BOOL bShow)
{
    IDeskBarClient *pDbc;
    HRESULT hRet;

    hRet = IBandSite_QueryInterface(This->BandSite,
                                    &IID_IDeskBarClient,
                                    (PVOID*)&pDbc);
    if (SUCCEEDED(hRet))
    {
        hRet = IDeskBarClient_UIActivateDBC(pDbc,
                                            bShow ? DBC_SHOW : DBC_HIDE);
        IDeskBarClient_Release(pDbc);
    }

    return hRet;
}

static HRESULT
ITrayBandSiteImpl_LoadFromStream(IN OUT ITrayBandSiteImpl *This,
                                 IN OUT IStream *pStm)
{
    IPersistStream *pPStm;
    HRESULT hRet;

    ASSERT(This->BandSite != NULL);

    /* We implement the undocumented COM interface IBandSiteStreamCallback
       that the shell will query so that we can intercept and custom-load
       the task band when it finds the task band's CLSID (which is internal).
       This way we can prevent the shell from attempting to CoCreateInstance
       the (internal) task band, resulting in a failure... */
    hRet = IBandSite_QueryInterface(This->BandSite,
                                    &IID_IPersistStream,
                                    (PVOID*)&pPStm);
    if (SUCCEEDED(hRet))
    {
        hRet = IPersistStream_Load(pPStm,
                                   pStm);
        DbgPrint("IPersistStream_Load() returned 0x%x\n", hRet);
        IPersistStream_Release(pPStm);
    }

    return hRet;
}

static IStream *
GetUserBandsStream(IN DWORD grfMode)
{
    HKEY hkStreams;
    IStream *Stream = NULL;

    if (RegCreateKey(hkExplorer,
                     TEXT("Streams"),
                     &hkStreams) == ERROR_SUCCESS)
    {
        Stream = SHOpenRegStream(hkStreams,
                                 TEXT("Desktop"),
                                 TEXT("TaskbarWinXP"),
                                 grfMode);

        RegCloseKey(hkStreams);
    }

    return Stream;
}

static IStream *
GetDefaultBandsStream(IN DWORD grfMode)
{
    HKEY hkStreams;
    IStream *Stream = NULL;

    if (RegCreateKey(HKEY_LOCAL_MACHINE,
                     TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Streams"),
                     &hkStreams) == ERROR_SUCCESS)
    {
        Stream = SHOpenRegStream(hkStreams,
                                 TEXT("Desktop"),
                                 TEXT("Default Taskbar"),
                                 grfMode);

        RegCloseKey(hkStreams);
    }

    return Stream;
}

static HRESULT
ITrayBandSiteImpl_Load(IN OUT ITrayBandSiteImpl *This)
{
    IStream *pStm;
    HRESULT hRet;

    /* Try to load the user's settings */
    pStm = GetUserBandsStream(STGM_READ);
    if (pStm != NULL)
    {
        hRet = ITrayBandSiteImpl_LoadFromStream(This,
                                                pStm);

        DbgPrint("Loaded user bands settings: 0x%x\n", hRet);
        IStream_Release(pStm);
    }
    else
        hRet = E_FAIL;

    /* If the user's settings couldn't be loaded, try with
       default settings (ie. when the user logs in for the
       first time! */
    if (!SUCCEEDED(hRet))
    {
        pStm = GetDefaultBandsStream(STGM_READ);
        if (pStm != NULL)
        {
            hRet = ITrayBandSiteImpl_LoadFromStream(This,
                                                    pStm);

            DbgPrint("Loaded default user bands settings: 0x%x\n", hRet);
            IStream_Release(pStm);
        }
        else
            hRet = E_FAIL;
    }

    return hRet;
}

static ITrayBandSiteImpl *
ITrayBandSiteImpl_Construct(IN OUT ITrayWindow *Tray,
                            OUT HWND *phWndRebar,
                            OUT HWND *phwndTaskSwitch)
{
    ITrayBandSiteImpl *This;
    IDeskBarClient *pDbc;
    IDeskBand *pDb;
    IOleWindow *pOw;
    HRESULT hRet;

    *phWndRebar = NULL;
    *phwndTaskSwitch = NULL;

    This = HeapAlloc(hProcessHeap,
                     0,
                     sizeof(*This));
    if (This == NULL)
        return NULL;

    ZeroMemory(This,
               sizeof(*This));
    This->lpVtbl = &ITrayBandSiteImpl_Vtbl;
    This->lpBandSiteVtbl = &IBandSiteImpl_Vtbl;
    This->Ref = 1;
    This->Tray = Tray;

    /* Create a RebarBandSite provided by the shell */
    hRet = CoCreateInstance(&CLSID_RebarBandSite,
                            (LPUNKNOWN)IBandSite_from_ITrayBandSiteImpl(This),
                            CLSCTX_INPROC_SERVER,
                            &IID_IUnknown,
                            (LPVOID*)&This->punkInner);
    if (!SUCCEEDED(hRet))
    {
        ITrayBandSiteImpl_Free(This);
        return NULL;
    }

    hRet = IUnknown_QueryInterface(This->punkInner,
                                   &IID_IBandSite,
                                   (PVOID*)&This->BandSite);
    if (!SUCCEEDED(hRet))
    {
        ITrayBandSiteImpl_Free(This);
        return NULL;
    }

    hRet = IUnknown_QueryInterface(This->punkInner,
                                   &IID_IWindowEventHandler,
                                   (PVOID*)&This->WindowEventHandler);
    if (!SUCCEEDED(hRet))
    {
        ITrayBandSiteImpl_Free(This);
        return NULL;
    }

    This->TaskBand = CreateTaskBand(Tray);
    if (This->TaskBand != NULL)
    {
        /* Add the task band to the site */
        hRet = IBandSite_QueryInterface(This->BandSite,
                                        &IID_IDeskBarClient,
                                        (PVOID*)&pDbc);
        if (SUCCEEDED(hRet))
        {
            hRet = ITaskBand_QueryInterface(This->TaskBand,
                                            &IID_IOleWindow,
                                            (PVOID*)&pOw);
            if (SUCCEEDED(hRet))
            {
                /* We cause IDeskBarClient to create the rebar control by passing the new
                   task band to it. The band reports the tray window handle as window handle
                   so that IDeskBarClient knows the parent window of the Rebar control that
                   it wants to create. */
                hRet = IDeskBarClient_SetDeskBarSite(pDbc,
                                                     (IUnknown *)pOw);

                if (SUCCEEDED(hRet))
                {
                    /* The Rebar control is now created, we can query the window handle */
                    hRet = IDeskBarClient_GetWindow(pDbc,
                                                    &This->hWndRebar);

                    if (SUCCEEDED(hRet))
                    {
                        /* We need to manually remove the RBS_BANDBORDERS style! */
                        SetWindowStyle(This->hWndRebar,
                                       RBS_BANDBORDERS,
                                       0);
                    }
                }

                IOleWindow_Release(pOw);
            }

            if (SUCCEEDED(hRet))
            {
                DWORD dwMode = 0;

                /* Set the Desk Bar mode to the current one */

                /* FIXME: We need to set the mode (and update) whenever the user docks
                          the tray window to another monitor edge! */

                if (!ITrayWindow_IsHorizontal(This->Tray))
                    dwMode = DBIF_VIEWMODE_VERTICAL;

                hRet = IDeskBarClient_SetModeDBC(pDbc,
                                                 dwMode);
            }

            IDeskBarClient_Release(pDbc);
        }

        /* Load the saved state of the task band site */
        /* FIXME: We should delay loading shell extensions, also see DBID_DELAYINIT */
        ITrayBandSiteImpl_Load(This);

        /* Add the task bar band if it hasn't been added already */
        hRet = ITrayBandSiteImpl_AddTaskBand(This);
        if (SUCCEEDED(hRet))
        {
            hRet = ITaskBand_QueryInterface(This->TaskBand,
                                            &IID_IDeskBand,
                                            (PVOID*)&pDb);
            if (SUCCEEDED(hRet))
            {
                hRet = IDeskBand_GetWindow(pDb,
                                           phwndTaskSwitch);
                if (!SUCCEEDED(hRet))
                    *phwndTaskSwitch = NULL;

                IDeskBand_Release(pDb);
            }
        }

        /* Should we send this after showing it? */
        ITrayBandSiteImpl_Update(This);

        /* FIXME: When should we send this? Does anyone care anyway? */
        ITrayBandSiteImpl_FinishInit(This);

        /* Activate the band site */
        ITrayBandSiteImpl_Show(This,
                               TRUE);
    }

    *phWndRebar = This->hWndRebar;

    return This;
}

/*******************************************************************/

ITrayBandSite *
CreateTrayBandSite(IN OUT ITrayWindow *Tray,
                   OUT HWND *phWndRebar,
                   OUT HWND *phWndTaskSwitch)
{
    ITrayBandSiteImpl *This;

    This = ITrayBandSiteImpl_Construct(Tray,
                                       phWndRebar,
                                       phWndTaskSwitch);
    if (This != NULL)
    {
        return ITrayBandSite_from_ITrayBandSiteImpl(This);
    }

    return NULL;
}

⌨️ 快捷键说明

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