haajunky.blogg.se

Delphi getwindowtext from another process
Delphi getwindowtext from another process












delphi getwindowtext from another process

In any case, I wrote a little program, GWTTest, that illustrates the point. I suspect the friendly Redmondtonians had to accommodate some naughty legacy apps in the move from fake to real multitasking. The real question is: why didn't the Redmondtonians simply make GetWindowText do the right thing? That is, why doesn't GetWindowText do a SendMessage(WM_GETTEXT) if the window is in the current process and a SendMessageTimeout if it's in another? Good question. Amazing, all the pesky things to consider in a multitasking world! So where's the protection? Ah, but you don't have to use SendMessage! You can use SendMessageTimeout, which is guaranteed to return even if you call into a dead process. Of course a cynical programmer might counter: what good is that? GetWindowText doesn't get the text, so if you want the text you have to SendMessage WM_GETTEXT, which can hang. In other words, you can get the caption from the main window of another process, but not the text of a child window such as an edit control, combobox, or button within it.Īnd why is that? Why is this behavior "by design?" Because, the documentation further explains, "it allows applications to call GetWindowText without hanging if the process that owns the target window is hung." Preeeetty clever, eh? GetWindowText affords protection from calling into never-never land. If the window does not have a caption, the return value is a null string. If the target window is owned by another process and has a caption, GetWindowText retrieves the window caption text.

delphi getwindowtext from another process

If the window belongs to a different process, GetWindowText does something else. GetWindowText only sends WM_GETTEXT if the window belongs to the current process. GetWindowText doesn't just send WM_GETTEXT. Some of you are no doubt wondering: hey, wait a minute-if that works, why doesn't GetWindowText work? After all, GetWindowText just sends WM_GETTEXT, right? Wrong.

delphi getwindowtext from another process

CWnd* pWnd = GetOtherAppWindow() TCHAR buf pWnd->SendMessage(WM_GETTEXT, sizeof(buf)/sizeof(TCHAR), (LPARAM)(void*)buf) If you're programming in C, you'd naturally use the HWND instead of CWnd. To get the text of a window in another process, all you have to do is send WM_GETTEXT directly.

delphi getwindowtext from another process

Oh, I love softball questions they make me look so smart.














Delphi getwindowtext from another process