• <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  評論-111  文章-0  trackbacks-0
            效果:

            只實現了對BUTTON的換膚 不過其他的控件基本原理是一樣的吧~!
            代碼有點亂 并且有些部分的設計還不是很合理

            帖出來就是希望各位大俠們批評指教

            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:    // 按鈕風格改變
                    self->m_isDefault=((wParam&BS_DEFPUSHBUTTON)!=0);
                    self
            ->m_isPushButton=((wParam&BS_PUSHBUTTON)!=0);

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

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

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

                
            case WM_SETTEXT:    // 設置窗口文本
                    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:        // 窗口移動
                    if ( !self->m_isHighLight )
                    
            {            
                        self
            ->m_isHighLight=true;
                        self
            ->Draw();

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

                    
            break;

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

                    
            break;

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

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

                
            // 調用原來的回調函數
                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:        // 默認按鈕
                                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) 評論(0)  編輯 收藏 引用 所屬分類: C++
            精品久久久无码21p发布| 国产精品久久精品| 国産精品久久久久久久| 久久婷婷五月综合97色| 久久久久亚洲精品日久生情| 久久最新免费视频| 久久久久久久综合日本| 国产精品熟女福利久久AV| 青青国产成人久久91网| 久久精品亚洲中文字幕无码麻豆 | 99久久99久久精品国产片果冻 | 精品久久久久久久无码 | 国产欧美久久一区二区| 97精品国产91久久久久久| 精品一区二区久久久久久久网站| 久久国产精品久久| 99久久国产主播综合精品| 久久久久亚洲精品男人的天堂| 久久亚洲2019中文字幕| 久久AV高潮AV无码AV| 国产69精品久久久久777| 国产三级精品久久| 伊人久久大香线蕉综合网站| 色欲久久久天天天综合网| 99国产欧美久久久精品蜜芽 | 一本一本久久a久久综合精品蜜桃| 亚洲中文久久精品无码ww16| 国产成人久久AV免费| 久久国产香蕉一区精品| 国产精品99久久久精品无码| 国产精品久久久久久影院| 无码国内精品久久人妻麻豆按摩| 无码国内精品久久人妻| 久久久久99精品成人片三人毛片| A级毛片无码久久精品免费| 久久免费线看线看| 久久亚洲AV无码精品色午夜麻豆| 国产精品久久久久…| av色综合久久天堂av色综合在| 国产成人久久精品二区三区| 午夜精品久久久久久久久|