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. SendMessage to another dialog window

SendMessage to another dialog window

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
9 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.
  • G Offline
    G Offline
    georgiek50
    wrote on last edited by
    #1

    I'm having a problem sending a message from one window to another in my (Win32) application. A little background: 1) It's a dialog based app 2) It consists of a tab control and several child window dialogs I want to send the text of an edit control from one tab/child window to another tab/child window's list box using: SendMessage(hwnd, LB_ADDSTRING, 0, (LPARAM) szString); However I can not get them to communicate. I can't figure this out (never attempted it before). I have a single function handling all messages of each child window of the tab control. Everything works great as long as I'm updating the window/tab in view. Can anyone point me in the right direction? Thanks in advance.

    W realJSOPR P 3 Replies Last reply
    0
    • G georgiek50

      I'm having a problem sending a message from one window to another in my (Win32) application. A little background: 1) It's a dialog based app 2) It consists of a tab control and several child window dialogs I want to send the text of an edit control from one tab/child window to another tab/child window's list box using: SendMessage(hwnd, LB_ADDSTRING, 0, (LPARAM) szString); However I can not get them to communicate. I can't figure this out (never attempted it before). I have a single function handling all messages of each child window of the tab control. Everything works great as long as I'm updating the window/tab in view. Can anyone point me in the right direction? Thanks in advance.

      W Offline
      W Offline
      Waldermort
      wrote on last edited by
      #2

      You cannot do that with a string. The string is in the memory of your process, all that you are sending is the address, which the second process will not be able to read. To send a string send the WM_COPYDATA message instead. But this will not allow you to add it to a listbox like you are trying.

      P 1 Reply Last reply
      0
      • G georgiek50

        I'm having a problem sending a message from one window to another in my (Win32) application. A little background: 1) It's a dialog based app 2) It consists of a tab control and several child window dialogs I want to send the text of an edit control from one tab/child window to another tab/child window's list box using: SendMessage(hwnd, LB_ADDSTRING, 0, (LPARAM) szString); However I can not get them to communicate. I can't figure this out (never attempted it before). I have a single function handling all messages of each child window of the tab control. Everything works great as long as I'm updating the window/tab in view. Can anyone point me in the right direction? Thanks in advance.

        realJSOPR Offline
        realJSOPR Offline
        realJSOP
        wrote on last edited by
        #3

        Make sure your message handler is prototyped as follows: in the header file:

        afx_msg LRESULT OnHandleMyMessage(WPARAM wParam, LPARAM lParam);

        and in the cpp file:

        BEGIN_MESSAGE_MAP(CMyClass, CDialog)
        ON_MESSAGE(LB_ADDSTRING, OnHandleMyMessage)
        END_MESSAGE_MAP()

        LRESULT CMyClass::OnHandleMyMessage(WPARAM wParam, LPARAM lParam)
        {
        // your code goes here

        return 1L;
        

        }

        Also, you should call PostMessage unless you need to wait for the message handler to return.

        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
        -----
        "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

        G 1 Reply Last reply
        0
        • realJSOPR realJSOP

          Make sure your message handler is prototyped as follows: in the header file:

          afx_msg LRESULT OnHandleMyMessage(WPARAM wParam, LPARAM lParam);

          and in the cpp file:

          BEGIN_MESSAGE_MAP(CMyClass, CDialog)
          ON_MESSAGE(LB_ADDSTRING, OnHandleMyMessage)
          END_MESSAGE_MAP()

          LRESULT CMyClass::OnHandleMyMessage(WPARAM wParam, LPARAM lParam)
          {
          // your code goes here

          return 1L;
          

          }

          Also, you should call PostMessage unless you need to wait for the message handler to return.

          "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
          -----
          "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

          G Offline
          G Offline
          georgiek50
          wrote on last edited by
          #4

          Thanks for the reply. I'm quite new at coding and can't quite decipher what you provided, but are you suggesting I subclass the control?

          W 1 Reply Last reply
          0
          • G georgiek50

            Thanks for the reply. I'm quite new at coding and can't quite decipher what you provided, but are you suggesting I subclass the control?

            W Offline
            W Offline
            Waldermort
            wrote on last edited by
            #5

            He means, make sure you have correctly configured the message handler. But this is only valid if you are using MFC.

            G 1 Reply Last reply
            0
            • W Waldermort

              He means, make sure you have correctly configured the message handler. But this is only valid if you are using MFC.

              G Offline
              G Offline
              georgiek50
              wrote on last edited by
              #6

              I see. I'm using Win32. Is there a workaround for this?

              M 1 Reply Last reply
              0
              • W Waldermort

                You cannot do that with a string. The string is in the memory of your process, all that you are sending is the address, which the second process will not be able to read. To send a string send the WM_COPYDATA message instead. But this will not allow you to add it to a listbox like you are trying.

                P Offline
                P Offline
                prasad_som
                wrote on last edited by
                #7

                He doesn't mention two windows from two processes here.

                Prasad Notifier using ATL | Operator new[],delete[][^]

                1 Reply Last reply
                0
                • G georgiek50

                  I'm having a problem sending a message from one window to another in my (Win32) application. A little background: 1) It's a dialog based app 2) It consists of a tab control and several child window dialogs I want to send the text of an edit control from one tab/child window to another tab/child window's list box using: SendMessage(hwnd, LB_ADDSTRING, 0, (LPARAM) szString); However I can not get them to communicate. I can't figure this out (never attempted it before). I have a single function handling all messages of each child window of the tab control. Everything works great as long as I'm updating the window/tab in view. Can anyone point me in the right direction? Thanks in advance.

                  P Offline
                  P Offline
                  prasad_som
                  wrote on last edited by
                  #8

                  georgiek50 wrote:

                  SendMessage(hwnd, LB_ADDSTRING, 0, (LPARAM) szString);

                  What value does this function returns ? I assume hwnd is handle to target list box.

                  Prasad Notifier using ATL | Operator new[],delete[][^]

                  1 Reply Last reply
                  0
                  • G georgiek50

                    I see. I'm using Win32. Is there a workaround for this?

                    M Offline
                    M Offline
                    malaugh
                    wrote on last edited by
                    #9

                    Not familiar with Win32, If you can, add something like the following: BOOL MyDialog::PreTranslateMessage(MSG* pMsg) { // catch any WM_USER messages if (pMsg->message == WM_USER) { // see if it's your message if (pMsg->wParam == LB_ADDSTRING) { ... process the message .... .....

                    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