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. C / C++ / MFC
  4. howto Post Message

howto Post Message

Scheduled Pinned Locked Moved C / C++ / MFC
questionannouncement
8 Posts 6 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.
  • A Offline
    A Offline
    aei_totten
    wrote on last edited by
    #1

    okay working with a dialog app. I have a little worker thread doing stuff and then I want to update the dialog. So here is what I am doing... #define UWM_UPDATEGRAPH (WM_APP + 1) //{{AFX_MSG_MAP(CVC_ExampleDlg) ... ON_MESSAGE(UWM_UPDATEGRAPH, OnUpdateGraph) ... //}}AFX_MSG_MAP // I ignore both params LRESULT CVC_ExampleDlg::OnUpdateGraph(WPARAM, LPARAM) {...} now to post this message I thought I wanted to write PostMessage(UWM_UPDATEGRAPH, 0, 0); however it is asking for an additional parameter of the HWND. So here is my question, did I define my message wrong or do how is the best way to get the HWND

    C C K T 4 Replies Last reply
    0
    • A aei_totten

      okay working with a dialog app. I have a little worker thread doing stuff and then I want to update the dialog. So here is what I am doing... #define UWM_UPDATEGRAPH (WM_APP + 1) //{{AFX_MSG_MAP(CVC_ExampleDlg) ... ON_MESSAGE(UWM_UPDATEGRAPH, OnUpdateGraph) ... //}}AFX_MSG_MAP // I ignore both params LRESULT CVC_ExampleDlg::OnUpdateGraph(WPARAM, LPARAM) {...} now to post this message I thought I wanted to write PostMessage(UWM_UPDATEGRAPH, 0, 0); however it is asking for an additional parameter of the HWND. So here is my question, did I define my message wrong or do how is the best way to get the HWND

      C Offline
      C Offline
      Cedric Moonen
      wrote on last edited by
      #2

      The first argument to PostMessage should be the handle of the window to which you want to post the message. You can retrieve it from the CDialog by calling GetSafeHwnd() on it.

      Cédric Moonen Software developer
      Charting control [v1.4] OpenGL game tutorial in C++

      S 1 Reply Last reply
      0
      • A aei_totten

        okay working with a dialog app. I have a little worker thread doing stuff and then I want to update the dialog. So here is what I am doing... #define UWM_UPDATEGRAPH (WM_APP + 1) //{{AFX_MSG_MAP(CVC_ExampleDlg) ... ON_MESSAGE(UWM_UPDATEGRAPH, OnUpdateGraph) ... //}}AFX_MSG_MAP // I ignore both params LRESULT CVC_ExampleDlg::OnUpdateGraph(WPARAM, LPARAM) {...} now to post this message I thought I wanted to write PostMessage(UWM_UPDATEGRAPH, 0, 0); however it is asking for an additional parameter of the HWND. So here is my question, did I define my message wrong or do how is the best way to get the HWND

        C Offline
        C Offline
        CPallini
        wrote on last edited by
        #3

        PostMessage function [^] takes four parameters, indeed. I.e. did you realize the thread procedure is NOT a method (a instance one) of your dialog class? :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

        1 Reply Last reply
        0
        • A aei_totten

          okay working with a dialog app. I have a little worker thread doing stuff and then I want to update the dialog. So here is what I am doing... #define UWM_UPDATEGRAPH (WM_APP + 1) //{{AFX_MSG_MAP(CVC_ExampleDlg) ... ON_MESSAGE(UWM_UPDATEGRAPH, OnUpdateGraph) ... //}}AFX_MSG_MAP // I ignore both params LRESULT CVC_ExampleDlg::OnUpdateGraph(WPARAM, LPARAM) {...} now to post this message I thought I wanted to write PostMessage(UWM_UPDATEGRAPH, 0, 0); however it is asking for an additional parameter of the HWND. So here is my question, did I define my message wrong or do how is the best way to get the HWND

          K Offline
          K Offline
          krmed
          wrote on last edited by
          #4

          If you're starting your thread from within the dialog you want to update, pass the hwnd of the dialog as the LPARAM if you use MFC (AfxBeginThread) - then you can use that in your PostMessage. If you don't use MFC, you can pass it as arglist or lpParmeter depending on how you start your thread. You can use GetSafeHwnd() in your dialog to get the hWnd to pass. Inside the thread, cast that parameter to an hWnd and you've got it. Hope that helps.

          Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

          1 Reply Last reply
          0
          • C Cedric Moonen

            The first argument to PostMessage should be the handle of the window to which you want to post the message. You can retrieve it from the CDialog by calling GetSafeHwnd() on it.

            Cédric Moonen Software developer
            Charting control [v1.4] OpenGL game tutorial in C++

            S Offline
            S Offline
            Stephen Hewitt
            wrote on last edited by
            #5

            Cedric Moonen wrote:

            The first argument to PostMessage should be the handle of the window to which you want to post the message. You can retrieve it from the CDialog by calling GetSafeHwnd() on it.

            CDialog is derived from CWnd which has a PostMessage method with the following signature:

            BOOL CWnd::PostMessage(UINT message, WPARAM wParam, LPARAM lParam)

            Depending on the specifics calling Win32's ::PostMessage function may not be the best way to go about things.

            Steve

            C 1 Reply Last reply
            0
            • S Stephen Hewitt

              Cedric Moonen wrote:

              The first argument to PostMessage should be the handle of the window to which you want to post the message. You can retrieve it from the CDialog by calling GetSafeHwnd() on it.

              CDialog is derived from CWnd which has a PostMessage method with the following signature:

              BOOL CWnd::PostMessage(UINT message, WPARAM wParam, LPARAM lParam)

              Depending on the specifics calling Win32's ::PostMessage function may not be the best way to go about things.

              Steve

              C Offline
              C Offline
              Cedric Moonen
              wrote on last edited by
              #6

              Stephen Hewitt wrote:

              Depending on the specifics calling Win32's ::PostMessage function may not be the best way to go about things.

              What do you mean ? If the thread runs outside the dialog class, you have to use ::PostMessage to deliver the message to the correct window. I don't see what you mean in fact, could you elaborate ?

              Cédric Moonen Software developer
              Charting control [v1.4] OpenGL game tutorial in C++

              S 1 Reply Last reply
              0
              • C Cedric Moonen

                Stephen Hewitt wrote:

                Depending on the specifics calling Win32's ::PostMessage function may not be the best way to go about things.

                What do you mean ? If the thread runs outside the dialog class, you have to use ::PostMessage to deliver the message to the correct window. I don't see what you mean in fact, could you elaborate ?

                Cédric Moonen Software developer
                Charting control [v1.4] OpenGL game tutorial in C++

                S Offline
                S Offline
                Stephen Hewitt
                wrote on last edited by
                #7

                He’s using MFC and wants to post a message to a CDialog derived class. If the worker thread has access to this class then he can use CDialog::PostMessage. An example:

                CDialog theDialog;
                 
                void CalledFromOtherThread()
                {
                theDialog.PostMessage(WM_APP, 0, 0);
                }

                Steve

                1 Reply Last reply
                0
                • A aei_totten

                  okay working with a dialog app. I have a little worker thread doing stuff and then I want to update the dialog. So here is what I am doing... #define UWM_UPDATEGRAPH (WM_APP + 1) //{{AFX_MSG_MAP(CVC_ExampleDlg) ... ON_MESSAGE(UWM_UPDATEGRAPH, OnUpdateGraph) ... //}}AFX_MSG_MAP // I ignore both params LRESULT CVC_ExampleDlg::OnUpdateGraph(WPARAM, LPARAM) {...} now to post this message I thought I wanted to write PostMessage(UWM_UPDATEGRAPH, 0, 0); however it is asking for an additional parameter of the HWND. So here is my question, did I define my message wrong or do how is the best way to get the HWND

                  T Offline
                  T Offline
                  ThatsAlok
                  wrote on last edited by
                  #8

                  you can also you the application object memeber variable m_hWnd!

                  "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
                  Never mind - my own stupidity is the source of every "problem" - Mixture

                  cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You/xml>

                  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