Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. WTL work around WM_NOTIFY

WTL work around WM_NOTIFY

Scheduled Pinned Locked Moved ATL / WTL / STL
c++tutorialquestiondiscussion
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    conman110
    wrote on last edited by
    #1

    Hi, I came up with a way how to call member functions directly so sending WM_NODIFY messages is no longer neccessary and I am interested in your opinions! I have a MDI window (derived from CMDIFrameWindowImpl) that notifies the active MDI child (CChildFrame derived from CMDIChildWindowImpl) if its document should be opened/saved/reopened ect... The only way I knew to do this was to send the MDI child a WM_NOTIFY message with different notification code and NMHDR*. I thought it would be nice to call member function like Save(), Open(CString file),... directly on the CChildFrame object because it would be a lot easier to read and the casting of NMHDR* would no longer be neccessary. So here is the code: // The notification code #define ATL_GET_THIS 100 template<typename T> T* AtlGetObject(HWND hWnd) { NMHDR nmhdr = { hWnd, 0, ATL_GET_THIS }; return (T*)(::SendMessage(hWnd, WM_NOTIFY, 0, (LPARAM)&nmhdr)); } The CChildFrame must handle the ATL_GET_THIS notification: BEGIN_MSG_MAP_EX(CChildFrame) ... NOTIFY_CODE_HANDLER_EX(ATL_GET_THIS, _AtlOnNotifyGetThis) ... END_MSG_MAP() LRESULT _AtlOnNotifyGetThis(NMHDR* /*phdr*/) { return (LRESULT)this; } So the code in the parent to call some member function in the active MDI child would look like this: CChildFrame* pWndChild = AtlGetObject(MDIGetActive()); CString sFilename = pWndChild->GetFilename(); CFileDialog dlg(FALSE, 0, sFilename); if (dlg.DoModal() == IDOK) { pWndChild->SaveAs(dlg.m_ofn.lpstrFile); } What do you say? I know it works, but are there some traps I didn't see? And if this is a good idea, why is nothing like this in the ATL/WTL already? Or there is and I didn't see it? Thanks for your time! Constantin

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups