WM_SETTEXT and PostMessage()

This is a discussion on WM_SETTEXT and PostMessage() within the Windows Programming forums, part of the Platform Specific Boards category; OK I have code that I'm trying to make work completely using PostMessage -- this is in a worker thread ...

  1. #1
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571

    WM_SETTEXT and PostMessage()

    OK I have code that I'm trying to make work completely using PostMessage -- this is in a worker thread and it is possible (although exceedingly improbable in this particular case) that using SendMessage() to a window whose procedure is running in my main thread could cause a deadlock.

    My problem is PostMessage with WM_SETTEXT does not work (the text of the control remains unaltered). If I use SendMessage, it works fine.

    It's not a scope issue, the buffer whose address I'm passing remains allocated throughout the life of the program. And if that was the case, I would expect it to change the caption to some kind of garbage -- it's leaving it totally unchanged.

    I suppose I could make a user-defined message, post it to my main window, and have my main thread call ::SetWindowText(), but it seems like it should be possible to make it work with just

    ::PostMessage(param->statusWnd,WM_SETTEXT,(WPARAM)0, (LPARAM) threadbuffer);

    And as mentioned, simply changing PostMessage to SendMessage causes it to work as expected.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

  2. #2
    Cat
    Cat is offline
    Registered User
    Join Date
    May 2003
    Posts
    1,571
    Solved that problem in the manner I mentioned above. Turns out the API tries to protect me against scope issues; PostMessage() always fails with WM_SETTEXT, or any other system-defined message that has a pointer as a parameter.

    Made the user-defined message, and that works.
    Last edited by Cat; 11-22-2005 at 11:21 PM.
    You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21