norains的专栏

只专注于WINCE开发

用户操作
[即时聊天] [发私信] [加为好友]
norainsID:norains
142881次访问,排名598,好友0人,关注者53人。
代码其实是一种乐趣
norains的文章
原创 189 篇
翻译 0 篇
转载 10 篇
评论 274 篇
norains的公告
联系方式请看置顶文章
最近评论
dfdf:讨厌MFC!我觉得MFC就是太乱了!看似无用的代码不要不行,MD微软啥都给我们做完了,原理性的东西我们却永远没法搞懂了!
ironox:有个地方 我觉得很别扭,不知道怎么办好

比如说 CReg reg(HKEY_CURRENT_USER,TEXT("ControlPanel\Volume"));
ControlPanel\Volume 有可能不存在呀,这个该怎么处理哦?对象虽然创建了,出错了也没提示
szterry:呵呵,果然工作狂技术狂,同感,一样的感觉……不过我才刚毕业一年……搞IT就是玩……
jinlking:这个botton的实现只是在主窗口画了一块区域,对于事件的处理还要放在主窗口的窗口处理函数之中,在对应的消息处理上调用CheckTap来判断是否是此“按钮”,问一下,这种方法与把按钮封装在子窗口中有什么区别,二者使用那个更好?
KUODY:博主真是好人
文章分类
收藏
    相册
    动漫
    文章图片
    程序交流
    xumercury的BLOG
    狗友们的博客
    清蒸石斑鱼
    美女如刀锋
    茁茁的BLOG
    魅力老姐的窝
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    原创 CProgress类使用例程收藏

    新一篇: 串口伪驱动实例 | 旧一篇: CText类使用例程

    //========================================================================
    //TITLE:
    //    CProgress类使用例程
    //AUTHOR:
    //    norains
    //DATE:
    //    Tuesday  17-April-2007
    //Environment:
    //        EVC4.0 + Standard SDK 4.2
    //        EVC4.0 + Standard SDK 5.0
    //========================================================================

            CProgress类是仿照微软的CProgress写的一个显示进度类.最大的区别在于,该类的状态显示的图片可以按自己意愿设置,这对于某些需要风格独特的程序来说,显得比较方便.
           
            该类的使用范例如下:
           
            //声明一个对象       
     CProgress prg;

           
            //设置显示的位置       
     prg.SetPosition(rcWnd);


            //设置有效和无效的图片
      prg.SetImgInfoInvalid(&imgInvalid);
      prg.SetImgInfoValid(
    &imgValid)

            //设置范围     
       prg.SetRange(0,6);
           
            //设置等级       
     prg.SetLevel(4);        
           
            //传入应用程序的实例句柄,令控件能读取图片       
     prg.SetHinstance(hInst);
           
            //绘制控件       
     prg.Draw(hdc);



    //////////////////////////////////////////////////////////////////////
    // Progress.h: interface for the CProgress class.
    //
    //Version: 
    //    1.0.2
    //Data:
    //    2007.04.12   
    //////////////////////////////////////////////////////////////////////

    #ifndef PROGRESS_H
    #define PROGRESS_H


    #include 
    "CtrlCommon.h"


    //The image displayed information
    typedef struct
    {
        LONG imgID;
        LONG left;
        LONG top;
        LONG right;
        LONG bottom;
    }
    DISPIMAGEINFO,*PDISPIMAGEINFO;

    class CProgress  
    {
    public:
        BOOL SetBkMode(
    int iMode);
        
    void SetBkColor(COLORREF crColor);
        
    void SetHinstance(HINSTANCE hInst);
        BOOL Draw(HDC hdc);
        BOOL SetLevel(
    int m_iLevel);
        BOOL SetRange(
    int iMin,int iMax);
        
    void SetImgInfoInvalid(const DISPIMAGEINFO *pInfo);
        
    void SetImgInfoValid(const DISPIMAGEINFO *pInfo);
        
    void SetPosition(const RECT *prc);
        CProgress();
        
    virtual ~CProgress();
    protected:
        RECT m_rcWndPos;
        DISPIMAGEINFO m_ImgValid;
        DISPIMAGEINFO m_ImgInvalid;
        
    int m_iMinLevel;
        
    int m_iMaxLevel;
        
    int m_iCurLevel;
        HINSTANCE m_hInst;
        COLORREF m_crBkColor;
        
    int m_iBkMode;
    }
    ;

    #endif //#ifndef PROGRESS_H


    //////////////////////////////////////////////////////////////////////
    // Progress.cpp: implementation of the CProgress class.
    //
    //////////////////////////////////////////////////////////////////////

    #include 
    "stdafx.h"
    #include 
    "Progress.h"


    //--------------------------------------------------------------------
    //Macro define
    #define DEFAULT_MIN_LEVEL                0
    #define DEFAULT_MAX_LEVEL                10
    #define DEFAULT_CUR_LEVEL                0
    #define DEFAULT_BKCOLOR                    RGB(128,128,128)
    #define DEFAULT_BKMODE                    TRANSPARENT

    //The interval between two level image
    #define LEVEL_INTERVAL            4
    //--------------------------------------------------------------------
    //////////////////////////////////////////////////////////////////////
    // Construction/Destruction
    //////////////////////////////////////////////////////////////////////

    CProgress::CProgress()
    {
        memset(
    &m_rcWndPos,0,sizeof(m_rcWndPos));
        memset(
    &m_ImgValid,0,sizeof(m_ImgValid));
        memset(
    &m_ImgInvalid,0,sizeof(m_ImgInvalid));
        m_iMaxLevel 
    = DEFAULT_MAX_LEVEL;
        m_iMinLevel 
    = DEFAULT_MIN_LEVEL;
        m_iCurLevel 
    = DEFAULT_CUR_LEVEL;
        m_hInst 
    = NULL;
        m_crBkColor 
    = DEFAULT_BKCOLOR;
        m_iBkMode 
    = DEFAULT_BKMODE;
    }


    CProgress::
    ~CProgress()
    {
    }



    //-------------------------------------------------------------------
    //Description:
    //    Set the position
    //-------------------------------------------------------------------
    void CProgress::SetPosition(const RECT *prc)
    {
        m_rcWndPos 
    = *prc;
    }



    //-------------------------------------------------------------------
    //Description:
    //    Set the image information for valid
    //-------------------------------------------------------------------
    void CProgress::SetImgInfoValid(const DISPIMAGEINFO *pInfo)
    {
        m_ImgValid 
    = *pInfo;
    }



    //-------------------------------------------------------------------
    //Description:
    //    Set the image information for invalid
    //-------------------------------------------------------------------
    void CProgress::SetImgInfoInvalid(const DISPIMAGEINFO *pInfo)
    {
        m_ImgInvalid 
    = *pInfo;
    }



    //-------------------------------------------------------------------
    //Description:
    //    Set the range
    //-------------------------------------------------------------------
    BOOL CProgress::SetRange(int iMin, int iMax)
    {
        
    if(iMin < 0 || iMax < 0 || iMin >= iMax)
        
    {
            
    return FALSE;
        }


        m_iMinLevel 
    = iMin;
        m_iMaxLevel 
    = iMax;

        
    return TRUE;
    }




    //-------------------------------------------------------------------
    //Description:
    //    Set the position
    //-------------------------------------------------------------------
    BOOL CProgress::SetLevel(int iLevel)
    {
        
    if(iLevel < m_iMinLevel || iLevel > m_iMaxLevel)
        
    {
            
    return FALSE;
        }

        m_iCurLevel 
    = iLevel;
        
    return TRUE;
    }



    //-------------------------------------------------------------------
    //Description:
    //    Draw the control
    //-------------------------------------------------------------------
    BOOL CProgress::Draw(HDC hdc)
    {
        
    if(m_hInst == NULL)
        
    {
            
    return FALSE;
        }


        
    int iImgTotalWidth = (m_ImgValid.right - m_ImgValid.left) * (m_iMaxLevel - m_iMinLevel) + LEVEL_INTERVAL * (m_iMaxLevel - m_iMinLevel - 1);
        
    int iImgTotalHeight = m_ImgValid.bottom - m_ImgValid.top;

        
    //Create a DC that matches the device
        HBITMAP hBitmap = CreateCompatibleBitmap(hdc,iImgTotalWidth,iImgTotalHeight);
        HDC hdcMem 
    = CreateCompatibleDC(hdc);
        
    //Select the bitmap into to the compatible device context
        HGDIOBJ hOldSel = SelectObject(hdcMem,hBitmap);



        
    //Draw the background
        
    //The frame color
        HPEN hPen=CreatePen(PS_SOLID,1,m_crBkColor);
        HPEN hOldPen
    =NULL;
        hOldPen
    =(HPEN)SelectObject(hdcMem,hPen);
        
    //the rect color
        HBRUSH hBrush = CreateSolidBrush(m_crBkColor);
        HGDIOBJ hOldBrush 
    = SelectObject(hdcMem,hBrush);
        
    //Draw
        Rectangle(hdcMem,0,0,iImgTotalWidth + 1, iImgTotalHeight + 1);
        
    //Realse the resource
        SelectObject(hdcMem,hOldBrush);
        DeleteObject(hBrush);
        SelectObject(hdcMem,hOldPen);
        DeleteObject(hPen);




        
    //Draw the valid image
        
    //Create a DC that matches the device to draw the background bitmap
        HDC hdcBmp = CreateCompatibleDC(hdc);
        
    //Load the  bitmap
        HANDLE    hBmp = LoadImage(m_hInst,MAKEINTRESOURCE(m_ImgValid.imgID),IMAGE_BITMAP,0,0,0);
        
    //Select the bitmap into to the compatible device context
        HGDIOBJ hOldBmpSel = SelectObject(hdcBmp,hBmp);
        
    int i = 0, iPos_x = 0;
        
    for(i = m_iMinLevel + 1; i <= m_iCurLevel; i ++)
        
    {
            
    //Copy the bitmap image to the memory DC
            BitBlt(hdcMem,iPos_x,0,(m_ImgValid.right - m_ImgValid.left),(m_ImgValid.bottom - m_ImgValid.top),hdcBmp,m_ImgValid.left,m_ImgValid.top,SRCCOPY);
            iPos_x 
    += (m_ImgValid.right - m_ImgValid.left) + LEVEL_INTERVAL;
        }

        
    //Delete the bmp
        DeleteObject(hBmp);


        
    //Draw the invalid image
        hBmp = LoadImage(m_hInst,MAKEINTRESOURCE(m_ImgInvalid.imgID),IMAGE_BITMAP,0,0,0);
        
    //Select the bitmap into to the compatible device context
        SelectObject(hdcBmp,hBmp);
        
    for(i = m_iCurLevel + 1; i <= m_iMaxLevel; i ++)
        
    {
            
    //Copy the bitmap image to the memory DC
            BitBlt(hdcMem,iPos_x,0,(m_ImgValid.right - m_ImgValid.left),(m_ImgValid.bottom - m_ImgValid.top),hdcBmp,m_ImgInvalid.left,m_ImgInvalid.top,SRCCOPY);
            iPos_x 
    += (m_ImgValid.right - m_ImgValid.left) + LEVEL_INTERVAL;
        }

        
    //Delete the bmp
        DeleteObject(hBmp);



        
    if(m_iBkMode == TRANSPARENT)
        
    {
            TransparentImage(hdc,m_rcWndPos.left,m_rcWndPos.top,(m_rcWndPos.right 
    - m_rcWndPos.left),(m_rcWndPos.bottom - m_rcWndPos.top),
                hdcMem,
    0,0,iImgTotalWidth,iImgTotalHeight,m_crBkColor);
        }

        
    else
        
    {
            StretchBlt(hdc,m_rcWndPos.left,m_rcWndPos.top,(m_rcWndPos.right 
    - m_rcWndPos.left),(m_rcWndPos.bottom - m_rcWndPos.top),
                hdcMem,
    0,0,iImgTotalWidth,iImgTotalHeight,SRCCOPY);
        }

        
    //Restore original bitmap selection and destroy the memory DC
        SelectObject(hdcBmp,hOldBmpSel);
        SelectObject(hdcMem,hOldSel);
        DeleteObject(hBitmap);    
        DeleteDC(hdcBmp);
        DeleteDC(hdcMem);



        
    return TRUE;
    }



    //-------------------------------------------------------------------
    //Description:
    //    Set the hinstance
    //-------------------------------------------------------------------
    void CProgress::SetHinstance(HINSTANCE hInst)
    {
        m_hInst 
    = hInst;
    }



    //-------------------------------------------------------------------
    //Description:
    //    Set the background color
    //-------------------------------------------------------------------
    void CProgress::SetBkColor(COLORREF crColor)
    {
        m_crBkColor 
    = crColor;
    }



    //--------------------------------------------------------------------
    //Description:
    //    Set the background mode.If you choose the TRANSPARENT, the transparent
    //color is the background color
    //
    //Parameters:
    //    iMode: [in] The value is just like as follow:
    //        OPAQUE      -- Background is filled with the current background color before the text, 
    //                        hatched brush, or pen is drawn. 
    //        TRANSPARENT -- Background remains untouched. 

    //--------------------------------------------------------------------
    BOOL CProgress::SetBkMode(int iMode)
    {
        
    if(iMode == OPAQUE || iMode == TRANSPARENT)
        
    {
            m_iBkMode 
    = iMode;
            
    return TRUE;
        }

        
    else
        
    {
            
    return FALSE;
        }

    }

    发表于 @ 2007年04月17日 23:36:00|评论(loading...)|编辑

    新一篇: 串口伪驱动实例 | 旧一篇: CText类使用例程

    评论:没有评论。

    发表评论  


    登录
    Csdn Blog version 3.1a
    Copyright © norains