【译】用于多媒体应用的无窗口ATL ActiveX控件容器
来源:互联网 发布:读卡器软件 编辑:程序博客网 时间:2024/05/20 18:48
原文链接:ATL Windowless ActiveX Media Container
这个ATL activeX框架适用于作为Windows Media Player,Flash以及Sliverlight动画的承载容器。整个框架分布在Windowless文件夹下,共有6个文件。架构如图所示:
使用Adobe Flash Player作为子控件
主要代码如下:
class CMainDlg : public CAxWindowlessHost<CMainDlg>
LRESULT CMainDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
// center the dialog on the screen
CenterWindow();
// set icons
HICON hIcon = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME),
IMAGE_ICON, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR);
SetIcon(hIcon, TRUE);
HICON hIconSmall = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME),
IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
SetIcon(hIconSmall, FALSE);
TCHAR szPath[MAX_PATH] = { 0 };
if ( ::GetModuleFileName(NULL, szPath, MAX_PATH) > 0 )
{//定位.swf文件
LPTSTR pszSep = _tcsrchr(szPath, TCHAR('//'));
pszSep++;
*pszSep = 0;
::StringCchCat(szPath, MAX_PATH, _T("Construction.swf"));
}
// Initialize Flash Player (Shockwave .swf)
HRESULT hr;
ActiveXSite* pSite;
pSite = CAxWindowlessHost<CMainDlg>::GetControlSite(IDC_SHOCKWAVEFLASH);//获取flash player子控件
if ( pSite != NULL )
{
CComQIPtr<IShockwaveFlash> spFlash = pSite->ActiveXControl();
hr = spFlash->put_WMode( CComBSTR("Transparent") );//设置“透明”
hr = spFlash->put_Movie( CComBSTR(szPath) );//设置影片源文件
}
return TRUE;
}
LRESULT CMainDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
// center the dialog on the screen
CenterWindow();
// set icons
HICON hIcon = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME),
IMAGE_ICON, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR);
SetIcon(hIcon, TRUE);
HICON hIconSmall = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME),
IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
SetIcon(hIconSmall, FALSE);
TCHAR szPath[MAX_PATH] = { 0 };
if ( ::GetModuleFileName(NULL, szPath, MAX_PATH) > 0 )
{//定位.swf文件
LPTSTR pszSep = _tcsrchr(szPath, TCHAR('//'));
pszSep++;
*pszSep = 0;
::StringCchCat(szPath, MAX_PATH, _T("Construction.swf"));
}
// Initialize Flash Player (Shockwave .swf)
HRESULT hr;
ActiveXSite* pSite;
pSite = CAxWindowlessHost<CMainDlg>::GetControlSite(IDC_SHOCKWAVEFLASH);//获取flash player子控件
if ( pSite != NULL )
{
CComQIPtr<IShockwaveFlash> spFlash = pSite->ActiveXControl();
hr = spFlash->put_WMode( CComBSTR("Transparent") );//设置“透明”
hr = spFlash->put_Movie( CComBSTR(szPath) );//设置影片源文件
}
return TRUE;
}
使用Windows Meida Player作为子控件
主要代码如下:
LRESULT CMainDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
// center the dialog on the screen
CenterWindow();
// set icons
HICON hIcon = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME),
IMAGE_ICON, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR);
SetIcon(hIcon, TRUE);
HICON hIconSmall = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME),
IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
SetIcon(hIconSmall, FALSE);
// Initialize Windows Media Player
HRESULT hr;
ActiveXSite* pSite;
pSite = CAxWindowlessHost<CMainDlg>::GetControlSite(IDC_WMP11);//获取Meida Player子控件
if ( pSite != NULL )
{
pSite->SetAllowResize(false);//不允许自动调整大小
CComQIPtr<IWMPCore> wmp = pSite->ActiveXControl();
CComQIPtr<IWMPPlayer4> wmp4 = pSite->ActiveXControl();
// this can be done manually as well
if ( wmp4 )
{
hr = wmp4->put_windowlessVideo( VARIANT_TRUE );//无窗口模式
//hr = wmp4->put_uiMode( CComBSTR("Full") );//填充模式
}
//hr = wmp->put_URL( CComBSTR("c://temp//videofile.wmv") );//多媒体文件地址
}
return TRUE;
}
LRESULT CMainDlg::OnBnClickedBtnBrowse(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{//选择多媒体文件
static LPCTSTR pszFilter = _T("Video Files (*.avi;*.mpg;*.wmv)/0*.avi;*.mpg;*.wmv/0/0");
CFileDialog fileOpen(TRUE, _T("avi"), NULL,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, pszFilter/*, m_hWnd*/);
if ( IDOK == fileOpen.DoModal() )
{
ActiveXSite* pSite;
pSite = CAxWindowlessHost<CMainDlg>::GetControlSite(IDC_WMP11);
SetDlgItemText(IDC_TXT_FILENAME, fileOpen.m_szFileName);
CComQIPtr<IWMPPlayer4> wmp4 = pSite->ActiveXControl();
wmp4->close();
wmp4->put_URL( CComBSTR( fileOpen.m_szFileName ) );
}
return 0;
}
{
// center the dialog on the screen
CenterWindow();
// set icons
HICON hIcon = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME),
IMAGE_ICON, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR);
SetIcon(hIcon, TRUE);
HICON hIconSmall = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME),
IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
SetIcon(hIconSmall, FALSE);
// Initialize Windows Media Player
HRESULT hr;
ActiveXSite* pSite;
pSite = CAxWindowlessHost<CMainDlg>::GetControlSite(IDC_WMP11);//获取Meida Player子控件
if ( pSite != NULL )
{
pSite->SetAllowResize(false);//不允许自动调整大小
CComQIPtr<IWMPCore> wmp = pSite->ActiveXControl();
CComQIPtr<IWMPPlayer4> wmp4 = pSite->ActiveXControl();
// this can be done manually as well
if ( wmp4 )
{
hr = wmp4->put_windowlessVideo( VARIANT_TRUE );//无窗口模式
//hr = wmp4->put_uiMode( CComBSTR("Full") );//填充模式
}
//hr = wmp->put_URL( CComBSTR("c://temp//videofile.wmv") );//多媒体文件地址
}
return TRUE;
}
LRESULT CMainDlg::OnBnClickedBtnBrowse(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{//选择多媒体文件
static LPCTSTR pszFilter = _T("Video Files (*.avi;*.mpg;*.wmv)/0*.avi;*.mpg;*.wmv/0/0");
CFileDialog fileOpen(TRUE, _T("avi"), NULL,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, pszFilter/*, m_hWnd*/);
if ( IDOK == fileOpen.DoModal() )
{
ActiveXSite* pSite;
pSite = CAxWindowlessHost<CMainDlg>::GetControlSite(IDC_WMP11);
SetDlgItemText(IDC_TXT_FILENAME, fileOpen.m_szFileName);
CComQIPtr<IWMPPlayer4> wmp4 = pSite->ActiveXControl();
wmp4->close();
wmp4->put_URL( CComBSTR( fileOpen.m_szFileName ) );
}
return 0;
}
使用Sliverlight作为子控件
主要代码如下:
LRESULT CMainDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
// center the dialog on the screen
CenterWindow();
// set icons
HICON hIcon = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME),
IMAGE_ICON, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR);
SetIcon(hIcon, TRUE);
HICON hIconSmall = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME),
IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
SetIcon(hIconSmall, FALSE);
// Initialize Silverlight Control (this is not windowless but cool anyway)
HRESULT hr;
ActiveXSite* pSite;
pSite = CAxWindowlessHost<CMainDlg>::GetControlSite(IDC_AGCONTROL1);//获取SliverLight子控件
if ( pSite != NULL )
{
// disable right-click!
pSite->SetAllowRClick(false);//禁止掉右键
// load from URL
//CComBSTR bstrUrl("file:///c://temp//SortTheFootbars.xap");
CComBSTR bstrUrl("http://www.andybeaulieu.com/silverlight/2.0/sortthefoobars/ClientBin/SortTheFoobars.xap");
pSite->SetUrl(bstrUrl);//设置多媒体源文件
CComQIPtr<IXcpControl2> slight = pSite->ActiveXControl();
hr = slight->put_Source(bstrUrl);
}
return TRUE;
}
{
// center the dialog on the screen
CenterWindow();
// set icons
HICON hIcon = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME),
IMAGE_ICON, ::GetSystemMetrics(SM_CXICON), ::GetSystemMetrics(SM_CYICON), LR_DEFAULTCOLOR);
SetIcon(hIcon, TRUE);
HICON hIconSmall = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDR_MAINFRAME),
IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), LR_DEFAULTCOLOR);
SetIcon(hIconSmall, FALSE);
// Initialize Silverlight Control (this is not windowless but cool anyway)
HRESULT hr;
ActiveXSite* pSite;
pSite = CAxWindowlessHost<CMainDlg>::GetControlSite(IDC_AGCONTROL1);//获取SliverLight子控件
if ( pSite != NULL )
{
// disable right-click!
pSite->SetAllowRClick(false);//禁止掉右键
// load from URL
//CComBSTR bstrUrl("file:///c://temp//SortTheFootbars.xap");
CComBSTR bstrUrl("http://www.andybeaulieu.com/silverlight/2.0/sortthefoobars/ClientBin/SortTheFoobars.xap");
pSite->SetUrl(bstrUrl);//设置多媒体源文件
CComQIPtr<IXcpControl2> slight = pSite->ActiveXControl();
hr = slight->put_Source(bstrUrl);
}
return TRUE;
}
- 【译】用于多媒体应用的无窗口ATL ActiveX控件容器
- 用于多媒体应用的无窗口ATL ActiveX控件容器1
- 在ATL无窗口ACTIVEX控件中响应timer消息
- 如何用VC写无窗口的ActiveX控件
- ATL 中的ActiveX 容器
- MFC ActiveX控件与ATL ActiveX控件的比较
- MFC ActiveX控件与ATL ActiveX控件的比较
- MFC ActiveX控件与ATL ActiveX控件的比较 .
- 解决 无法获取“”控件的窗口句柄。不支持无窗口的 ActiveX 控件
- VMware vSphere Client 解决 无法获取“”控件的窗口句柄。不支持无窗口的 ActiveX 控件
- 无法获取控件的窗口句柄和不支持无窗口的 ActiveX 控件
- 解决 无法获取“”控件的窗口句柄。不支持无窗口的 ActiveX 控件
- 基于GDI+的gif ActiveX控件(ATL)
- 使用ATL建立ActiveX控件的学习体会
- 用ATL写简单的ActiveX控件
- 用ATL写简单的ActiveX控件
- 编写 ATL ActiveX 控件
- ActiveX控件(ATL篇)
- 《Advanced Linux Programming》读书笔记(1)
- 基于Chrome的扩展开发(一)
- 由Tencent://Message协议想到的一个解决方案
- PuTom团队的CSDN博客开通了!!
- CodeFx:一站式微软开发技术解决方案
- 【译】用于多媒体应用的无窗口ATL ActiveX控件容器
- 解决打印代码的一个Bug
- ActiveX控件版本自动更新问题的解决方案
- GDI+学习笔记(一)
- 本周学习心得
- 《Windows驱动开发技术详解》读书笔记(二)
- C++ Exercises(十九)
- 《Windows驱动开发技术详解》读书笔记(一)
- C++ Exercises(十八)