• <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>
            隨筆-60  評(píng)論-111  文章-0  trackbacks-0
            效果:

            只實(shí)現(xiàn)了對(duì)BUTTON的換膚 不過其他的控件基本原理是一樣的吧~!
            代碼有點(diǎn)亂 并且有些部分的設(shè)計(jì)還不是很合理

            帖出來就是希望各位大俠們批評(píng)指教

            Skin.h
            #pragma once
            #include 
            <map>

            void InstallSkin(HINSTANCE hInst);

            #if defined(_PRIVATE_DECLARE_)
            class CSkinButton
            {
            private:
                
            static std::multimap<HWND,CSkinButton*> s_HWND2Class;
                
            static LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
                CSkinButton();
                
            ~CSkinButton();
                
            void Draw();

                WNDPROC m_OldProc;
                DWORD m_Style;
                DWORD m_Check;
                
            bool m_isHighLight;
                
            bool m_isDefault;
                
            bool m_isPressed;
                
            bool m_isFocus;
                
            bool m_isPushButton;
                HWND m_hWnd;
            public:
                
            static void Install(HWND hWnd);
            }
            ;
            #endif
            Skin.cpp
            #define _PRIVATE_DECLARE_
            #include 
            "skin.h"

            #include 
            <WindowsX.h>

            #include 
            "Resource.h"

            HHOOK g_hSKinHook 
            = 0;
            HINSTANCE g_hInst 
            = 0;

            std::multimap
            <HWND,CSkinButton*> CSkinButton::s_HWND2Class;

            CSkinButton::CSkinButton() 
            : m_isHighLight(
            false)
            , m_isDefault(
            false)
            , m_isPressed(
            false)
            , m_isFocus(
            false)
            , m_isPushButton(
            true)
            {
            }


            CSkinButton::
            ~CSkinButton()
            {
                SetWindowLongPtr(m_hWnd,GWLP_WNDPROC,(LONG_PTR)m_OldProc);
                s_HWND2Class.erase(m_hWnd);
            }


            void CSkinButton::Install(HWND hWnd)
            {
                
            if(s_HWND2Class.find(hWnd)==s_HWND2Class.end())
                
            {
                    CSkinButton
            *inst=new CSkinButton;
                    s_HWND2Class.insert(std::pair
            <HWND,CSkinButton*>(hWnd,inst));
                    inst
            ->m_hWnd=hWnd;
                    inst
            ->m_OldProc=(WNDPROC)SetWindowLongPtr(hWnd,GWLP_WNDPROC,(LONG_PTR)WndProc);
                }

            }


            LRESULT CSkinButton::WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
            {
                LONG lReturn;
                std::multimap
            <HWND,CSkinButton*>::iterator pair=s_HWND2Class.find(hWnd);
                ASSERT(pair
            !=s_HWND2Class.end());
                CSkinButton
            *self=pair->second;
                
            switch (uMsg)
                
            {
                
            case BM_SETSTYLE:    // 按鈕風(fēng)格改變
                    self->m_isDefault=((wParam&BS_DEFPUSHBUTTON)!=0);
                    self
            ->m_isPushButton=((wParam&BS_PUSHBUTTON)!=0);

                    self
            ->m_Style=wParam;
                    self
            ->Draw();
                    
            break;

                
            case BM_SETSTATE:    // 設(shè)置按鈕狀態(tài)
                    lReturn = (LONG) CallWindowProc(self->m_OldProc, hWnd, uMsg, wParam, lParam);
                    self
            ->m_isPressed=(wParam!=FALSE);
                    self
            ->Draw();
                    
            return lReturn;

                
            case BM_SETCHECK:    // 設(shè)置選中狀態(tài)
                    lReturn = (LONG) CallWindowProc(self->m_OldProc, hWnd, uMsg, wParam, lParam);
                    self
            ->m_Check=wParam;
                    self
            ->Draw();
                    
            return lReturn;

                
            case WM_SETTEXT:    // 設(shè)置窗口文本
                    lReturn = (LONG) DefWindowProc(hWnd, uMsg, wParam, lParam);
                    self
            ->Draw();
                    
            return lReturn;

                
            case WM_PAINT:        // 窗口重畫
                    lReturn = (LONG) DefWindowProc(hWnd, uMsg, wParam, lParam);
                    self
            ->Draw();
                    
            return lReturn;
                
            case WM_DESTROY:        // 窗口銷毀
                    lReturn = (LONG) CallWindowProc(self->m_OldProc, hWnd, uMsg, wParam, lParam);
                    delete self;
                    
            return lReturn;
                
            case WM_MOUSEMOVE:        // 窗口移動(dòng)
                    if ( !self->m_isHighLight )
                    
            {            
                        self
            ->m_isHighLight=true;
                        self
            ->Draw();

                        
            // 追蹤鼠標(biāo)移出消息一次
                        TRACKMOUSEEVENT Tme;
                        Tme.cbSize 
            = sizeof(TRACKMOUSEEVENT);
                        Tme.dwFlags 
            = TME_LEAVE;
                        Tme.hwndTrack 
            = hWnd;
                        TrackMouseEvent(
            &Tme);
                    }

                    
            break;

                
            case WM_MOUSELEAVE:        // 鼠標(biāo)移出
                    if (self->m_isHighLight)
                    
            {
                        self
            ->m_isHighLight=false;
                        self
            ->Draw();
                    }

                    
            break;

                
            case WM_SETFOCUS:        // 獲得焦點(diǎn)
                    self->m_isFocus=true;
                    self
            ->Draw();
                    
            break;

                
            case WM_KILLFOCUS:        // 丟失焦點(diǎn)
                    self->m_isFocus=false;
                    self
            ->Draw();
                    
            break;
                }

                
            // 調(diào)用原來的回調(diào)函數(shù)
                lReturn = (LONG) CallWindowProc(self->m_OldProc, hWnd, uMsg, wParam, lParam);
                
            return lReturn;
            }


            void CSkinButton::Draw()
            {
                HDC hDC
            =GetWindowDC(m_hWnd);
                RECT rectWnd;
                GetWindowRect(m_hWnd,
            &rectWnd);
                rectWnd.right 
            -= rectWnd.left;
                rectWnd.bottom 
            -= rectWnd.top;
                rectWnd.left 
            = rectWnd.top = 0;

                HBITMAP hBmp
            =LoadBitmap(g_hInst,MAKEINTRESOURCE(IDB_BUTTON));
                HDC hMemDC
            =CreateCompatibleDC(hDC);
                SelectBitmap(hMemDC,hBmp);

                
            int idx=0;
                
            if(m_isDefault)
                    idx
            =4;
                
            if(m_isHighLight)
                    idx
            =1;
                
            if(m_isPressed)
                    idx
            =2;
                
            if(!IsWindowEnabled(m_hWnd))
                    idx
            =3;
                
            const int roundw=4;
                
            const int roundh=4;
                
            const int bmpw=18;
                
            const int bmph=21;
                idx
            *=bmph;
                BitBlt( hDC, 
            00, roundw, roundh,
                    hMemDC, 
            0, idx+0, SRCCOPY);
                BitBlt( hDC, 
            0, rectWnd.bottom-roundh, roundw, roundh,
                    hMemDC, 
            0, idx+bmph-roundh, SRCCOPY);
                BitBlt(hDC, rectWnd.right
            -roundw, 0, roundw, roundh,
                    hMemDC, bmpw
            -roundw, idx+0, SRCCOPY);
                BitBlt(hDC, rectWnd.right
            -roundw, rectWnd.bottom-roundh, roundw, roundh,
                    hMemDC, bmpw
            -roundw, idx+bmph-roundh, SRCCOPY);

                StretchBlt( hDC, 
            0, roundh, roundw, rectWnd.bottom-roundh*2,
                    hMemDC, 
            0, idx+roundh, roundw, bmph-roundh*2, SRCCOPY);
                StretchBlt( hDC, rectWnd.right
            -roundw, roundh, roundw, rectWnd.bottom-roundh*2,
                    hMemDC, bmpw
            -roundw, idx+roundh, roundw, bmph-roundh*2, SRCCOPY);
                StretchBlt( hDC, roundw, 
            0, rectWnd.right-roundw*2, roundh,
                    hMemDC, roundw, idx
            +0, bmpw-roundw*2, roundh, SRCCOPY);
                StretchBlt( hDC, roundw, rectWnd.bottom
            -roundh, rectWnd.right-roundw*2, roundh,
                    hMemDC, roundw, idx
            +bmph-roundh, bmpw-roundw*2, roundh, SRCCOPY);

                StretchBlt( hDC, roundw, roundh, rectWnd.right
            -roundw*2, rectWnd.bottom-roundh*2,
                    hMemDC, roundw, idx
            +roundh, bmpw-roundw*2, bmph-roundh*2, SRCCOPY);

                
            //if(m_isFocus)
                
            //{
                
            //    RECT r;
                
            //    r.left=r.top=3;
                
            //    r.right=rectWnd.right-3;
                
            //    r.bottom=rectWnd.bottom-3;
                
            //    DrawFocusRect(hDC, &r );
                
            //}

                SetBkMode(hDC,TRANSPARENT);
                HFONT hFont
            =GetWindowFont(m_hWnd);
                SelectFont(hDC,hFont);
                
            char szWinText[0x1000];
                GetWindowText(m_hWnd,szWinText,
            0x1000);
                DrawText(hDC,szWinText,strlen(szWinText),
            &rectWnd,DT_CENTER|DT_VCENTER|DT_SINGLELINE);

                DeleteDC(hMemDC);
                DeleteObject(hBmp);
            }


            LRESULT CALLBACK HookProc(
            int nCode, WPARAM wParam, LPARAM lParam)
            {
                LONG lReturn;
                
            if( nCode == HC_ACTION )
                
            {
                    PCWPSTRUCT pcwps
            =(PCWPSTRUCT)lParam;
                    
            switch(pcwps->message)
                    
            {
                    
            case WM_CREATE:
                        
            {
                            CHAR szClass[MAX_PATH];
                            GetClassName(pcwps
            ->hwnd, szClass, MAX_PATH);
                            
            if ( lstrcmpi(szClass, "Button"== 0 )
                            
            {
                                lReturn 
            = GetWindowLong(pcwps->hwnd, GWL_STYLE);
                                
            switch (lReturn & SS_TYPEMASK)
                                
            {
                                
            case BS_DEFPUSHBUTTON:        // 默認(rèn)按鈕
                                case BS_PUSHBUTTON:            // 普通按鈕
                                    CSkinButton::Install(pcwps->hwnd);
                                    
            break;
                                }

                            }

                        }

                        
            break;
                    }

                }


                
            return CallNextHookEx(g_hSKinHook, nCode, wParam, lParam);
            }


            void InstallSkin(HINSTANCE hInst)
            {
                g_hInst
            =hInst;
                
            if (g_hSKinHook)
                    UnhookWindowsHookEx(g_hSKinHook);
                g_hSKinHook 
            = SetWindowsHookEx(WH_CALLWNDPROC, HookProc, 0, GetCurrentThreadId());
            }

            VC7.1工程 下載
            posted on 2006-09-20 03:14 shaker(太子) 閱讀(2881) 評(píng)論(0)  編輯 收藏 引用 所屬分類: C++
            99久久中文字幕| 亚洲级αV无码毛片久久精品| 久久精品国产亚洲Aⅴ香蕉| 久久99精品免费一区二区| 亚洲伊人久久成综合人影院 | 青青热久久国产久精品| 中文字幕久久精品| 久久久久国产精品熟女影院| 久久香蕉国产线看观看乱码| 精品国产综合区久久久久久| 久久国语露脸国产精品电影| 潮喷大喷水系列无码久久精品| 国产精品久久久99| 亚洲精品无码久久一线| 韩国三级大全久久网站| 麻豆久久| 97超级碰碰碰久久久久| 久久人人爽人人澡人人高潮AV| 99久久国产综合精品女同图片| 亚洲精品国产成人99久久| 99久久综合国产精品免费| 久久美女网站免费| 久久精品国产亚洲αv忘忧草| a级成人毛片久久| 久久久久亚洲国产| 久久91这里精品国产2020| 久久国产免费直播| 少妇被又大又粗又爽毛片久久黑人| 欧美亚洲色综久久精品国产| 久久一本综合| 99久久www免费人成精品| 久久这里只有精品18| 一本大道久久香蕉成人网| 青青热久久综合网伊人| 久久久噜噜噜久久中文福利| 国产精品久久久久蜜芽| 久久无码人妻精品一区二区三区| 久久精品嫩草影院| 国产91色综合久久免费| 欧美黑人又粗又大久久久| 国产69精品久久久久久人妻精品|