Thread: WM_SETTEXT and PostMessage()

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    1,619

    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
    Registered User
    Join Date
    May 2003
    Posts
    1,619
    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-23-2005 at 12:21 AM.
    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