📄 cavictrl.cls
字号:
lDstWidth = lSrcStartWidth
lDstX = x
lSrcX = lSrcStartX
Do While lDstX < (x + Width)
If (lDstX + lDstWidth) > (x + Width) Then
lDstWidth = x + Width - lDstX
If (lDstWidth = 0) Then
lDstWidth = 4
End If
End If
'If (lDstWidth > Width) Then lDstWidth = Width
'If (lDstHeight > Height) Then lDstHeight = Height
BitBlt hdc, lDstX, lDstY, lDstWidth, lDstHeight, lSrcDC, lSrcX, lSrcY, vbSrcCopy
lDstX = lDstX + lDstWidth
lSrcX = 0
lDstWidth = lBitmapW
Loop
lDstY = lDstY + lDstHeight
lSrcY = 0
lDstHeight = lBitmapH
Loop
End Sub
' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' ///
' // CAVICtrl protected members
Private Sub DrawCurrentFrame(ByVal lHDC As Long)
Dim lpBI As Long
Dim tBi As BITMAPINFOHEADER
Dim rcClip As RECT
Dim hdcComp As Long
Dim hBmp As Long
Dim hBmpOld As Long
Dim lR As Long
GetClientRect m_hWnd, rcClip
If m_bCentre Then
m_nAVIOffsetX = ((rcClip.Right - rcClip.Left) - Width) \ 2
m_nAVIOffsetY = ((rcClip.Bottom - rcClip.Top) - Height) \ 2
Else
m_nAVIOffsetX = 0
m_nAVIOffsetY = 0
End If
' lpBi = (LPBITMAPINFOHEADER)AVIStreamGetFrame(m_pGF, (LONG)m_nCurrentFrame);
' _ASSERTE(lpBi);
lpBI = AVIStreamGetFrame(ByVal m_pGF, m_nCurrentFrame)
Debug.Assert (lpBI <> 0)
If (lpBI) Then
If m_bTransparent Then
' // create compatible dc & bitmap
' CDC dcComp;
' CBitmap bmp, *bmpOld;
'
' dcComp.CreateCompatibleDC(pDC);
' bmp.CreateCompatibleBitmap(pDC, rcClip.Width(), rcClip.Height());
' bmpOld = dcComp.SelectObject(&bmp);
hdcComp = CreateCompatibleDC(lHDC)
hBmp = CreateCompatibleBitmap(lHDC, rcClip.Right - rcClip.Left + 1, rcClip.Bottom - rcClip.Top + 1)
hBmpOld = SelectObject(hdcComp, hBmp)
If m_bInitBkg Then
LSet m_tR = rcClip
m_cDCBack.Width = m_tR.Right - m_tR.Left
m_cDCBack.Height = m_tR.Bottom - m_tR.Top
pDrawBackground
m_bInitBkg = False
End If
'
' // again, this is only for dumb Win95/98 :-(
' // initialize background of compatible dc
' dcComp.BitBlt(0, 0, rcClip.Width(), rcClip.Height(), &m_dcBkg, 0, 0, SRCCOPY);
BitBlt hdcComp, 0, 0, rcClip.Right - rcClip.Left + 1, rcClip.Bottom - rcClip.Top - 1, m_cDCBack.hdc, 0, 0, vbSrcCopy
'
' // draw into comp dc
' VERIFY(DrawDibDraw(m_hDrawDib, dcComp.GetSafeHdc(), rcClip.left+m_nAVIOffsetX, rcClip.top+m_nAVIOffsetY,
' m_nRealWidth, m_nRealHeight, lpBi, NULL,
' 0, 0, -1, -1, 0));
lR = DrawDibDraw(m_hDrawDib, hdcComp, rcClip.Left + m_nAVIOffsetX, rcClip.Top + m_nAVIOffsetY, _
m_nRealWidth, m_nRealHeight, ByVal lpBI, ByVal 0&, _
0, 0, -1, -1, 0)
'
' // draw transparently to screen
' DrawTransparent(rcClip.left, rcClip.top,
' rcClip.Width(), rcClip.Height(), &dcComp, pDC);
DrawTransparent rcClip.Left, rcClip.Top, rcClip.Right - rcClip.Left + 1, rcClip.Bottom - rcClip.Top + 1, hdcComp, lHDC
SelectObject hdcComp, hBmpOld
DeleteObject hBmp
DeleteDC hdcComp
'
' dcComp.SelectObject(bmpOld);
' }
Else
'
lR = DrawDibDraw(m_hDrawDib, lHDC, rcClip.Left + m_nAVIOffsetX, rcClip.Top + m_nAVIOffsetY, _
m_nRealWidth, m_nRealHeight, ByVal lpBI, ByVal 0&, _
0, 0, -1, -1, 0)
End If
End If
'}
End Sub
Private Sub DrawTransparent( _
ByVal x As Long, _
ByVal y As Long, _
ByVal nWidth As Long, _
ByVal nHeight As Long, _
ByVal hDCSrc As Long, _
ByVal hDCDst As Long _
)
'{
' CDC maskDC, memDC;
' CBitmap maskBmp, *pOldMaskBmp, memBmp, *pOldMemBmp;
Dim hDCMask As Long
Dim hBmpMask As Long
Dim hBmpMaskOld As Long
Dim hDCMem As Long
Dim hBmpMem As Long
Dim hBmpMemOld As Long
'
'
' maskDC.CreateCompatibleDC(pSrcDC);
' maskBmp.CreateBitmap(nWidth, nHeight, 1, 1, NULL);
' pOldMaskBmp = maskDC.SelectObject(&maskBmp);
hDCMask = CreateCompatibleDC(0)
hBmpMask = CreateCompatibleBitmap(hDCMask, nWidth, nHeight)
hBmpMaskOld = SelectObject(hDCMask, hBmpMask)
' memDC.CreateCompatibleDC(pDstDC);
' memBmp.CreateCompatibleBitmap(pDstDC, nWidth, nHeight);
' pOldMemBmp = memDC.SelectObject(&memBmp);
hDCMem = CreateCompatibleDC(hDCDst)
hBmpMem = CreateCompatibleBitmap(hDCDst, nWidth, nHeight)
hBmpMemOld = SelectObject(hDCMem, hBmpMem)
'
' memDC.BitBlt(0, 0, nWidth, nHeight, &m_dcBkg, 0, 0, SRCCOPY);
BitBlt hDCMem, 0, 0, nWidth, nHeight, m_cDCBack.hdc, 0, 0, vbSrcCopy
'
' pSrcDC->SetBkColor(m_clrTransp);
' maskDC.BitBlt(m_nAVIOffsetX, m_nAVIOffsetY, m_nRealWidth, m_nRealHeight, pSrcDC, m_nAVIOffsetX, m_nAVIOffsetY, SRCCOPY);
SetBkColor hDCSrc, TranslateColor(m_oTransColor)
BitBlt hDCMask, m_nAVIOffsetX, m_nAVIOffsetY, m_nRealWidth, m_nRealHeight, hDCSrc, m_nAVIOffsetX, m_nAVIOffsetY, vbSrcCopy
'
' pSrcDC->SetBkColor(BLACK);
' pSrcDC->SetTextColor(WHITE);
' pSrcDC->BitBlt(m_nAVIOffsetX, m_nAVIOffsetY, nWidth, nHeight, &maskDC, m_nAVIOffsetX, m_nAVIOffsetY, SRCAND);
SetBkColor hDCSrc, &H0&
SetTextColor hDCSrc, &HFFFFFF
BitBlt hDCSrc, m_nAVIOffsetX, m_nAVIOffsetY, nWidth, nHeight, hDCMask, m_nAVIOffsetX, m_nAVIOffsetY, vbSrcAnd
'
' memDC.SetBkColor(WHITE);
' memDC.SetTextColor(BLACK);
' memDC.BitBlt(m_nAVIOffsetX, m_nAVIOffsetY, m_nRealWidth, m_nRealHeight, &maskDC, m_nAVIOffsetX, m_nAVIOffsetY, SRCAND);
' memDC.BitBlt(0, 0, nWidth, nHeight, pSrcDC, 0, 0, SRCPAINT);
SetBkColor hDCMem, &HFFFFFF
SetTextColor hDCMem, &H0&
BitBlt hDCMem, m_nAVIOffsetX, m_nAVIOffsetY, m_nRealWidth, m_nRealHeight, hDCMask, m_nAVIOffsetX, m_nAVIOffsetY, vbSrcAnd
BitBlt hDCMem, 0, 0, nWidth, nHeight, hDCSrc, 0, 0, vbSrcPaint
'
' pDstDC->BitBlt(x, y, nWidth, nHeight, &memDC, 0, 0, SRCCOPY);
BitBlt hDCDst, x, y, nWidth, nHeight, hDCMem, 0, 0, vbSrcCopy
'
' memDC.SelectObject(pOldMemBmp);
' maskDC.SelectObject(pOldMaskBmp);
SelectObject hDCMem, hBmpMemOld
DeleteObject hBmpMem
DeleteDC hDCMem
SelectObject hDCMask, hBmpMaskOld
DeleteObject hBmpMask
DeleteDC hDCMask
'}
End Sub
Private Sub InitBackground()
If (m_pAS = 0) Or ((m_dwFlags And AVC_MAPWINDOWCOLOR) = AVC_MAPWINDOWCOLOR) Then
Exit Sub
End If
'
' CWnd* pParentWnd;
' CRect rcAVIWnd, rcParent;
'
' ' // init
' pParentWnd = GetParent();
' _ASSERTE(pParentWnd);
' if (!pParentWnd)
' {
' return;
' }
'
' ' // calculate position of control in parent
' GetWindowRect(&rcAVIWnd);
'
' ' // border moves window later, so we move it here too
' if (GetExStyle() & (WS_EX_CLIENTEDGE|WS_EX_DLGMODALFRAME))
' {
' rcAVIWnd.OffsetRect(GetSystemMetrics(SM_CXEDGE),GetSystemMetrics(SM_CYEDGE));
' }
' else if(GetStyle() & WS_BORDER)
' {
' rcAVIWnd.OffsetRect(GetSystemMetrics(SM_CXBORDER), GetSystemMetrics(SM_CYBORDER));
' }
'
' rcParent = rcAVIWnd;
' pParentWnd->ScreenToClient(&rcParent);
' GetClientRect(&rcAVIWnd); ' // recycle this rect...
'
' ' // get parents dc
' CClientDC dcParent(pParentWnd);
'
' ' // cleanup old dc & bmp if exist
' if (m_pbmpBkgOld)
' {
' m_dcBkg.SelectObject(m_pbmpBkgOld);
' m_dcBkg.DeleteDC();
' m_bmpBkg.DeleteObject();
' }
'
' ' // get parent image from behind control
' m_dcBkg.CreateCompatibleDC(&dcParent);
' m_bmpBkg.CreateCompatibleBitmap(&dcParent, rcAVIWnd.Width(), rcAVIWnd.Height());
' m_pbmpBkgOld = m_dcBkg.SelectObject(&m_bmpBkg);
' _ASSERTE(m_pbmpBkgOld != NULL);
'
' ' //ShowWindow(SW_HIDE);
' m_dcBkg.BitBlt(rcAVIWnd.left, rcAVIWnd.top, rcAVIWnd.Width(), rcAVIWnd.Height(),
' &dcParent, rcParent.left, rcParent.top, SRCCOPY);
' ' //ShowWindow(SW_RESTORE);
'}
'
End Sub
Private Function GetFirstPixelColor() As Long
' _ASSERTE(m_pAS);
' _ASSERTE(m_pGF);
'
' LPBITMAPINFO lpbi;
'
' ' // fetch first frame
' lpbi = (LPBITMAPINFO)AVIStreamGetFrame(m_pGF, 0);
' _ASSERTE(lpbi);
'
' ' // currently works only with 8bit-BMPs
' if (!lpbi || lpbi->bmiHeader.biBitCount != 8)
' {
' return LTGREEN;
' }
'
' ' // get first pixel and use as index in the color table
' LPBYTE lpbyIndex = (LPBYTE)((DWORD)lpbi + lpbi->bmiHeader.biSize + (lpbi->bmiHeader.biClrUsed*sizeof(RGBQUAD)));
' RGBQUAD* pRGBFirst = (RGBQUAD*)(&lpbi->bmiColors[*lpbyIndex]);
'
' return RGB(pRGBFirst->rgbRed, pRGBFirst->rgbGreen, pRGBFirst->rgbBlue);
End Function
Private Property Get GetTempAVIFileName() As String
'{
' CString sTempDir, sTempFile, sRet;
'
' VERIFY(GetTempPath(_MAX_PATH, sTempDir.GetBuffer(_MAX_PATH+1)));
' sTempDir.ReleaseBuffer();
' _ASSERTE(!sTempDir.IsEmpty());
'
' ' // make sure to create unique filename
' Do
' {
' sTempFile.Format("AVC%X.AVI", GetTickCount());
' Sleep(100);
' sRet = sTempDir + sTempFile;
' }
' while (_taccess(sRet, 0) == 0);
'
' return sRet;
'}
'
End Property
' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' //' ///
' // CAVICtrl private helper functions
Private Sub CtrlInit()
m_pAS = 0
m_pGF = 0
'm_pbmpBkgOld = 0
m_nCurrentFrame = 0
m_nAVIOffsetX = 0
m_nAVIOffsetY = 0
m_bPlaying = False
m_bInitBkg = True
Set m_cDCBack = New pcMemDC
End Sub
Private Sub CtrlDestroy()
Dim bS As Boolean
' // still running?
If (m_bPlaying) Then
AVIStop
End If
' // close frame interface
If (m_pGF) Then
bS = (AVIStreamGetFrameClose(ByVal m_pGF) = 0)
Debug.Assert bS
m_pGF = 0
End If
' // release avi stream
If Not (m_pAS = 0) Then
AVIStreamRelease ByVal m_pAS
m_pAS = 0
End If
' // clear up background if exists
Set m_cDCBack = Nothing
Set m_cDCPicture = Nothing
' // delete temp file if exist
'if (!m_csTempFile.IsEmpty())
'{
' VERIFY(DeleteFile(m_csTempFile));
' m_csTempFile.Empty();
'}
'}
End Sub
Private Property Let ISubClass_MsgResponse(ByVal RHS As EMsgResponse)
'
End Property
Private Property Get ISubClass_MsgResponse() As EMsgResponse
Select Case CurrentMessage
Case WM_ERASEBKGND
ISubClass_MsgResponse = emrConsume
Case Else
ISubClass_MsgResponse = emrPreprocess
End Select
End Property
Private Function ISubClass_WindowProc(ByVal hWnd As Long, ByVal iMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Select Case iMsg
Case WM_PAINT
OnPaint
'Case WM_ERASEBKGND
'ISubClass_WindowProc = OnEraseBkgnd()
Case WM_WINDOWPOSCHANGING
Dim tWP As WINDOWPOS
CopyMemory tWP, ByVal lParam, Len(tWP)
OnWindowPosChanging tWP
Case WM_WININICHANGE
OnSysColorChange
Case WM_DESTROY
OnDestroy
End Select
End Function
Private Function FAILED(ByVal hr As Long) As Boolean
FAILED = Not (SUCCEEDED(hr))
End Function
Private Function SUCCEEDED(ByVal hr As Long) As Boolean
SUCCEEDED = ((hr And &H80000000) = 0)
End Function
Private Function Max(ByVal lArg1 As Long, ByVal lArg2 As Long) As Long
If lArg1 > lArg2 Then
Max = lArg1
Else
Max = lArg2
End If
End Function
Private Function TranslateColor(ByVal oClr As OLE_COLOR, _
Optional hPal As Long = 0) As Long
' Convert Automation color to Windows color
If OleTranslateColor(oClr, hPal, TranslateColor) Then
TranslateColor = -1 'CLR_INVALID
End If
End Function
Private Sub m_cTimer_ThatTime()
'
'{
' CAVICtrl* pThis = (CAVICtrl*)CWnd::FromHandle(hWnd);
' _ASSERTE(pThis);
' if (pThis == NULL)
' {
' return;
' }
'
' if (++pThis->m_nCurrentFrame >= (UINT)pThis->m_lFrames)
' {
' pThis->m_nCurrentFrame = 0;
'
' if (pThis->m_bOnce)
' {
' pThis->Stop(TRUE);
' return;
' }
' }
'
' pThis->Invalidate();
If IsLoaded Then
' Draw next frmae:
m_nCurrentFrame = m_nCurrentFrame + 1
If m_nCurrentFrame >= m_lFrames Then
If m_bOnce Then
AVIStop
Exit Sub
End If
m_nCurrentFrame = 0
End If
'Invalidate
Test m_nCurrentFrame
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -