winapigetmessage

Win32 - GetMessage from another thread


According to this thread: Can the HWND from CreateWindow/CreateDialog be GetMessage'd from another thread?, it seems that I can't use GetMessage in another thread using the main thread's HWND.

I'm simply trying to grab the value inside an edittext using GetMessage which is called from a new thread. What are some ways I can do this?


Solution

  • If you want to get the value from an edit control you don't actually use GetMessage at all. GetMessage is for receiving messages, but to get the text from a window you have to send it a message - i.e. you use SendMessage.

    The message to send is WM_GETTEXT (preceeded by WM_GETTEXTLENGTH). Or even easier, use one of the wrapper functions the OS provides for you - in this instance GetWindowText or GetDlgItemText. They work across thread boundaries just fine (and in fact even across process boundaries).