惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
Recent Announcements
Recent Announcements
D
Docker
V
V2EX
阮一峰的网络日志
阮一峰的网络日志
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
The GitHub Blog
The GitHub Blog
U
Unit 42
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
月光博客
月光博客
腾讯CDC
B
Blog
博客园_首页
罗磊的独立博客
D
DataBreaches.Net
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
L
LangChain Blog
aimingoo的专栏
aimingoo的专栏
MongoDB | Blog
MongoDB | Blog
GbyAI
GbyAI
Stack Overflow Blog
Stack Overflow Blog
M
MIT News - Artificial intelligence

博客园 - Clingingboy

冒个泡,刷刷存在感 使用文件映射和信号量来进程间通信 Xperf Basics: Recording a Trace (the easy way)(转) Xperf Basics: Recording a Trace(转) Xperf Analysis Basics(转) Android相关sdk使用 Uniscribe文字自动换行 Chrome RenderText分析(2) c++智能指针 codepage IMLangCodePages GUI 快捷键的实现思路 Menu实现逻辑 2个函数宏技巧 绘图 Painter转接口封装的方式 DirectUI消息循环的简单封装 c++以代理的方式来实现接口化编程 c++对象工厂 使用模板来解决接口继承问题 VC++ 使用attributes定义接口
控件保持多种绘图状态的做法
Clingingboy · 2013-11-21 · via 博客园 - Clingingboy

控件保持多种绘图状态的做法

2013-11-21 15:03  Clingingboy  阅读(357)  评论()    收藏  举报

基本思路

#pragma once
#include <map>

struct IPainter
{
    void Paint() {}
};

class Element
{
    void SetPainterState(int dwState, IPainter* pPainter)
    {
        m_mapStatePainter[dwState]=pPainter;

        if(dwState==m_dwState)
        {
            GoToState(dwState);
        }
    }

    IPainter* GetPainterState(int dwState)
    {
        return m_mapStatePainter[m_dwState];
    }

    int GetState()
    {
        return m_dwState;
    }

    void GoToState(int dwState)
    {
        m_dwState=dwState;

        //InvalidateRect();
    }

    void Paint() 
    {
        m_mapStatePainter[m_dwState]->Paint();
    }

private:
    int        m_dwState;
    std::map<int,IPainter*>     m_mapStatePainter;
};