I have found that the text window has unique attributes that identify it.
It is the only RichEdit20A class that is visible, has no OleDrop propertirs, and has WS_EX_NOPARENTNOTIFY extended style.
My code in C (sould be easy to port to basic) look like this:
- Code: Select all
static BOOL CALLBACK EnomRoomTextProps(HWND hwnd, LPCTSTR szProp, HANDLE)
{
char atom_name[64];
//OleDropTargetInterface
//OleDropTargetMarshalHwnd
if (is_atom(szProp)) {
ATOM atom = LOWORD(szProp);
if (!GetAtomName(atom, atom_name, sizeof(atom_name)))
return FALSE;
szProp = atom_name;
}
if (!strncmp(szProp, "OleDrop", 7)) {
SetLastError(0);
return FALSE;
}
return TRUE;
}
static BOOL CALLBACK FindRoomTextProc(HWND hwnd, LPARAM lParam)
{
TCHAR str[128];
if (RealGetWindowClass(hwnd, str, sizeof(str)) == 0)
return TRUE;
if (strcmp(str, "RichEdit20A"))
return TRUE;
if (!IsWindowVisible(hwnd))
return TRUE;
if (!EnumProps(hwnd, EnomRoomTextProps))
return TRUE;
if ((GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_NOPARENTNOTIFY) == 0)
return TRUE;
*((HWND *)lParam) = hwnd;
SetLastError(0);
return FALSE;
}
//...
HWND rich20;
if (EnumChildWindows(hwnd, (WNDENUMPROC)FindRoomTextProc,
PtrToLong(&rich20)) ||
GetLastError() != 0) {
// could not find room text
return;
}
// do whatever with rich20 here
Note that "failur" of EnumChildWindows actually indicats sucess (combined with GetLastError() return of 0)
For those who have diffuculties reading C:
hwnd is the room HWND, EnumChildWindows get the address of rich20 as lParam to FindRoomTextProc callback.
When the callback identify the window, it puts the hwind in the addres that was sent to it, set last error to zero, and returns false (zero in basic), which cuase the enumeration to "fail".
If the enumeration succeeds it means it hasn't found the room text.