亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? animator.cpp

?? window下的多線程編程參考書。值得一讀
?? CPP
字號:
//
// FILE: Animator.cpp
//
// Copyright (c) 1997 by Aaron Michael Cohen and Mike Woodring
//
/////////////////////////////////////////////////////////////////////////

#include "Animator.h"

// CAnimator class message map...
BEGIN_MESSAGE_MAP( CAnimator, CStatic)
    ON_WM_PAINT()
    ON_WM_DESTROY()
END_MESSAGE_MAP()

// CAnimator class constructor/destructor...
CAnimator::CAnimator() : 
    m_czFrame(0,0), 
    m_czBitmap(0,0), 
    m_nFrames(0), 
    m_bBackAndForth(FALSE),
    m_bTransparent(FALSE),
    m_nCurrentFrameIndex(0),
    m_dwFrameInterval(0),
    m_nFrameIncrement(1) {
    return;
}

afx_msg void CAnimator::OnPaint() {
    // just paint the current frame...
    CPaintDC dc(this);
    DrawCurrentFrame(&dc);
}

afx_msg void CAnimator::OnDestroy() {
    // make sure that the worker thread has exited
    // before our window is destroyed...
    Stop();

    // make sure that there is no bitmap
    // attached to the CBitmap object...
    // the animator just uses a passed in HBITMAP, 
    // it does not manage the resource's lifetime...
    m_cBitmap.Detach();

    // call the parent function...
    CStatic::OnDestroy();
}

void CAnimator::SetupAnimation( HBITMAP hBitmap, CSize czFrame, int nFrames, int nFramesPerSecond, BOOL bBackAndForth, BOOL bTransparent) {
    // make sure we have exclusive access to the object
    // while we modify its properties...
    CMclAutoLock autoLock(m_CritSec);

    // make sure that there is no bitmap
    // attached to the CBitmap object...
    m_cBitmap.Detach();

    // attach the passed in bitmap handle...
    m_cBitmap.Attach(hBitmap);

    // save the initial animation properties...
    m_czFrame = czFrame;
    m_nFrames = nFrames;
    m_dwFrameInterval = 1000 / nFramesPerSecond;
    m_bBackAndForth = bBackAndForth;

    // compute the overall size of the animation bitmap...
    BITMAP bm;
    m_cBitmap.GetObject(sizeof(BITMAP), &bm);
    m_czBitmap = CSize( bm.bmWidth, bm.bmHeight);

    // initialize mask for transparent animation if necessary,,,
    m_bTransparent = bTransparent;
    if (m_bTransparent)
        SetupBitmapsForTransparency();
    else
        CleanupBitmapsForTransparency();
}

void CAnimator::SetFrameRate( int nFramesPerSecond) {
    // make sure we have exclusive access to the object
    // while we modify its properties...
    CMclAutoLock autoLock(m_CritSec);

    // compute the frame interval in milliseconds...
    m_dwFrameInterval = 1000 / nFramesPerSecond;
}

void CAnimator::SetTransparency( BOOL bTransparent) {
    // make sure we have exclusive access to the object
    // while we modify its properties...
    CMclAutoLock autoLock(m_CritSec);

    if (bTransparent != m_bTransparent) {
        // change the transparency...
        if (bTransparent) {
            SetupBitmapsForTransparency();
        }
        else {
            CleanupBitmapsForTransparency();
        }

        // change the current mode...
        m_bTransparent = bTransparent;

        // redraw the control with the new transparency...
        RedrawWindow();
    }
}

void CAnimator::SetLoopStyle( BOOL bBackAndForth) {
    // make sure we have exclusive access to the object
    // while we modify its properties...
    CMclAutoLock autoLock(m_CritSec);

    // change the repeat pattern type...
    m_bBackAndForth = bBackAndForth;
}

void CAnimator::Start(void) {
    // create an animation thread if there is none...
    if (m_apAnimationThread.IsNull()) {
        m_apAnimationThread = new CMcl4MfcWorkerThread(this);
    }
}

void CAnimator::Stop(void) {
    // if there is an animation thread,
    // use the event to signal it to stop
    // and wait for the thread to exit before
    // resetting our auto-pointer to NULL...
    if (!m_apAnimationThread.IsNull()) {
        m_ceControl.Set();
        m_apAnimationThread->Wait(INFINITE);
        m_apAnimationThread = NULL;
    }
}

void CAnimator::SetFrame( int nFrameNumber) {
    // make sure we have exclusive access to the object
    // while we modify its properties...
    CMclAutoLock autoLock(m_CritSec);

    // set the new current frame...
    if ((nFrameNumber >= 0) && (nFrameNumber < m_nFrames))
        m_nCurrentFrameIndex = nFrameNumber;

    // redraw the control at the new frame...
    RedrawWindow();
}

void CAnimator::AdvanceFrame(void) {
    // make sure we have exclusive access to the object
    // while we modify its properties...
    CMclAutoLock autoLock(m_CritSec);

    if (m_bBackAndForth) {
        // oscillate back and forth, increment from frame zero to 
        // m_nFrames - 1, and then decrement back to frame zero
        // and store the current direction in m_nFrameIncrement...
        m_nCurrentFrameIndex = (m_nCurrentFrameIndex + m_nFrameIncrement);
        if (m_nCurrentFrameIndex >= m_nFrames) {
            m_nCurrentFrameIndex = m_nFrames - 1;
            m_nFrameIncrement = -1;
        }
        else if (m_nCurrentFrameIndex < 0) {
            m_nCurrentFrameIndex = 1;
            m_nFrameIncrement = 1;
        }     
    }
    else {
        // just cycle around the frames, when we go past the last
        // frame, start over at frame zero...
        m_nCurrentFrameIndex = (m_nCurrentFrameIndex + 1) % m_nFrames;
    }
}

void CAnimator::DrawCurrentFrame(CDC *pDC) {
    // all of the CDC calls such as SelectObject, BitBlt, and StretchBlt,
    // used in this function are simple wrappers around Win32 API
    // function and are safe to call from threads other than
    // the one which created the objects...

    // make sure we have exclusive access to the object
    // while we use its properties, we don't want some
    // other thread calling SetupAnimation() while we are
    // in the middle of drawing the current frame...
    CMclAutoLock autoLock(m_CritSec);

    // use the HBITMAP operator to determine if there is
    // an attached bitmap,
    // if there is no bitmap, we don't draw anything...
    if ((HBITMAP)(m_cBitmap) == NULL)
        return;

    // compute the offset into the bitmap, by counting m_nCurrentFrameIndex images
    // into the bitmap by rows and then columns...
    int bmx = m_czFrame.cx * (m_nCurrentFrameIndex % (m_czBitmap.cx / m_czFrame.cx));
    int bmy = m_czFrame.cy * ((m_nCurrentFrameIndex * m_czFrame.cx) / m_czBitmap.cx);

    // create a memory DC and select the animation bitmap...
    CDC bdc;
    bdc.CreateCompatibleDC(pDC);
    CBitmap *pcOldBitmap = bdc.SelectObject(&m_cBitmap);

    // get current client dimensions for our window...
    CRect cr;
    GetClientRect(cr);

    // use stretchblt to fill the control client area no matter
    // what the size of the animation frames...
    if (m_bTransparent) {
        // create an offscreen DC and select the offscreen bitmap into it...
        CDC odc;
        odc.CreateCompatibleDC(pDC);
        CBitmap *pcOldOffscreenBitmap = odc.SelectObject(&m_cOffscreenBitmap);

        // fill the offscreen bitmap with the background color...
        CBrush cbrush(::GetSysColor(COLOR_3DFACE));
        odc.FillRect( CRect( 0, 0,m_czFrame.cx, m_czFrame.cy), &cbrush);  

        // create a memory DC and select in the mask bitmap...
        CDC mdc;
        mdc.CreateCompatibleDC(pDC);
        CBitmap *pcOldMaskBitmap = mdc.SelectObject(&m_cMaskBitmap);

        COLORREF crOldBkColor = odc.SetBkColor(RGB(255,255,255));
        COLORREF crOldTextColor = odc.SetTextColor(RGB(0,0,0));
        odc.BitBlt( 0, 0, m_czFrame.cx, m_czFrame.cy, &mdc, bmx, bmy, SRCAND);
        odc.BitBlt( 0, 0, m_czFrame.cx, m_czFrame.cy, &bdc, bmx, bmy, SRCPAINT);
        odc.SetBkColor(crOldBkColor);
        odc.SetTextColor(crOldTextColor);

        // finally, blt the offscreen image into our client area...
        pDC->StretchBlt( 0, 0, cr.Width(), cr.Height(), &odc, 0, 0, m_czFrame.cx, m_czFrame.cy, SRCCOPY);

        // clean up...
        mdc.SelectObject(pcOldMaskBitmap);
        odc.SelectObject(pcOldOffscreenBitmap);
    }
    else {
        pDC->StretchBlt( 0, 0, cr.Width(), cr.Height(), &bdc, bmx, bmy, m_czFrame.cx, m_czFrame.cy, SRCCOPY);
    }

    // restore the orginal bitmap to the bitmap memory DC...
    bdc.SelectObject(pcOldBitmap);
}

void CAnimator::SetupBitmapsForTransparency(void) {
    // clean up any bitmaps used previously...
    CleanupBitmapsForTransparency();

    // create a bitmap object for the mask...
    // this type of mask only works if the non-image part of the 
    // bitmap (the "off" pixels) are black and the
    // image does not use black (very dark grey is okay)..
    m_cMaskBitmap.CreateBitmap( m_czBitmap.cx, m_czBitmap.cy, 1, 1, NULL);

    // select the bitmap into a DC...
    CDC bdc;
    bdc.CreateCompatibleDC(NULL);
    CBitmap *pOldBitmap = bdc.SelectObject(&m_cBitmap);

    // set up a DC for the mask...
    CDC mdc;
    mdc.CreateCompatibleDC(NULL);
    CBitmap *pOldMaskBitmap = mdc.SelectObject(&m_cMaskBitmap);

    // create the mask, "on" pixels are black, "off" pixels are white...
    bdc.SetBkColor(RGB(0,0,0));
    mdc.BitBlt( 0, 0, m_czBitmap.cx, m_czBitmap.cy, &bdc, 0, 0, SRCCOPY);

    // create an offscreen bitmap for use later on...
    m_cOffscreenBitmap.CreateCompatibleBitmap( &bdc, m_czBitmap.cx, m_czBitmap.cy);

    // clean up...
    bdc.SelectObject(pOldBitmap);
    mdc.SelectObject(pOldMaskBitmap);
}

void CAnimator::CleanupBitmapsForTransparency(void) {
    m_cMaskBitmap.DeleteObject();
    m_cOffscreenBitmap.DeleteObject();
}

unsigned CAnimator::ThreadHandlerProc(void) {
    // create a DC for our window...
    //
    // while the CClientDC is not an inline function
    // it is a simple wrapper around the Win32 
    // ::GetDC() API which simply accesses the m_hWnd
    // of the CAnimator object...
    //
    // notice that this is NOT the thread which created
    // the m_hWnd, but we can get a valid DC for it
    // anyway...
    //
    // we could have done it like this:
    //
    // CWnd *pWnd = CWnd::FromHandle(m_hWnd);
    // CClientDC dc(pWnd);
    //
    // which creates a temporary CWnd object but
    // otherwise winds up being the same thing as
    // what we have done here.
    CClientDC dc(this);

    // as long as the wait returns timeout, advance to the
    // next frame in the animation and draw it...
    while (TRUE) {
        DWORD dwStatus = m_ceControl.Wait(m_dwFrameInterval);
        if (CMclWaitTimeout(dwStatus)) {
            // advance m_nCurrentFrameIndex to the next frame...
            AdvanceFrame();

            // draw the next frame using this worker thread...
            DrawCurrentFrame(&dc);
        }
        else {
            return 0;
        }
    }
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91精品国产综合久久福利| 国产欧美日韩激情| 国产成人午夜电影网| 亚洲色图欧洲色图婷婷| 日韩一区二区三区四区五区六区| 久久精品国产一区二区三| 亚洲国产精品av| 9191精品国产综合久久久久久| 国产一区二区伦理| 一区二区三区四区亚洲| 亚洲成人手机在线| 久久久不卡影院| 在线一区二区三区做爰视频网站| 久久精品国产第一区二区三区| 亚洲欧洲av另类| 精品久久久影院| 在线观看成人小视频| 国产成人午夜精品影院观看视频| 婷婷亚洲久悠悠色悠在线播放 | 欧美一级高清片| 91蜜桃视频在线| 国产成人在线影院| 激情综合亚洲精品| 奇米色777欧美一区二区| 一区二区三区四区乱视频| 欧美激情艳妇裸体舞| 日韩女优视频免费观看| 欧美色男人天堂| 91成人网在线| 欧美视频日韩视频在线观看| 99久久99久久精品免费观看| 国产九色精品成人porny| 男男视频亚洲欧美| 日本午夜一区二区| 亚洲一区二区视频在线| 一区二区三区美女| 一区二区三区在线免费播放| 亚洲蜜臀av乱码久久精品| 日韩理论电影院| 尤物视频一区二区| 日韩美女啊v在线免费观看| 成人一二三区视频| 国产成人在线免费观看| 国产成人在线网站| 成人午夜电影小说| 99久久精品国产网站| 色狠狠色狠狠综合| 欧美视频一区在线| 56国语精品自产拍在线观看| 制服丝袜中文字幕亚洲| 精品免费日韩av| 国产日本欧美一区二区| 日韩一区日韩二区| 亚洲国产人成综合网站| 奇米影视一区二区三区小说| 久久99九九99精品| 成人黄色片在线观看| 欧美精品色综合| 精品国产乱码久久久久久免费| 亚洲天堂精品在线观看| 18欧美乱大交hd1984| 天堂一区二区在线免费观看| 色哟哟一区二区| 国产精品免费人成网站| 激情综合色播五月| 欧美一区二区三区在线视频| 国产日韩欧美在线一区| 久久99国产精品久久99 | 亚洲精品成人悠悠色影视| 一区二区免费在线播放| 黑人巨大精品欧美一区| 93久久精品日日躁夜夜躁欧美| 9191精品国产综合久久久久久| 精品久久久久久久久久久院品网 | 亚洲永久免费av| 精品一区二区在线观看| 99免费精品视频| 日韩欧美的一区| 亚洲乱码国产乱码精品精小说 | 美腿丝袜在线亚洲一区| 91网上在线视频| 国产日韩欧美在线一区| 国内精品免费**视频| 欧美日韩成人高清| 亚洲va天堂va国产va久| 亚洲色图丝袜美腿| 成人免费电影视频| 久久精品亚洲精品国产欧美kt∨| 日精品一区二区三区| 69堂成人精品免费视频| 亚洲黄一区二区三区| 色狠狠色狠狠综合| 亚洲精品老司机| 日本国产一区二区| 亚洲一区中文日韩| 欧美另类久久久品| 天堂久久一区二区三区| 91麻豆精品国产综合久久久久久| 亚洲影院理伦片| 欧美日韩黄色影视| 免费的成人av| 中文字幕中文字幕在线一区| 国产拍欧美日韩视频二区| 亚洲国产精品天堂| 日韩一级精品视频在线观看| 成人免费视频一区| 日产国产欧美视频一区精品| 国产精品国产三级国产普通话三级 | 在线观看日韩av先锋影音电影院| 午夜精品成人在线| 狂野欧美性猛交blacked| 久久毛片高清国产| 91麻豆国产精品久久| 日本特黄久久久高潮| 久久久久久综合| 在线观看不卡一区| 麻豆91免费观看| 欧美精品日韩综合在线| 国产麻豆成人精品| 亚洲一二三四区不卡| 欧美大尺度电影在线| 99精品一区二区三区| 日韩成人dvd| 亚洲欧洲www| 欧美电视剧免费观看| 91久久精品一区二区三| 久久草av在线| 婷婷久久综合九色国产成人| 国产日本一区二区| 欧美日韩一二三| 国产酒店精品激情| 午夜精品视频在线观看| 亚洲日本va午夜在线影院| 日韩你懂的在线观看| 欧美午夜片在线观看| 不卡视频在线观看| 狠狠色丁香九九婷婷综合五月| 粉嫩欧美一区二区三区高清影视| 石原莉奈一区二区三区在线观看| 中文字幕乱码日本亚洲一区二区| 日韩欧美国产系列| 欧美日韩在线观看一区二区| 不卡电影免费在线播放一区| 韩国三级电影一区二区| 日韩**一区毛片| 午夜在线电影亚洲一区| 亚洲高清视频的网址| 亚洲一区二区3| 亚洲午夜精品网| 亚洲电影第三页| 亚洲国产精品自拍| 五月天一区二区| 日韩精品福利网| 免费在线观看视频一区| 视频一区免费在线观看| 日韩二区在线观看| 日韩高清一级片| 蜜桃一区二区三区在线| 九九在线精品视频| 国产麻豆9l精品三级站| 成人av在线播放网址| 久久久影视传媒| 国产女主播视频一区二区| 国产精品美日韩| 亚洲成av人片在线观看| 久草在线在线精品观看| www.欧美日韩| 欧美日本免费一区二区三区| 久久尤物电影视频在线观看| 中文字幕一区二区三区蜜月| 亚洲成av人片www| 国产aⅴ综合色| 99re视频精品| 日本韩国欧美国产| 欧美一级专区免费大片| 日韩欧美一区中文| 国产亚洲精品7777| 亚洲精品v日韩精品| 三级久久三级久久久| 国产一区二区不卡在线| 不卡区在线中文字幕| 8x8x8国产精品| 日本一区二区免费在线| 午夜精品久久久| 国产不卡一区视频| 欧洲精品在线观看| 精品免费日韩av| 伊人性伊人情综合网| 精品一区二区免费视频| 91在线观看成人| 日韩欧美在线影院| 欧美激情综合五月色丁香小说| 国产精品短视频| 久久er精品视频| 91国偷自产一区二区开放时间| 日韩欧美国产三级| 一区二区三区在线视频观看| 久久99精品久久久久婷婷| 在线国产电影不卡| 五月激情综合婷婷|