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

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
Help Net Security
Help Net Security
P
Privacy International News Feed
T
Threat Research - Cisco Blogs
C
Cisco Blogs
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
L
LINUX DO - 热门话题
Security Latest
Security Latest
A
Arctic Wolf
G
GRAHAM CLULEY
月光博客
月光博客
S
Securelist
D
Docker
J
Java Code Geeks
T
Troy Hunt's Blog
T
Tenable Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
SecWiki News
SecWiki News
S
Security @ Cisco Blogs
量子位
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
L
LINUX DO - 最新话题
Recent Commits to openclaw:main
Recent Commits to openclaw:main
aimingoo的专栏
aimingoo的专栏
博客园 - 【当耐特】
H
Heimdal Security Blog
The Hacker News
The Hacker News
博客园 - 三生石上(FineUI控件)
Application and Cybersecurity Blog
Application and Cybersecurity Blog
N
Netflix TechBlog - Medium
Vercel News
Vercel News
Forbes - Security
Forbes - Security
B
Blog RSS Feed
H
Hackread – Cybersecurity News, Data Breaches, AI and More
IT之家
IT之家
B
Blog
MongoDB | Blog
MongoDB | Blog
博客园 - 聂微东
Google DeepMind News
Google DeepMind News
S
Secure Thoughts
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
C
Check Point Blog
云风的 BLOG
云风的 BLOG
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
T
The Blog of Author Tim Ferriss
L
Lohrmann on Cybersecurity
F
Full Disclosure
D
Darknet – Hacking Tools, Hacker News & Cyber Security
P
Proofpoint News Feed

博客园 - 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;
};