CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Andrew Truckle Guest

    [RESOLVED] Posting Messages

    I have a thread which sends user defined messages to another window.

    How can I get it to send a text string?

    For example, the window which receives a certain message has a static text control which I would like to update.

    At the moment I have derived a series of CONSTANTS and sent those. Then the message handler sets the text according to which CONSTANT was received.

    There must be a more flexible approach.

    I hope someone can help.




  2. #2
    Guest

    Re: Posting Messages

    In the thread you can send the message using something like:

    CString sendstring = _T("Send this text");
    char *lpszPostedBytes = (char *) LocalAlloc(LPTR,sendstring.Length() + 1);
    if (lpszPostedBytes != NULL)
    {
    strcpy(lpszPostedBytes, (LPCTSTR) sendstring);
    PostMessage(myWnd, YOUR_MESSAGE, (LPARAM) lpszPostedBytes, 0L);
    }

    Then release the memory when the message been processed using:
    LocalFree();



  3. #3
    Join Date
    Apr 1999
    Posts
    65

    Re: Posting Messages

    I HAVE done this before...
    I did Send Message() ;
    I didnt find the necessity for any user defined messages
    U can instead adhere to WM_SETTEXT
    It worked perfectly



  4. #4
    Guest

    Re: Posting Messages

    SendMessage to main app from a thread is DANGEROUS. It can cuase dead locks. Don't do it!


  5. #5
    Andrew Truckle Guest

    Re: Posting Messages

    Hi, thanks for your sample code.

    I've added it in, but have one problem. How to I do when the message has been processed so that I can call LocalFree()?


  6. #6
    Join Date
    May 1999
    Location
    Sydney, Australia
    Posts
    420

    Re: Posting Messages

    LocalFree is called on the receiving side

    Sally


  7. #7
    Andrew Truckle Guest

    Re: Posting Messages

    Hi Sally

    I've tried putting LocalFree(var) into the message handler function, but it doesn't like the parameter being passed which is now a LPARAM.

    Any ideas?


  8. #8
    Join Date
    Apr 1999
    Location
    Bruton, Somerset, England
    Posts
    47

    Re: Posting Messages

    LocalFree((char*) var)?


  9. #9
    Guest

    Re: Posting Messages

    Sure, for some strange reason I couldn't log in today.....

    you have to cast the LPARAM to the correct datatype to be freed

    Sally


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured