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. PostMessage problem

PostMessage problem

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
10 Posts 5 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.
  • T Offline
    T Offline
    tataxin
    wrote on last edited by
    #1

    I want to send a string between 2 dialog. So I try to use SendMessage() with WM_COPYDATA message Here is the code in send dialog

    COPYDATASTRUCT cds;
    .... // insert data here

    ::SendMessage(hWnd, WM_COPYDATA, (WPARAM) m_hWnd, (LPARAM) &cds );

    And receive dialog code:

    BEGIN_MESSAGE_MAP(RcvDlg, CDialog)
    .....
    ON_WM_COPYDATA()
    END_MESSAGE_MAP()

    BOOL RcvDlg::OnCopyData(){
    ... // get data here
    }

    It works, but while sending messeage, it locks the send dialog. So I want to change to another way, PostMessage. But I don't know how to implement. I tried to look on the internet, but cannot find what I want. Can anyone help me? Thanks in advance, :)

    N H J T B 5 Replies Last reply
    0
    • T tataxin

      I want to send a string between 2 dialog. So I try to use SendMessage() with WM_COPYDATA message Here is the code in send dialog

      COPYDATASTRUCT cds;
      .... // insert data here

      ::SendMessage(hWnd, WM_COPYDATA, (WPARAM) m_hWnd, (LPARAM) &cds );

      And receive dialog code:

      BEGIN_MESSAGE_MAP(RcvDlg, CDialog)
      .....
      ON_WM_COPYDATA()
      END_MESSAGE_MAP()

      BOOL RcvDlg::OnCopyData(){
      ... // get data here
      }

      It works, but while sending messeage, it locks the send dialog. So I want to change to another way, PostMessage. But I don't know how to implement. I tried to look on the internet, but cannot find what I want. Can anyone help me? Thanks in advance, :)

      N Offline
      N Offline
      Naveen
      wrote on last edited by
      #2

      Don't you see the following comments just below the help of WM_COPYDATA in MSDN[^] _An application must use the SendMessage function to send this message, not the PostMessage function_.

      nave [OpenedFileFinder]

      T 1 Reply Last reply
      0
      • N Naveen

        Don't you see the following comments just below the help of WM_COPYDATA in MSDN[^] _An application must use the SendMessage function to send this message, not the PostMessage function_.

        nave [OpenedFileFinder]

        T Offline
        T Offline
        tataxin
        wrote on last edited by
        #3

        oh, that's why I wasn't success. thank you very much, Naveen. So this means that when dialog A sends a string message to dialog B, it must be locked until receive the reply. Is it correct??

        N 1 Reply Last reply
        0
        • T tataxin

          I want to send a string between 2 dialog. So I try to use SendMessage() with WM_COPYDATA message Here is the code in send dialog

          COPYDATASTRUCT cds;
          .... // insert data here

          ::SendMessage(hWnd, WM_COPYDATA, (WPARAM) m_hWnd, (LPARAM) &cds );

          And receive dialog code:

          BEGIN_MESSAGE_MAP(RcvDlg, CDialog)
          .....
          ON_WM_COPYDATA()
          END_MESSAGE_MAP()

          BOOL RcvDlg::OnCopyData(){
          ... // get data here
          }

          It works, but while sending messeage, it locks the send dialog. So I want to change to another way, PostMessage. But I don't know how to implement. I tried to look on the internet, but cannot find what I want. Can anyone help me? Thanks in advance, :)

          H Offline
          H Offline
          Hamid Taebi
          wrote on last edited by
          #4

          And see Inter-Process Communication using WM_COPYDATA[^].

          1 Reply Last reply
          0
          • T tataxin

            oh, that's why I wasn't success. thank you very much, Naveen. So this means that when dialog A sends a string message to dialog B, it must be locked until receive the reply. Is it correct??

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

            tataxin wrote:

            So this means that when dialog A sends a string message to dialog B, it must be locked until receive the reply. Is it correct??

            Yes. :(

            nave [OpenedFileFinder]

            T 1 Reply Last reply
            0
            • T tataxin

              I want to send a string between 2 dialog. So I try to use SendMessage() with WM_COPYDATA message Here is the code in send dialog

              COPYDATASTRUCT cds;
              .... // insert data here

              ::SendMessage(hWnd, WM_COPYDATA, (WPARAM) m_hWnd, (LPARAM) &cds );

              And receive dialog code:

              BEGIN_MESSAGE_MAP(RcvDlg, CDialog)
              .....
              ON_WM_COPYDATA()
              END_MESSAGE_MAP()

              BOOL RcvDlg::OnCopyData(){
              ... // get data here
              }

              It works, but while sending messeage, it locks the send dialog. So I want to change to another way, PostMessage. But I don't know how to implement. I tried to look on the internet, but cannot find what I want. Can anyone help me? Thanks in advance, :)

              J Offline
              J Offline
              Jijo Raj
              wrote on last edited by
              #6

              tataxin wrote:

              It works, but while sending messeage, it locks the send dialog.

              Since SendMessage is blocking call, it will return only after the WM_COPYMESSAGE handler returns. So don't do any heavy processing in your WM_COPYMESSAGE handler. The best method is copy the data and trigger the processing in another thread so that the handler can return immediately.

              tataxin wrote:

              It works, but while sending messeage, it locks the send dialog. So I want to change to another way, PostMessage.

              You should not use PostMessage for WM_COPYDATA, since its asynchronous. This article might be helpful - http://www.codeguru.com/cpp/w-p/win32/article.php/c1429/[^] Regards, Jijo.

              _____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.

              1 Reply Last reply
              0
              • T tataxin

                I want to send a string between 2 dialog. So I try to use SendMessage() with WM_COPYDATA message Here is the code in send dialog

                COPYDATASTRUCT cds;
                .... // insert data here

                ::SendMessage(hWnd, WM_COPYDATA, (WPARAM) m_hWnd, (LPARAM) &cds );

                And receive dialog code:

                BEGIN_MESSAGE_MAP(RcvDlg, CDialog)
                .....
                ON_WM_COPYDATA()
                END_MESSAGE_MAP()

                BOOL RcvDlg::OnCopyData(){
                ... // get data here
                }

                It works, but while sending messeage, it locks the send dialog. So I want to change to another way, PostMessage. But I don't know how to implement. I tried to look on the internet, but cannot find what I want. Can anyone help me? Thanks in advance, :)

                T Offline
                T Offline
                tataxin
                wrote on last edited by
                #7

                thank you everyone, I will do like that

                1 Reply Last reply
                0
                • T tataxin

                  I want to send a string between 2 dialog. So I try to use SendMessage() with WM_COPYDATA message Here is the code in send dialog

                  COPYDATASTRUCT cds;
                  .... // insert data here

                  ::SendMessage(hWnd, WM_COPYDATA, (WPARAM) m_hWnd, (LPARAM) &cds );

                  And receive dialog code:

                  BEGIN_MESSAGE_MAP(RcvDlg, CDialog)
                  .....
                  ON_WM_COPYDATA()
                  END_MESSAGE_MAP()

                  BOOL RcvDlg::OnCopyData(){
                  ... // get data here
                  }

                  It works, but while sending messeage, it locks the send dialog. So I want to change to another way, PostMessage. But I don't know how to implement. I tried to look on the internet, but cannot find what I want. Can anyone help me? Thanks in advance, :)

                  B Offline
                  B Offline
                  bonkers
                  wrote on last edited by
                  #8

                  You need a class that handles the post msgs....

                  void FACTORY::addWindow(HWND hWnd)
                  {
                  m_Windows.push_back(hWnd);
                  }

                  thus, regsiter all the windows with this class with the function above. (FACTORY::instance().addWindow(m_hWnd);) then, you send these messages to the different classes that registered to this via the PostMessage function....

                  void FACTORY::PostMessage(UINT Msg, WPARAM wParam, LPARAM lParam)
                  {

                  list<HWND>::iterator i;
                  int count = 0;
                  
                  HWND hWnd;
                  for( i = m\_Windows.begin(); i != m\_Windows.end(); i++)
                  {
                    hWnd = \*i;
                  
                    ::PostMessage(hWnd, Msg, wParam, lParam);
                  }	
                  

                  }

                  Then simply post the message and catch it in the class....

                  FACTORY::instance().PostMessage(THE_MESSAGE, (long)VAL1, (long)VAL2);

                  and "catch" it in you PretranslateMessage functions....

                  if(pMsg->message == THE_MESSAGE)

                  then get the vals...

                  int VAL1 = (long)pMsg->wParam;
                  int VAL2 = (long)pMsg->lParam;

                  OR SOMETHING LIKE THAT....

                  modified on Tuesday, June 24, 2008 3:04 AM

                  T 1 Reply Last reply
                  0
                  • N Naveen

                    tataxin wrote:

                    So this means that when dialog A sends a string message to dialog B, it must be locked until receive the reply. Is it correct??

                    Yes. :(

                    nave [OpenedFileFinder]

                    T Offline
                    T Offline
                    tataxin
                    wrote on last edited by
                    #9

                    Oh ha', thank you Naveen

                    1 Reply Last reply
                    0
                    • B bonkers

                      You need a class that handles the post msgs....

                      void FACTORY::addWindow(HWND hWnd)
                      {
                      m_Windows.push_back(hWnd);
                      }

                      thus, regsiter all the windows with this class with the function above. (FACTORY::instance().addWindow(m_hWnd);) then, you send these messages to the different classes that registered to this via the PostMessage function....

                      void FACTORY::PostMessage(UINT Msg, WPARAM wParam, LPARAM lParam)
                      {

                      list<HWND>::iterator i;
                      int count = 0;
                      
                      HWND hWnd;
                      for( i = m\_Windows.begin(); i != m\_Windows.end(); i++)
                      {
                        hWnd = \*i;
                      
                        ::PostMessage(hWnd, Msg, wParam, lParam);
                      }	
                      

                      }

                      Then simply post the message and catch it in the class....

                      FACTORY::instance().PostMessage(THE_MESSAGE, (long)VAL1, (long)VAL2);

                      and "catch" it in you PretranslateMessage functions....

                      if(pMsg->message == THE_MESSAGE)

                      then get the vals...

                      int VAL1 = (long)pMsg->wParam;
                      int VAL2 = (long)pMsg->lParam;

                      OR SOMETHING LIKE THAT....

                      modified on Tuesday, June 24, 2008 3:04 AM

                      T Offline
                      T Offline
                      tataxin
                      wrote on last edited by
                      #10

                      Thank you, bonkers. I just wonder if the receive dialog can get a string message ("Hello" for example) by this way?

                      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