1

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?

Community
  • 1
  • 1
ShrimpCrackers
  • 4,388
  • 17
  • 50
  • 76

1 Answers1

1

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).

Jonathan Potter
  • 36,172
  • 4
  • 64
  • 79
  • "Or even easier, use one of the wrapper functions the OS provides for you - in this instance GetWindowText or GetDlgItemText" - highly controversial advice: for example, after version 6 Spy++ its authors even replaced GetWindowText on SendMessage (WM_GETTEXT)... – kero Jul 02 '13 at 23:42
  • Citation? GetWindowText just sends WM_GETTEXT for threads in the same process, there's no effective difference. Cross-process it's even better as it won't hang if the target process is non-responsive whereas sending the message yourself would. – Jonathan Potter Jul 02 '13 at 23:46
  • 1
    Please - citation: "Copies the text of the specified window's title bar (if it has one) into a buffer. If the specified window is a control, the text of the control is copied. However, GetWindowText cannot retrieve the text of a control in another application". (GetWindowText, MSDN) – kero Jul 02 '13 at 23:50