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

📄 winsite.cpp

📁 著名的 helix realplayer 基于手机 symbian 系统的 播放器全套源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/* ***** BEGIN LICENSE BLOCK ***** 
 * Version: RCSL 1.0/RPSL 1.0 
 *  
 * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 
 *      
 * The contents of this file, and the files included with this file, are 
 * subject to the current version of the RealNetworks Public Source License 
 * Version 1.0 (the "RPSL") available at 
 * http://www.helixcommunity.org/content/rpsl unless you have licensed 
 * the file under the RealNetworks Community Source License Version 1.0 
 * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 
 * in which case the RCSL will apply. You may also obtain the license terms 
 * directly from RealNetworks.  You may not use this file except in 
 * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 
 * applicable to this file, the RCSL.  Please see the applicable RPSL or 
 * RCSL for the rights, obligations and limitations governing use of the 
 * contents of the file.  
 *  
 * This file is part of the Helix DNA Technology. RealNetworks is the 
 * developer of the Original Code and owns the copyrights in the portions 
 * it created. 
 *  
 * This file, and the files included with this file, is distributed and made 
 * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
 * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 
 * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
 * 
 * Technology Compatibility Kit Test Suite(s) Location: 
 *    http://www.helixcommunity.org/content/tck 
 * 
 * Contributor(s): 
 *  
 * ***** END LICENSE BLOCK ***** */ 

#include "hxcom.h"
#include "hxtypes.h"
#include "hxwintyp.h"
#include "ihxpckts.h"
#include "hxwin.h"
#include "hxengin.h"
#include "hxsite2.h"
#include "hxevent.h"
#include "hxcomm.h"
#include "hxstrutl.h"

#include "hxvsurf.h"
#include "basesite.h"
#include "winsite.h"
//#include "hxwinver.h"
#include "hxalloc.h"
#include "diballoc.h"

#include "ihxpckts.h"
#include "hxprefs.h"
#include "hxtick.h"
#include "sitetext.h"
#include "hxcore.h"
#include "hxthread.h"

#include "hxheap.h"
#include "basesurf.h"
#include "mmx_util.h"

#include "colormap.h"

#ifdef _DEBUG
#undef HX_THIS_FILE             
static const char HX_THIS_FILE[] = __FILE__;
#endif

#define MODE_SEPERATOR                          "|"
#define REGKEY_FULLSCREEN_DATA                  "FullScreenData"
#define REGKEY_FULLSCREEN_TEST_MODES            "TestModes"
#define REGKEY_FULLSCREEN_PREFERED_MODE         "PreferedMode"
#define TEST_THRESHOLD                          30  
#define REGKEY_FULLSCREEN_POSTAGE_STAMP         "PostageStamp"
#define TEST_LENGTH                             6000

// These SPI_ flags are not defined in header files with MSDEV 5.0, so
// that is why these are needed.  These can be removed when we compile
// with a newer version of the compiler
#ifndef SPI_GETFOREGROUNDLOCKTIMEOUT
#define SPI_GETFOREGROUNDLOCKTIMEOUT 0x2000
#endif /* SPI_GETFOREGROUNDLOCKTIMEOUT */

#ifndef SPI_SETFOREGROUNDLOCKTIMEOUT
#define SPI_SETFOREGROUNDLOCKTIMEOUT 0x2001
#endif /* SPI_SETFOREGROUNDLOCKTIMEOUT */


#define NO_HOOK_FOUND_RETURNING_WITH_ZERO 0
CHXMapPtrToPtr      CHXWinSite::zm_ParentWnds;
CHXMapPtrToPtr      CHXWinSite::zm_ParentsThreadList;
CHXMapPtrToPtr      CHXWinSite::zm_SubclassedWnds;
CHXMapPtrToPtr      CHXWinSite::zm_ScrollBarWnds;
CHXMapPtrToPtr      CHXWinSite::zm_ListOfHiddenWindows;
char*               CHXWinSite::zm_pszWindowClassName       = "HXWinVideoClass";
char*               CHXWinSite::zm_pszWindowName            = "HXWinVideoWindow";
INT32               CHXWinSite::zm_nInstanceCount           = 0;

BOOL g_bPrintSiteData = FALSE;


// convert from HXxPoint pt to Windows POINT
POINT WINPOINT(HXxPoint pt)
{
    POINT winPt;
    
    winPt.x = pt.x;
    winPt.y = pt.y;
    
    return winPt;
}

BOOL CALLBACK HXxRemoveWindows( HWND hwnd, LPARAM lParam)
{
    void* This;
    BOOL bVisible;
    
    if (!CHXWinSite::zm_SubclassedWnds.Lookup((void*)hwnd,This))
    {
        bVisible = IsWindowVisible(hwnd);
        if (bVisible)
        {
            CHXWinSite::zm_ListOfHiddenWindows.SetAt(hwnd, hwnd);
            ::ShowWindow(hwnd, SW_HIDE);
        }
    }
    
    return TRUE;
}


/************************************************************************
 *  Method:
 *    Constructor
 */
CHXWinSite::CHXWinSite(IUnknown* pContext, IUnknown* pUnkOuter, INT32 lZorder)
    : CHXBaseSite(pContext, pUnkOuter, lZorder)
    , m_oldWndProc(NULL)
    , m_hXSlider(NULL)
    , m_hYSlider(NULL)
    , m_windowParent(NULL)
    , m_pContainingWindow(NULL)
{
    InitializeCriticalSection(&m_CriticalSection);
    m_ulSiteThreadID = GetCurrentThreadId();
}


/************************************************************************
 *  Method:
 *    Destructor
 */
CHXWinSite::~CHXWinSite()
{                   
    DeleteCriticalSection(&m_CriticalSection);
    UnHookParents();
}

void 
CHXWinSite::_NeedWindowedSite()
{
    UINT32 ulFlags = WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
    if (m_bIsVisible)
    {
        ulFlags |= WS_VISIBLE;
    }

    if (m_pTopLevelSite && m_pTopLevelSite->m_pWindow)
    {
        Create(m_pTopLevelSite->m_pWindow->window, ulFlags);
    }
}

/************************************************************************
 *  Method:
 *    IHXSiteWindowed::Create
 */
void* 
CHXWinSite::_Create(void* ParentWindow, UINT32 style)
{
/*
 * Make sure the window class is registered.
 */
    
    RegisterClass();
    
    HWND hWnd = CreateWindowEx(NULL,
                               zm_pszWindowClassName, 
                               zm_pszWindowName, 
                               style, 
                               0, 
                               0,
                               0,
                               0,
                               (HWND)ParentWindow, 
                               NULL, 
                               GetModuleHandle(NULL), 
                               NULL);
    
    return hWnd;
}

/************************************************************************
 *  Method:
 *    IHXSiteWindowed::Destroy
 */
void 
CHXWinSite::_Destroy(HXxWindow* pWindow) 
{
    BOOL retVal = ::DestroyWindow((HWND) pWindow->window);
    UnRegisterClass();
}

/************************************************************************
 *  Method:
 *    CHXBaseSite::AttachWindow
 */
void 
CHXWinSite::_AttachWindow()
{
    HX_ASSERT(GetWindow() && GetWindow()->window);
    
    m_oldWndProc = (WNDPROC)::GetWindowLong((HWND)GetWindow()->window, GWL_WNDPROC);
    ::SetWindowLong((HWND)GetWindow()->window, GWL_WNDPROC,(DWORD)HXxWinHookSiteProc);
    zm_SubclassedWnds.SetAt(GetWindow()->window,this);
    
    if (!m_pParentSite)
    {
        HookParents();
    }
}


/************************************************************************
 *  Method:
 *    IHXSiteWindowed::DetachWindow
 */
void CHXWinSite::_DetachWindow()
{
    ::SetWindowLong((HWND)GetWindow()->window, GWL_WNDPROC,(DWORD)m_oldWndProc);
    zm_SubclassedWnds.RemoveKey(GetWindow()->window);
    
    UnHookParents();
    m_oldWndProc = NULL;
}

/************************************************************************
 *  Function:
 *    CHXWinSiteWindowedProc
 */
LRESULT HXEXPORT CHXWinSiteWindowedProc
(
    HWND hWnd,
    UINT message,
    WPARAM uParam,
    LPARAM lParam
    )
{
    return (DefWindowProc(hWnd, message, uParam, lParam));
}


/************************************************************************
 *  Function:
 *    RegisterClass
 */
void
CHXWinSite::RegisterClass()
{
    if (0 == zm_nInstanceCount)
    {
        WNDCLASS wndClass;
        ATOM result;
        
        wndClass.style = 0; 
        wndClass.lpfnWndProc = CHXWinSiteWindowedProc; 
        wndClass.cbClsExtra = 0; 
        wndClass.cbWndExtra = 0; 
        wndClass.hInstance = GetModuleHandle(NULL);
        wndClass.hIcon = NULL; 
        wndClass.hCursor = NULL; 
        wndClass.hbrBackground = NULL;
        wndClass.lpszMenuName = NULL; 
        wndClass.lpszClassName = zm_pszWindowClassName; 
        
        result = ::RegisterClass(&wndClass);
        HX_ASSERT(result);
    }
    zm_nInstanceCount++;
}

/************************************************************************
 *  Function:
 *    UnRegisterClass
 */
void
CHXWinSite::UnRegisterClass()
{
    HX_ASSERT(zm_nInstanceCount > 0);
    
    if (zm_nInstanceCount > 0)
    {
        zm_nInstanceCount--;
    }
    
    if (0 == zm_nInstanceCount)
    {
        BOOL result = ::UnregisterClass(zm_pszWindowClassName,GetModuleHandle(NULL));
        HX_ASSERT(result);
    }
}

void CHXWinSite::HookParents()
{
    HWND hWnd = (HWND)GetWindow()->window;
    
    DWORD process = 0;

    while (hWnd)
    {
        int thread = GetWindowThreadProcessId(hWnd, &process);
        CParentWindowThreadData* pData = NULL;
        int threadRefCount = 0;
        
        if (!CHXWinSite::zm_ParentsThreadList.Lookup((void*)thread, (void*&) pData))
        {
            pData = new CParentWindowThreadData();
            pData->m_hHook              = SetWindowsHookEx(WH_KEYBOARD, (HOOKPROC)HXxWinHookChar, NULL, thread); 
            pData->m_hHookAllMessage    = SetWindowsHookEx(WH_CALLWNDPROC, (HOOKPROC)HXxWinHookAllMessages, NULL, thread); 
            CHXWinSite::zm_ParentsThreadList.SetAt((void*)thread, (void*)pData);
        }
    
        /*
         *  Don't I wish I could keep a simple RefCount. The problem with that 
         *  would be if ANY of these parent poped out of the chain (a possiblility)
         *  then we would not remove the hook. And you know what happens if we 
         *  do not remove the hook ... boom *crash IE*. And people do not like that.
         */

        if (!pData->m_ListOfTopLevelSites.Find(m_pTopLevelSite))
        {
            pData->m_ListOfTopLevelSites.AddTail(m_pTopLevelSite);
        }

        CHXSimpleList* pChildrenList;
        if (!CHXWinSite::zm_ParentWnds.Lookup((void*)hWnd,(void*&) pChildrenList))
        {
            pChildrenList = new CHXSimpleList;
            CHXWinSite::zm_ParentWnds.SetAt((void*)hWnd, (void*)pChildrenList);
        }
        
        LISTPOSITION pos = pChildrenList->Find(this);
        HX_ASSERT(pos == NULL);
        if (!pos)
        {
            pChildrenList->AddTail(this);
        }
        hWnd = GetParent(hWnd);
    }
}

void 
CHXWinSite::UnHookParents()
{
/* 
 * make sure to remove any reference to this object from the parent map.
 * We do not use Getparent calls here since the parent chain may have 
 * changed AFTER call to HookParents().
 *
 */
    HWND hWnd;
    CHXSimpleList* pChildrenList;
    POSITION pos = zm_ParentWnds.GetStartPosition();
    while (pos)
    {
        zm_ParentWnds.GetNextAssoc(pos, (void*&) hWnd, (void*&) pChildrenList);
        LISTPOSITION listpos = pChildrenList->Find(this);
        
        if (listpos)
        {
            pChildrenList->RemoveAt(listpos);
            
            if (!pChildrenList->GetCount())
            {
                pos = CHXWinSite::zm_ParentWnds.Remove((void*)hWnd);
                HX_DELETE(pChildrenList);
            }
        }
    }

    /* are we a top level site? If so we may have to clean up
     * some of our Window Hooks.
     */

    if (m_pTopLevelSite == this)
    {
        DWORD thread;
        CParentWindowThreadData* pData = NULL;
        POSITION pos = zm_ParentsThreadList.GetStartPosition();
        while (pos)
        {
            zm_ParentsThreadList.GetNextAssoc(pos, (void*&) thread, (void*&) pData);
            LISTPOSITION listpos = pData->m_ListOfTopLevelSites.Find(this);
            
            if (listpos)
            {
                pData->m_ListOfTopLevelSites.RemoveAt(listpos);
                
                if (!pData->m_ListOfTopLevelSites.GetCount())
                {
                    UnhookWindowsHookEx(pData->m_hHook); 
                    UnhookWindowsHookEx(pData->m_hHookAllMessage);
                    pos = CHXWinSite::zm_ParentsThreadList.Remove((void*)thread);

                    delete pData;
                }

⌨️ 快捷键说明

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