English 中文(简体)
WTL Child window event handling
原标题:

I am developing window application in that I am having 2 child windows on left and right side. I want to handle input events for both windows separately. How to achieve it?

My code:

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;
    }

};
最佳回答

WTL::CSplitterWindow and WTL::CPaneContainer do not forward the WM_KEYxxx and WM_MOUSExxx messages to their parent.

Derive your EditorWindow from WTL::CSplitterWindowImpl and your Panes from WTL::CPaneContainerImpl for instance:

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; 
    }
问题回答

You can use ALT_MSG_MAP() in combination with CContainedWindow - you specify a message map ID for ATL_MSG_MAP() which you pass to CContainedWindows constructor.

The ATL documentation for CContainedWindowT has an example.





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签