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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. sendmessage and CDialog pointer

sendmessage and CDialog pointer

Scheduled Pinned Locked Moved C / C++ / MFC
question
9 Posts 4 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.
  • N Offline
    N Offline
    nss
    wrote on last edited by
    #1

    I need to transmit the pointer of the CDialog to the parent > I am not able to set a member of the parent because it doesnt fit with my scheme. So can I do this? m_pParent->SendMessage(UDM_SOMETHING, this, ndummy) ? Thanks

    V 1 Reply Last reply
    0
    • N nss

      I need to transmit the pointer of the CDialog to the parent > I am not able to set a member of the parent because it doesnt fit with my scheme. So can I do this? m_pParent->SendMessage(UDM_SOMETHING, this, ndummy) ? Thanks

      V Offline
      V Offline
      valikac
      wrote on last edited by
      #2

      One solution is GetParent(). Another solution is AfxGetMainWnd(). Kuphryn

      N 1 Reply Last reply
      0
      • V valikac

        One solution is GetParent(). Another solution is AfxGetMainWnd(). Kuphryn

        N Offline
        N Offline
        nss
        wrote on last edited by
        #3

        Cant do those. I am unable to include my view.h file into the cdialog.h file due to deeply entrenched circular includes... So is SendMessage a bad idea?

        D 1 Reply Last reply
        0
        • N nss

          Cant do those. I am unable to include my view.h file into the cdialog.h file due to deeply entrenched circular includes... So is SendMessage a bad idea?

          D Offline
          D Offline
          Dave Bryant
          wrote on last edited by
          #4

          nss wrote: I am unable to include my view.h file into the cdialog.h file due to deeply entrenched circular includes... But you should be able to include it in the cpp file, and just forward declare the class in the header file. Anyway, SendMessage will work (although it is not really necessary here). You can do something like: GetParent()->SendMessage( dlgPointerMessage, reinterpret_cast( this ) ); And in the parent message map: ON_MESSAGE( dlgPointerMessage, OnDlgPointerMessage ) LRESULT OnDlgPointerMessage(WPARAM wParam, LPARAM lParam) {   CDlg* pDlg = reinterpret_cast<CDlg*>( wParam );   ASSERT_VALID( pDlg );   // Do something   return 0; } Dave http://www.cloudsofheaven.org

          N 1 Reply Last reply
          0
          • D Dave Bryant

            nss wrote: I am unable to include my view.h file into the cdialog.h file due to deeply entrenched circular includes... But you should be able to include it in the cpp file, and just forward declare the class in the header file. Anyway, SendMessage will work (although it is not really necessary here). You can do something like: GetParent()->SendMessage( dlgPointerMessage, reinterpret_cast( this ) ); And in the parent message map: ON_MESSAGE( dlgPointerMessage, OnDlgPointerMessage ) LRESULT OnDlgPointerMessage(WPARAM wParam, LPARAM lParam) {   CDlg* pDlg = reinterpret_cast<CDlg*>( wParam );   ASSERT_VALID( pDlg );   // Do something   return 0; } Dave http://www.cloudsofheaven.org

            N Offline
            N Offline
            nss
            wrote on last edited by
            #5

            Terrific! Many thanks. I also wonder if GetParent()->RunParentFunction() would work.....I will try it. Apprecite your help greatly! I didnt know about the reinterpret_cast....

            D 1 Reply Last reply
            0
            • N nss

              Terrific! Many thanks. I also wonder if GetParent()->RunParentFunction() would work.....I will try it. Apprecite your help greatly! I didnt know about the reinterpret_cast....

              D Offline
              D Offline
              Dave Bryant
              wrote on last edited by
              #6

              It won't directly because GetParent() returns a CWnd pointer. But if you know exactly what type it is, you can cast it and then call your function. static_cast( GetParent() )->RunParentFunction(); Dave http://www.cloudsofheaven.org

              D 1 Reply Last reply
              0
              • D Dave Bryant

                It won't directly because GetParent() returns a CWnd pointer. But if you know exactly what type it is, you can cast it and then call your function. static_cast( GetParent() )->RunParentFunction(); Dave http://www.cloudsofheaven.org

                D Offline
                D Offline
                Dave Bryant
                wrote on last edited by
                #7

                Annoying html tags - i meant: static_cast<CParentClass*>( GetParent() )->RunParentFunction(); Dave http://www.cloudsofheaven.org

                N 1 Reply Last reply
                0
                • D Dave Bryant

                  Annoying html tags - i meant: static_cast<CParentClass*>( GetParent() )->RunParentFunction(); Dave http://www.cloudsofheaven.org

                  N Offline
                  N Offline
                  ns
                  wrote on last edited by
                  #8

                  IT works!! The only thing is that I think in your earliest post with the reinterpret_cast, the <> were missing so I guessed you meant: m_pParent->SendMessage(MSGE, ndummy, reinterporet_cast<UNIT>(this)); I did this by deducing it might be what you meant and its seems fine. Is this indeed what you intended I should do? Your post says interpret_cast (this) but it wouldnt compile that way--- not until I put in the type to cast to..... So is that okay or did you mean something else? Thanks! Appreciate your help, ns

                  D 1 Reply Last reply
                  0
                  • N ns

                    IT works!! The only thing is that I think in your earliest post with the reinterpret_cast, the <> were missing so I guessed you meant: m_pParent->SendMessage(MSGE, ndummy, reinterporet_cast<UNIT>(this)); I did this by deducing it might be what you meant and its seems fine. Is this indeed what you intended I should do? Your post says interpret_cast (this) but it wouldnt compile that way--- not until I put in the type to cast to..... So is that okay or did you mean something else? Thanks! Appreciate your help, ns

                    D Offline
                    D Offline
                    Dave Bryant
                    wrote on last edited by
                    #9

                    I meant to put in the angle brackets, but i forgot that CodeProject interprets them as HTML, so they got gobbled up... Dave http://www.cloudsofheaven.org

                    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