透明COM容器控件原理

以上是一個背景透明的COM容器控件,實現拖拽單個文件,進行循環播放歌曲的效果

FLASH透明窗體就是一種透明容器控件,網絡上找不到相關的示例和代碼,我這裏是通過獲取主窗口DC,然後傳遞給控件,在控件的OnDraw裏,實現透明疊加的結果,所以沒啥技術含量,但是可以達到實際效果就行了。

主程序關鍵代碼

	IUnknown* pUnKnwn=0; 

	pUnKnwn = m_AxWindow.GetControlUnknown();
	hr		= pUnKnwn->QueryInterface(IID_Ixplay,(void **)&m_pIxplay);

	if (!m_pIxplay)
	{ 
		::MessageBox(NULL,_T("m_pIxplay==NULL @CMainDlg::OnInitDialog"),_T("Faild"),MB_OK);
		return true;
	}

	if (!m_pMemDC)
	{		
		CPaintDC dc(this); 
		m_pMemDC = new CDC();
		m_pMemDC->CreateCompatibleDC(&dc);
		m_memBitmap.DeleteObject();
		m_memBitmap.CreateCompatibleBitmap(&dc,m_AxRct.Width(), m_AxRct.Height() );//rt.Width(), rt.Height()
		m_OldBitmap = m_pMemDC->SelectObject(&m_memBitmap);

		VARIANT varHDC;
		varHDC.vt = VT_I4 ;///指明數據類型
		varHDC.lVal = (LONG)m_pMemDC->m_hDC;
		m_pIxplay->SetAxMemDC(varHDC);
	}

	m_pIxplay->LoadFile(_T("J:/mp3/勵志歌曲/春天裏.mp3"));	
	m_pIxplay->ChangePlayState(0);

控件中OnDraw關鍵代碼

	if (m_plyState == Cxplay::PLAYING)
	{
		::BitBlt(hdc,0,0, nWidth,  nHeight, m_hAxDC,  0, 0, SRCCOPY);
		CUtil::CreateMaskDC(hdc, 0, 0, nImgWidth, nImgHeight, m_hPauseBg,  nImgWidth, nImgHeight);
	}else if (m_plyState == Cxplay::PAUSE || m_plyState == Cxplay::STOP)
	{
		::BitBlt(hdc,0,0, nWidth,  nHeight, m_hAxDC,  0, 0, SRCCOPY);
		CUtil::CreateMaskDC(hdc, 0, 0, nImgWidth, nImgHeight, m_hPlayBg,  nImgWidth, nImgHeight);
	}


DEMO下載:xPlayer.rar


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章