0

I'm experimenting with WTL, and I'd like to separate a large message map to two or more files. For example, I'd like to move the tray icon logic into a separate file. I'm aware of CHAIN_MSG_MAP and CHAIN_MSG_MAP_MEMBER, but what should I use in this case?

Also, how will I be able to access the window handle from the second class?

Roman R.
  • 68,205
  • 6
  • 94
  • 158
Paul
  • 6,061
  • 6
  • 39
  • 70
  • After looking at the code, I'm not sure that what I try to achieve is even possible. Is it possible to have two files (with probably two classes), while both have a `m_hWnd` member which refers to the same window? – Paul Sep 16 '14 at 16:20
  • Possible. But it is still too broad. – Roman R. Sep 16 '14 at 16:22
  • Well, take the tray icon as an example. on `WM_CREATE` I initialize `NOTIFYICONDATA`, call `Shell_NotifyIcon(NIM_ADD)`. On `"TaskbarCreated"`, I recreate it. Upon a right click, I show a menu. etc. Can I move all those functionality cleanly to a separate file? I found this class, which solved the task by creating an extra window (not too elegant IMO): http://www.naughter.com/ntray.html – Paul Sep 16 '14 at 16:43
  • I would suggest having one message map but partitioning the handlers into separate files, unless there is a specific requirement for the message map to also be split up. – user1793036 Sep 17 '14 at 02:59

1 Answers1

0

You may be looking for something like this (not tested; my WTL is rather rusty; caveat emptor).

class TrayIconHandler : public CWindow, public CMessageMap {
public:  
  BEGIN_MSG_MAP(TrayIconHandler)
  // Message handlers to taste
  END_MSG_MAP()
};

class MainWindow : public CWindowImpl<MainWindow> {
public:
  BEGIN_MSG_MAP(MainWindow)
    MESSAGE_HANDLER(WM_CREATE, OnCreate)
    // Other message handlers
    CHAIN_MSG_MAP_MEMBER(tray_icon_)
  END_MSG_MAP()

  LRESULT OnCreate(UINT, WPARAM, LPARAM, BOOL&) {
    tray_icon_.m_hWnd = m_hWnd;
  }
private:
  TrayIconHandler tray_icon_;
};

The two classes may be in different source files and/or headers, of course.

Igor Tandetnik
  • 50,461
  • 4
  • 56
  • 85