【问题标题】:WTL Child window event handlingWTL子窗口事件处理
【发布时间】:2011-02-03 17:02:54
【问题描述】:

我正在开发窗口应用程序,因为我在左侧和右侧有 2 个子窗口。 我想分别处理两个窗口的输入事件。 如何实现?

我的代码:

class EditorWindow : public DxWindow
{
public:
    CSplitterWindow m_vSplit;
    CPaneContainer m_lPane;
    CPaneContainer m_rPane; 
    PropertyDialog m_propertyWnd;
    DECLARE_WND_CLASS(_T("Specific_Class_Name"))

    BEGIN_MSG_MAP(EditorWindow)
        MESSAGE_HANDLER(WM_CREATE, OnCreate)
        MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
        MESSAGE_HANDLER(WM_LBUTTONDOWN, KeyHandler)
        MESSAGE_HANDLER(WM_KEYUP, KeyHandler)
        MESSAGE_HANDLER(WM_LBUTTONDOWN, KeyHandler)
    END_MSG_MAP()

    LRESULT OnCreate(UINT, WPARAM, LPARAM, BOOL&)
    {
        CRect rcVert;
        GetClientRect(&rcVert);     
        m_vSplit.Create(m_hWnd, rcVert, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
        m_vSplit.SetSplitterPos(rcVert.Width()/1.4f); // from left
        m_lPane.Create(m_vSplit.m_hWnd);        
        m_vSplit.SetSplitterPane(0, m_lPane);   
        //m_lPane.SetTitle(L"Left Pane");

        m_rPane.Create(m_vSplit.m_hWnd);    
        m_vSplit.SetSplitterPane(1, m_rPane);       
        m_rPane.SetTitle(L"Properties");
        m_propertyWnd.Create(m_rPane.m_hWnd);
        //m_vSplit.SetSplitterPane(SPLIT_PANE_LEFT, md.m_hWnd);

        return 0;
    }
    LRESULT OnDestroy( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled )
    {
        PostQuitMessage(0);
        bHandled = FALSE;
        return 0;
    }
    LRESULT KeyHandler( UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled )
    {
        return 0;
    }

};

【问题讨论】:

    标签: c++ winapi wtl


    【解决方案1】:

    您可以将 ALT_MSG_MAP()CContainedWindow 结合使用 - 您可以为 ATL_MSG_MAP() 指定消息映射 ID,并将其传递给 CContainedWindows 构造函数。

    CContainedWindowT 的 ATL 文档有一个示例。

    【讨论】:

      【解决方案2】:

      WTL::CSplitterWindow 和 WTL::CPaneContainer 不会将 WM_KEYxxx 和 WM_MOUSExxx 消息转发给它们的父级。

      例如,从 WTL::CSplitterWindowImpl 导出 EditorWindow,从 WTL::CPaneContainerImpl 导出窗格:

      class CMyPaneContainer : public CPaneContainerImpl<CMyPaneContainer>
      {
      public:
          DECLARE_WND_CLASS_EX(_T("MyPaneContainer"), 0, -1)
          BEGIN_MSG_MAP(CMyPaneContainer)
              MESSAGE_RANGE_HANDLER(WM_KEYFIRST, WM_KEYLAST, OnForward)
              MESSAGE_RANGE_HANDLER(WM_MOUSEFIRST, WM_MOUSELAST, OnForward)
              CHAIN_MSG_MAP(CPaneContainerImpl<CMyPaneContainer>)
          END_MSG_MAP()
      
          LRESULT OnForward(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
          {
             if (uMsg == WM_MOUSEWHEEL)
                 return bHandled = FALSE; // Don't forward WM_MOUSEWHEEL
             return GetParent().SendMessage(uMsg, wParam, lParam);
          }
      };
      
      
      class EditorWindow : public CSplitterWindowImpl<EditorWindow, true, CWindow/*DxWindow*/> 
      {
          typedef CSplitterWindowImpl<EditorWindow, true, CWindow/*DxWindow*/> baseClass;
      public: 
          CMyPaneContainer m_lPane; 
          CMyPaneContainer m_rPane;  
          //PropertyDialog m_propertyWnd; 
          DECLARE_WND_CLASS(_T("Specific_Class_Name")) 
      
          BEGIN_MSG_MAP(EditorWindow) 
              MESSAGE_HANDLER(WM_CREATE, OnCreate) 
              MESSAGE_HANDLER(WM_LBUTTONDOWN, KeyHandler) 
              MESSAGE_HANDLER(WM_KEYUP, KeyHandler) 
              CHAIN_MSG_MAP(baseClass)
          END_MSG_MAP() 
      
          LRESULT OnCreate(UINT, WPARAM, LPARAM, BOOL&) 
          { 
              m_lPane.Create(m_hWnd);         
              m_lPane.SetTitle(L"Left Pane"); 
      
              m_rPane.Create(m_hWnd);     
              m_rPane.SetTitle(L"Properties"); 
              //m_propertyWnd.Create(m_rPane.m_hWnd); 
              SetSplitterPosPct(70); // 70% from left 
              SetSplitterPanes(m_lPane, m_rPane); 
      
              return 0; 
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-04-03
        • 2014-05-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多