• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            l

            成都手游碼農(nóng)一枚
            隨筆 - 32, 文章 - 0, 評(píng)論 - 117, 引用 - 0
            數(shù)據(jù)加載中……

            windows動(dòng)畫窗體。

            同往常一樣,先放一章效果圖,這鴨子是會(huì)飛的哦。



            效果類似常見的QQ寵物、360精靈之類的。

            不說廢話了,還是說重點(diǎn)。

            ==================================================
               要實(shí)現(xiàn)這種效果,我的第一想法便是通過SetWindowRGN設(shè)置不規(guī)則窗體,然后更新。
            顯然,這樣是最容易想到的,但是也不由的有點(diǎn)擔(dān)心效率,最終我也通過這種方式,實(shí)現(xiàn)了一個(gè),
            正如擔(dān)心的一樣,每秒6幀的速度偶爾會(huì)出現(xiàn)閃爍(當(dāng)然我的本本可能不是很給力- -。)。
               這種方式就是通過載入的位圖,獲取每個(gè)像素點(diǎn),并生成相應(yīng)的HRGN,每幀動(dòng)畫一個(gè)。
            然后通過計(jì)時(shí)器切換,由于效果不是很好,在此就不貼代碼了。

               既然不能通過SetWindowRGN,那還能怎么做呢?其實(shí)windows自身已經(jīng)給了我們一個(gè)
            處理這種位圖窗口的API,而且還可以實(shí)現(xiàn)透明,一說到透明很多人都應(yīng)該知道是那個(gè)API了。

            Syntax

            BOOL SetLayeredWindowAttributes(          HWND hwnd,
                COLORREF crKey,
                BYTE bAlpha,
                DWORD dwFlags
            );
            Parameters

            hwnd
            [
            in] Handle to the layered window. A layered window is created by specifying WS_EX_LAYERED when creating the window with the CreateWindowEx function or by setting WS_EX_LAYERED via SetWindowLong after the window has been created.
            crKey
            [
            in] COLORREF structure that specifies the transparency color key to be used when composing the layered window. All pixels painted by the window in this color will be transparent. To generate a COLORREF, use the RGB macro.
            bAlpha
            [
            in] Alpha value used to describe the opacity of the layered window. Similar to the SourceConstantAlpha member of the BLENDFUNCTION structure. When bAlpha is 0, the window is completely transparent. When bAlpha is 255, the window is opaque.
            dwFlags
            [
            in] Specifies an action to take. This parameter can be one or more of the following values.
            LWA_COLORKEY
            Use crKey 
            as the transparency color.
            LWA_ALPHA
            Use bAlpha to determine the opacity of the layered window.
            Return Value

            If the function succeeds, the 
            return value is nonzero. 
            If the function fails, the 
            return value is zero. To get extended error information, call GetLastError.


            其實(shí)這個(gè)函數(shù)在以前也經(jīng)常用到,但主要是用它來實(shí)現(xiàn)透明,根本沒想到它還可以實(shí)現(xiàn)不規(guī)則窗體。
            看了MSDN你應(yīng)該知道了吧,其實(shí)通過設(shè)置第二個(gè)顏色屬性便可過濾掉窗體中指定的某種顏色,達(dá)到
            不規(guī)則窗體的效果。

            設(shè)置透明色的代碼如下:再此將白色設(shè)置為透明。

            HINSTANCE hInstance=(HINSTANCE)LoadLibrary("user32.dll");
                    
            if (hInstance)
                    
            {
                        typedef BOOL(WINAPI 
            *pFun)(HWND,COLORREF,BYTE,DWORD);     
                        pFun  fun  
            =  NULL;       
                        fun
            =(pFun)GetProcAddress(hInstance, "SetLayeredWindowAttributes");   
                        SetWindowLong(GWL_EXSTYLE, GetWindowLong(GWL_EXSTYLE) 
            | 0x80000);
                        
            if (fun)
                        
            {
                            fun(hWnd, RGB(
            255255255), 00x1);
                        }

                        FreeLibrary(hInstance);
                    }

            知道如何處理不規(guī)則窗體后剩下的就簡(jiǎn)單了,在此我用的一半游戲中的(4*4)行走圖做的。
            只需要在繪制的時(shí)候通過改變繪制區(qū)域坐標(biāo)來控制顯示的位置達(dá)到動(dòng)畫的效果。
            其中m_nX,m_nY分別是橫向幀數(shù) 和 豎向的幀數(shù) 在此為 4 * 4

            void OnPaint(CDCHandle /*dc*/)
                
            {
                    CPaintDC dc(
            *this);
                    CDC bmpDC;
                    CBitmapHandle bmpOld;
                    CRect rtClient;

                    GetClientRect(
            &rtClient);
                    
                    bmpDC.CreateCompatibleDC(dc);
                    bmpOld 
            = bmpDC.SelectBitmap(m_bmpBox);

                    
            int nSubX = m_nWidth / m_nX;
                    
            int nSubY = m_nHeight / m_nY;

                    dc.BitBlt(
            00, nSubX, nSubY, bmpDC, m_nCurX * nSubX, 
                        m_nCurY 
            * nSubY, SRCCOPY);

                    bmpDC.SelectBitmap(bmpOld);
                }

            剩下就是一些輔助的功能了:m_nCurX m_nCurY 分別只是當(dāng)前橫向第幾幀 和 縱向的第幾幀

             /**
                 * 實(shí)現(xiàn)移動(dòng)窗口
                 
            */

                UINT OnNcHitTest(CPoint point)
                
            {
                    
            return HTCAPTION;
                }


                
            /**
                 * 更新動(dòng)畫
                 
            */

                
            void OnTimer(UINT_PTR nIDEvent)
                
            {
                    
            if (nIDEvent == ANIMA_TIMER)
                    
            {
                        m_nCurX 
            = (++m_nCurX) % m_nX;
                        RedrawWindow();
                    }

                }


                
            /**
                 * 改變方向
                 
            */

                
            void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
                
            {
                    
            switch (nChar)
                    
            {
                    
            case VK_LEFT: m_nCurY = 1break;
                    
            case VK_RIGHT: m_nCurY = 2break;
                    
            case VK_UP: m_nCurY = 3break;
                    
            case VK_DOWN: m_nCurY = 0break;
                    
            case VK_ESCAPE:OnClose();break;
                    }

                }


            好了,結(jié)束,雖然沒啥技術(shù)含量,但也可以打發(fā)下無(wú)聊的時(shí)間。
            以后有好玩的東西我也會(huì)更新在此。



            posted on 2011-10-16 00:22 l1989 閱讀(3109) 評(píng)論(6)  編輯 收藏 引用 所屬分類: windows

            評(píng)論

            # re: windows動(dòng)畫窗體。  回復(fù)  更多評(píng)論   

            收藏。不過想要做出更復(fù)雜的窗口控制還是比較麻煩的。
            2011-10-16 09:53 | 畢達(dá)哥拉斯半圓

            # re: windows動(dòng)畫窗體。  回復(fù)  更多評(píng)論   

            不錯(cuò),感謝,收藏,原來qq寵物是這樣弄的啊,之前以為很神奇

            # re: windows動(dòng)畫窗體。  回復(fù)  更多評(píng)論   

            @glueless human hair lace front wigs
            QQ寵物和QQ秀,魔法表情全是Flash的
            2011-10-16 17:25 | CzBiX

            # re: windows動(dòng)畫窗體。  回復(fù)  更多評(píng)論   

            @CzBiX
            這還真沒研究過~
            其實(shí)除了窗體裁剪 動(dòng)畫的實(shí)現(xiàn)很多方法,當(dāng)然用flash也是一種。
            2011-10-16 17:31 | azl

            # re: windows動(dòng)畫窗體。  回復(fù)  更多評(píng)論   

            @glueless human hair lace front wigs
            QQ寵物室flash,如果是一幀一個(gè)圖片按這種方法那要多少bmp啊
            2011-10-17 09:49 | Skill

            # re: windows動(dòng)畫窗體。  回復(fù)  更多評(píng)論   

            不錯(cuò) 收藏了 以后關(guān)注你
            2011-10-17 13:06 | 無(wú)賴熊貓
            国产国产成人久久精品| 情人伊人久久综合亚洲| 久久精品国产亚洲av水果派| 久久久噜噜噜久久| 欧美777精品久久久久网| 久久久久香蕉视频| 国产精自产拍久久久久久蜜| 亚洲国产精品嫩草影院久久| 国産精品久久久久久久| 精品久久久久久综合日本| 人妻无码中文久久久久专区| 中文精品久久久久人妻不卡| 精品久久久无码21p发布| 久久精品中文无码资源站| 久久久国产精品福利免费| 久久精品免费一区二区| 久久久WWW免费人成精品| 国产成人综合久久综合| 久久99精品国产| 18岁日韩内射颜射午夜久久成人| 国产—久久香蕉国产线看观看| 亚洲国产精品无码成人片久久| 免费无码国产欧美久久18| AV无码久久久久不卡蜜桃| 日本国产精品久久| 亚洲午夜久久久久久噜噜噜| 久久免费香蕉视频| 精品久久久久久无码中文野结衣| 国产欧美久久久精品| 成人久久综合网| 国产精品99久久99久久久| 久久93精品国产91久久综合| 久久精品男人影院| 国产成人久久精品区一区二区| 久久不见久久见免费视频7| 久久久久久久久无码精品亚洲日韩| 少妇人妻综合久久中文字幕| 伊人久久大香线蕉综合网站| 一本大道久久东京热无码AV| 亚洲一级Av无码毛片久久精品| 亚洲精品午夜国产va久久|