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

推荐订阅源

S
Secure Thoughts
罗磊的独立博客
T
The Blog of Author Tim Ferriss
人人都是产品经理
人人都是产品经理
博客园 - 叶小钗
Last Week in AI
Last Week in AI
美团技术团队
Google Online Security Blog
Google Online Security Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
D
Docker
G
Google Developers Blog
大猫的无限游戏
大猫的无限游戏
酷 壳 – CoolShell
酷 壳 – CoolShell
小众软件
小众软件
月光博客
月光博客
L
LINUX DO - 最新话题
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
W
WeLiveSecurity
H
Heimdal Security Blog
Vercel News
Vercel News
SecWiki News
SecWiki News
Forbes - Security
Forbes - Security
Blog — PlanetScale
Blog — PlanetScale
Google DeepMind News
Google DeepMind News
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
TaoSecurity Blog
TaoSecurity Blog
T
Troy Hunt's Blog
A
About on SuperTechFans
C
Check Point Blog
S
Security Affairs
Hacker News - Newest:
Hacker News - Newest: "LLM"
AI
AI
WordPress大学
WordPress大学
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Help Net Security
Help Net Security
博客园_首页
The Last Watchdog
The Last Watchdog
S
SegmentFault 最新的问题
Hugging Face - Blog
Hugging Face - Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
Engineering at Meta
Engineering at Meta
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
I
Intezer
K
Kaspersky official blog
M
MIT News - Artificial intelligence
J
Java Code Geeks
G
GRAHAM CLULEY
P
Palo Alto Networks Blog

博客园 - 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转接口封装的方式 c++以代理的方式来实现接口化编程 c++对象工厂 使用模板来解决接口继承问题 VC++ 使用attributes定义接口
DirectUI消息循环的简单封装
Clingingboy · 2013-11-09 · via 博客园 - Clingingboy

2013-11-09 13:56  Clingingboy  阅读(1159)  评论()    收藏  举报

一.真窗体和假窗体

首先在DirectWindow内部创建一个真窗体(基于WTL),可以接收消息

class CMessageWindow : public CWindowImpl< CMessageWindow >
{
public:
    CMessageWindow();
    ~CMessageWindow();
    BEGIN_MSG_MAP( CMessageWindow )
        MESSAGE_RANGE_HANDLER( 0, 0xFFFF, HandleMessage )
    END_MSG_MAP()
}

然后在在HandleMessage 处理消息

image

二.通过MessageDispatcher转发消息

image

三.组装给上层比较容易理解的数据结构

image

这样上层就捕捉不到WM_LBUTTONUP消息,而变成自己封装的DirectUI_LButtonUp消息了

全部伪代码

class EventArg
{
public:
    int nId;
};

class MouseEventArg:public EventArg
{
public:
    int nX;
    int nY;
    int uKeyFlags;
};

class MessageDispatcher
{
    MessageDispatcher(DirectWindow *pWindow)
    {
        m_pWindow=pWindow;
    }

    void DispatcherLButtonUp(POINT pt,UINT uKeyFlags,BOOL *pbHandled)
    {
        MouseEventArg arg;
        arg.nId=DirectUI_LButtonUp;
        arg.nX=pt.x;
        arg.nY=pt.y;
        m_pWindow->OnMessage(&arg);
    }

private:
    DirectWindow *m_pWindow;
};

class CMessageWindow : public CWindowImpl< CMessageWindow >
{
public:
    CMessageWindow();
    ~CMessageWindow();
    BEGIN_MSG_MAP( CMessageWindow )
        MESSAGE_RANGE_HANDLER( 0, 0xFFFF, HandleMessage )
    END_MSG_MAP()

    virtual    LRESULT            HandleMessage( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled );

private:
    MessageDispatcher *m_pMessageDispatcher;
}

void CMessageWindow::OnLButtonUp( HWND hWnd, int nX, int nY, UINT uKeyFlags, BOOL& bHandled )
{
    POINT pt = {nX, nY};
    ::ClientToScreen(hWnd, &pt);

    m_pMessageDispatcher->DispatcherLButtonUp(pt, uKeyFlags, &bHandled)
}

class IElement;

class DirectWindow
{
    HRESULT OnMessage( IElement *pElement, EventArg *pArg, BOOL* pbHandled);
private:
    CMessageWindow *m_pMessageWindow;
};