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. How to use "GetWindowProc"?

How to use "GetWindowProc"?

Scheduled Pinned Locked Moved ATL / WTL / STL
tutorialquestion
3 Posts 2 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.
  • R Offline
    R Offline
    Roozbeh69
    wrote on last edited by
    #1

    Hi Everybody Does anybody know how to override the GetWindowProc method? I want to handle some specific messages in my own window procedure and direct the others to the base WndProc. Regards Roozbeh.

    I 1 Reply Last reply
    0
    • R Roozbeh69

      Hi Everybody Does anybody know how to override the GetWindowProc method? I want to handle some specific messages in my own window procedure and direct the others to the base WndProc. Regards Roozbeh.

      I Offline
      I Offline
      Igor Vigdorchik
      wrote on last edited by
      #2

      1. You do not need to override GetWindowProc(), it can be done in the PreTranslateMessage() like so:

      virtual BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)
      {
      if (pMsg->message == WM_COMMAND)
      OnCommand(true);

      return FALSE;
      

      }

      2. If you still want to do it, here is an example how to override a GetDialogProc(), hope it's helpful:

      DLGPROC CMyDlg::GetDialogProc()
      {
      return MyDialogProc;
      }

      // Our own dialog procedure that is mostly copied from
      // CDialogImplBaseT<>::DialogProc() in Atlwin.h.
      INT_PTR CALLBACK CMyDlg::MyDialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
      {
      CNoteDlg * pThis = (CNoteDlg*)hWnd;
      // Set a ptr to this message and save the old value.
      _ATL_MSG msg(pThis->m_hWnd, uMsg, wParam, lParam);
      const _ATL_MSG* pOldMsg = pThis->m_pCurrentMsg;
      pThis->m_pCurrentMsg = &msg;
      // Pass to the message map to process.
      LRESULT lRes;
      BOOL bRet = pThis->ProcessWindowMessage(pThis->m_hWnd, uMsg, wParam,
      lParam, lRes, 0);
      // If window has been destroyed and this is the last message,
      // then delete ourselves.
      if (DEFERDELETE == pThis->m_bAutoDelete && pOldMsg == NULL)
      {
      delete pThis;
      return FALSE;
      }
      // Restore saved value for the current message.
      ATLASSERT(pThis->m_pCurrentMsg == &msg);
      pThis->m_pCurrentMsg = pOldMsg;
      // Set result if message was handled.
      if(bRet)
      {
      switch (uMsg)
      {
      case WM_COMPAREITEM:
      case WM_VKEYTOITEM:
      case WM_CHARTOITEM:
      case WM_INITDIALOG:
      case WM_QUERYDRAGICON:
      case WM_CTLCOLORMSGBOX:
      case WM_CTLCOLOREDIT:
      case WM_CTLCOLORLISTBOX:
      case WM_CTLCOLORBTN:
      case WM_CTLCOLORDLG:
      case WM_CTLCOLORSCROLLBAR:
      case WM_CTLCOLORSTATIC:
      return lRes;
      break;
      }
      ::SetWindowLong(pThis->m_hWnd, DWL_MSGRESULT, lRes);
      return TRUE;
      }
      if(uMsg == WM_NCDESTROY)
      {
      // Clear out window handle.
      HWND hWnd = pThis->m_hWnd;
      pThis->m_hWnd = NULL;
      // Clean up after dialog box is destroyed.
      pThis->OnFinalMessage(hWnd);
      // If we want to automatically delete ourselves...
      if (pThis->m_bAutoDelete)
      {
      // If no outstanding messages to process in call stack,
      // m_pCurrentMsg will be NULL so we can delete ourselves.
      if (pThis->m_pCurrentMsg == NULL)
      delete pThis;
      // Else set a flag so we can delete ourselves later.
      else
      pThis->m_bAutoDelete = DEFERDELETE;
      }
      }

      return FALSE;
      

      }

      R 1 Reply Last reply
      0
      • I Igor Vigdorchik

        1. You do not need to override GetWindowProc(), it can be done in the PreTranslateMessage() like so:

        virtual BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)
        {
        if (pMsg->message == WM_COMMAND)
        OnCommand(true);

        return FALSE;
        

        }

        2. If you still want to do it, here is an example how to override a GetDialogProc(), hope it's helpful:

        DLGPROC CMyDlg::GetDialogProc()
        {
        return MyDialogProc;
        }

        // Our own dialog procedure that is mostly copied from
        // CDialogImplBaseT<>::DialogProc() in Atlwin.h.
        INT_PTR CALLBACK CMyDlg::MyDialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
        {
        CNoteDlg * pThis = (CNoteDlg*)hWnd;
        // Set a ptr to this message and save the old value.
        _ATL_MSG msg(pThis->m_hWnd, uMsg, wParam, lParam);
        const _ATL_MSG* pOldMsg = pThis->m_pCurrentMsg;
        pThis->m_pCurrentMsg = &msg;
        // Pass to the message map to process.
        LRESULT lRes;
        BOOL bRet = pThis->ProcessWindowMessage(pThis->m_hWnd, uMsg, wParam,
        lParam, lRes, 0);
        // If window has been destroyed and this is the last message,
        // then delete ourselves.
        if (DEFERDELETE == pThis->m_bAutoDelete && pOldMsg == NULL)
        {
        delete pThis;
        return FALSE;
        }
        // Restore saved value for the current message.
        ATLASSERT(pThis->m_pCurrentMsg == &msg);
        pThis->m_pCurrentMsg = pOldMsg;
        // Set result if message was handled.
        if(bRet)
        {
        switch (uMsg)
        {
        case WM_COMPAREITEM:
        case WM_VKEYTOITEM:
        case WM_CHARTOITEM:
        case WM_INITDIALOG:
        case WM_QUERYDRAGICON:
        case WM_CTLCOLORMSGBOX:
        case WM_CTLCOLOREDIT:
        case WM_CTLCOLORLISTBOX:
        case WM_CTLCOLORBTN:
        case WM_CTLCOLORDLG:
        case WM_CTLCOLORSCROLLBAR:
        case WM_CTLCOLORSTATIC:
        return lRes;
        break;
        }
        ::SetWindowLong(pThis->m_hWnd, DWL_MSGRESULT, lRes);
        return TRUE;
        }
        if(uMsg == WM_NCDESTROY)
        {
        // Clear out window handle.
        HWND hWnd = pThis->m_hWnd;
        pThis->m_hWnd = NULL;
        // Clean up after dialog box is destroyed.
        pThis->OnFinalMessage(hWnd);
        // If we want to automatically delete ourselves...
        if (pThis->m_bAutoDelete)
        {
        // If no outstanding messages to process in call stack,
        // m_pCurrentMsg will be NULL so we can delete ourselves.
        if (pThis->m_pCurrentMsg == NULL)
        delete pThis;
        // Else set a flag so we can delete ourselves later.
        else
        pThis->m_bAutoDelete = DEFERDELETE;
        }
        }

        return FALSE;
        

        }

        R Offline
        R Offline
        Roozbeh69
        wrote on last edited by
        #3

        Thanks a lot for your help. Regards Roozbeh.

        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