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. Post Message.

Post Message.

Scheduled Pinned Locked Moved C / C++ / MFC
questioncomtools
4 Posts 3 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.
  • J Offline
    J Offline
    John Uhlenbrock
    wrote on last edited by
    #1

    I asked this same question for SendMessage HERE once before. However, it appears as though the solution for SendMessage does not work for PostMessage. I want to pass a CString as one of the parameters of PostMessage. How is this done?

    M M 3 Replies Last reply
    0
    • J John Uhlenbrock

      I asked this same question for SendMessage HERE once before. However, it appears as though the solution for SendMessage does not work for PostMessage. I want to pass a CString as one of the parameters of PostMessage. How is this done?

      M Offline
      M Offline
      Michael Dunn
      wrote on last edited by
      #2

      I want to pass a CString as one of the parameters of PostMessage. How is this done? Well, you can pass a pointer to a CString, however this will work only if the receiver of the message to is in the same process as the sender, otherwise the pointer will be meaningless. You also have to make sure that the CString object exists long enough for the receiver to use it. Since posted messages are handled asynchronously, you'll need to arrange this part yourself. --Mike-- http://home.inreach.com/mdunn/ You are the weakest link, GOODBYE!

      1 Reply Last reply
      0
      • J John Uhlenbrock

        I asked this same question for SendMessage HERE once before. However, it appears as though the solution for SendMessage does not work for PostMessage. I want to pass a CString as one of the parameters of PostMessage. How is this done?

        M Offline
        M Offline
        Matt Gullett
        wrote on last edited by
        #3

        Assuming the target window is in the same process, you can send a CString via PostMessage like this:

        void SendTextToWindow(HWND hwndTarget, UINT uiMessage, LPCSTR lpszText);
        {
        CString* pText = new CString;
        (*pText) = lpszText;

         ::PostMessage(hwndTarget, uiMessage, (WPARAM)pText, 0);
        

        }

        Then, in the message handler for uiMessage,

        LRESULT OnSomeMessage(WPARAM wParam, LPARAM lParam)
        {
        CString* pText = (CString*)wParam;
        ASSERT(pText);

         // do something with pText
        
         delete pText;
        
         return 0;
        

        }

        I have used this, but I do not recommend it because there is a potential that the message could not make it to the target window and thus the CString never be destroyed. Also, this only works if the target window is in the same process. Ultimately, if you really need to do this often, I would recommend creating a manager class (something line CStringMessageManager), and have it be responspilble for deleting CString objects created and passed via PostMessage.

        1 Reply Last reply
        0
        • J John Uhlenbrock

          I asked this same question for SendMessage HERE once before. However, it appears as though the solution for SendMessage does not work for PostMessage. I want to pass a CString as one of the parameters of PostMessage. How is this done?

          M Offline
          M Offline
          Matt Gullett
          wrote on last edited by
          #4

          I went ahead and posted the code I use to deal with this situation. You can find it at http://www.codeproject.com/useritems/sendcstring.asp

          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