OLECONTAINER(BOOL)::Create(GUID clsid, DWORD dwExStyle, DWORD dwStyle, HWND hWndParent, HINSTANCE hInst) { m_hWndParent = hWndParent; m_hInst = hInst; m_CLSID = clsid; m_bTransparent = (dwExStyle & WS_EX_LAYERED) ? TRUE : FALSE; m_bChild = (dwStyle & WS_CHILD) ? TRUE : FALSE; WNDCLASSEX wcs = {0}; wcs.cbSize = sizeof(WNDCLASSEX); wcs.lpfnWndProc = COleContainerWnd<TObj>::WndProcStatic; wcs.hInstance = hInst; wcs.lpszClassName = W2X_FLASH_WND_CLASS; RegisterClassEx(&wcs); RECT rt = {0}; if (NULL != hWndParent) { if (m_bChild) { ::GetClientRect(hWndParent, &rt); } else { ::GetWindowRect(hWndParent, &rt); } } else { rt.right = rt.left + 32; rt.bottom = rt.top + 32; } m_hWnd = CreateWindowEx(dwExStyle, W2X_FLASH_WND_CLASS, m_wnd_name_ptr, dwStyle, rt.left, rt.top, rt.right - rt.left, rt.bottom - rt.top, hWndParent, NULL, hInst, (void *)this); HRESULT hr; hr = OleCreate(m_CLSID, IID_IOleObject, OLERENDER_DRAW, 0, (IOleClientSite *)this, (IStorage *)this, (void **)&m_lpO); if (FAILED(hr)) { if (hr == REGDB_E_CLASSNOTREG) { OnErrorClassNotReg(); } return FALSE; } hr = OleSetContainedObject(m_lpO, TRUE); if (FAILED(hr)) return FALSE; hr = m_lpO->QueryInterface(__uuidof(TObj), (void **)&m_lpControl); if (FAILED(hr)) return FALSE; hr = m_lpO->QueryInterface(IID_IViewObjectEx, (void **)&m_lpViewObjectEx); if (FAILED(hr)) { m_lpViewObjectEx = NULL; hr = m_lpO->QueryInterface(IID_IViewObject, (void **)&m_lpViewObject); if (FAILED(hr)) return FALSE; } if (m_bTransparent) { hr = m_lpO->QueryInterface(IID_IOleInPlaceObjectWindowless, (void **)&m_lpInPlaceObjWindowless); if (FAILED(hr)) { hr = m_lpO->QueryInterface(IID_IOleInPlaceObject, (void **)&m_lpInPlaceObj); if (FAILED(hr)) return FALSE; m_bTransparent = FALSE; } } else { hr = m_lpO->QueryInterface(IID_IOleInPlaceObject, (void **)&m_lpInPlaceObj); if (FAILED(hr)) return FALSE; } if (!OnBeforeShowingContent()) return FALSE; hr = m_lpO->DoVerb(OLEIVERB_SHOW, NULL, (IOleClientSite *)this, 0, NULL, NULL); if (FAILED(hr)) return FALSE; if (!OnAfterShowingContent()) return FALSE; return TRUE; }
//创建函数 OLECONTAINER_FUNCTION(BOOL)::Create(GUID clsid, DWORD dwExStyle, DWORD dwStyle, HWND hWndParent, HINSTANCE hInstance) { m_bTransparent=dwExStyle&WS_EX_LAYERED; //变量定义 WNDCLASSEX WndClassEx; ZeroMemory(&WndClassEx,sizeof(WndClassEx)); //设置变量 WndClassEx.cbSize=sizeof(WNDCLASSEX); WndClassEx.hInstance=hInstance; WndClassEx.lpszClassName=WND_FLASH_CLASS; WndClassEx.lpfnWndProc=COleContainerWnd<TControl>::WndProcStatic; //注册窗口 RegisterClassEx(&WndClassEx); CRect rcRect; if (dwStyle&WS_CHILD) ::GetClientRect(hWndParent, &rcRect); else ::GetWindowRect(hWndParent, &rcRect); m_hWnd=CreateWindowEx(dwExStyle,WND_FLASH_CLASS,NULL,dwStyle,rcRect.left,rcRect.top,rcRect.Width(),rcRect.Height(),hWndParent,NULL,hInstance,(VOID *)this); ::SetWindowPos(m_hWnd,HWND_TOP,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE); HRESULT hResult; hResult=OleCreate(clsid, IID_IOleObject, OLERENDER_DRAW,0,(IOleClientSite *)this,(IStorage *)this,(VOID **)&m_pIOleObject); if (FAILED(hResult)) { static bool bShow=true; if (hResult==REGDB_E_CLASSNOTREG && bShow) { bShow=false; //提示消息 CInformation Information; if (IDOK==Information.ShowMessageBox(TEXT("系统提示"),TEXT("您的FLASH播放器版本过低,为了正常使用功能,请您下载最新的Flash插件。点击确定最新的Flash插件 "),MB_OKCANCEL,30)) { //打开页面 ShellExecute(NULL,TEXT("OPEN"),TEXT("http://www.adobe.com/go/getflashplayer"),NULL,NULL,SW_NORMAL); } OnErrorClassNotReg(); } return FALSE; } if (FAILED(OleSetContainedObject(m_pIOleObject, TRUE))) return FALSE; if (FAILED(m_pIOleObject->QueryInterface(__uuidof(TControl), (VOID **)&m_pIControl))) return FALSE; if (FAILED(m_pIOleObject->QueryInterface(IID_IViewObjectEx, (VOID **)&m_pIViewObjectEx))) { m_pIViewObjectEx=NULL; if (FAILED(m_pIOleObject->QueryInterface(IID_IViewObject, (VOID **)&m_pIViewObject))) return FALSE; } if (m_bTransparent) { if (FAILED(m_pIOleObject->QueryInterface(IID_IOleInPlaceObjectWindowless, (VOID **)&m_pIOleInPlaceObjectWindowless))) { if (FAILED(m_pIOleObject->QueryInterface(IID_IOleInPlaceObject, (VOID **)&m_pIOleInPlaceObject))) return FALSE; m_bTransparent=FALSE; } } else { if (FAILED(m_pIOleObject->QueryInterface(IID_IOleInPlaceObject, (VOID **)&m_pIOleInPlaceObject))) return FALSE; } if (!OnBeforeShowingContent()) return FALSE; if (FAILED(m_pIOleObject->DoVerb(OLEIVERB_SHOW, NULL, (IOleClientSite *)this, 0, NULL, NULL))) return FALSE; if (!OnAfterShowingContent()) return FALSE; INT nScreenW=GetSystemMetrics(SM_CXSCREEN); INT nScreenH=GetSystemMetrics(SM_CYSCREEN); ::SetWindowPos(m_hWnd,HWND_TOPMOST,(nScreenW-rcRect.Width())/2, (nScreenH-rcRect.Height())/2, 0, 0, SWP_NOSIZE); return TRUE; }
OLECONTAINER(BOOL)::Create(GUID clsid, DWORD dwExStyle, DWORD dwStyle, HWND hWndParent, HINSTANCE hInst) { m_hWndParent = hWndParent; m_hInst = hInst; m_CLSID = clsid; m_bTransparent = dwExStyle & WS_EX_LAYERED; m_bChild = dwStyle & WS_CHILD; WNDCLASSEX wcs = {0}; wcs.cbSize = sizeof(WNDCLASSEX); wcs.lpfnWndProc = COleContainerWnd<TObj>::WndProcStatic; wcs.hInstance = hInst; wcs.lpszClassName = "MyOleControl"; RegisterClassEx(&wcs); RECT r; if (m_bChild) ::GetClientRect(hWndParent, &r); else ::GetWindowRect(hWndParent, &r); m_hWnd = CreateWindowEx(dwExStyle, "MyOleControl", "MyOleControlWindow", dwStyle, r.left, r.top, r.right-r.left, r.bottom-r.top, hWndParent, NULL, hInst, (void *)this); ::SetWindowPos(GetHWND(), HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); HRESULT hr; hr = OleCreate(m_CLSID, IID_IOleObject, OLERENDER_DRAW, 0, (IOleClientSite *)this, (IStorage *)this, (void **)&m_lpO); if (FAILED(hr)) { if (hr == REGDB_E_CLASSNOTREG) { OnErrorClassNotReg(); } return FALSE; } hr = OleSetContainedObject(m_lpO, TRUE); if (FAILED(hr)) return FALSE; hr = m_lpO->QueryInterface(__uuidof(TObj), (void **)&m_lpControl); if (FAILED(hr)) return FALSE; hr = m_lpO->QueryInterface(IID_IViewObjectEx, (void **)&m_lpViewObjectEx); if (FAILED(hr)) { m_lpViewObjectEx = NULL; hr = m_lpO->QueryInterface(IID_IViewObject, (void **)&m_lpViewObject); if (FAILED(hr)) return FALSE; } if (m_bTransparent) { hr = m_lpO->QueryInterface(IID_IOleInPlaceObjectWindowless, (void **)&m_lpInPlaceObjWindowless); if (FAILED(hr)) { hr = m_lpO->QueryInterface(IID_IOleInPlaceObject, (void **)&m_lpInPlaceObj); if (FAILED(hr)) return FALSE; m_bTransparent = FALSE; } } else { hr = m_lpO->QueryInterface(IID_IOleInPlaceObject, (void **)&m_lpInPlaceObj); if (FAILED(hr)) return FALSE; } if (!OnBeforeShowingContent()) return FALSE; hr = m_lpO->DoVerb(OLEIVERB_UIACTIVATE, NULL, (IOleClientSite *)this, 0, NULL, NULL); //hr = m_lpO->DoVerb(OLEIVERB_UIACTIVATE, NULL, (IOleClientSite *)this, 0, NULL, NULL); if (FAILED(hr)) return FALSE; if (!OnAfterShowingContent()) return FALSE; return TRUE; }