Getting a window id

I need to send an event (XSendEvent) from one application to another on Red Hat Enterprise Linux 4.0, using Motif 1.2 - (I know this is not OpenMotif but I figure the answer should be the same or very similar).

In order to do this I need my application to get the top window id of the other app. Apparently the other app should be able to register itself with the root window and my app should be able to read the id for that app from the root window.

a) Is this true
b) If so, how does the other app register itself with the root window and how do I read the window id from root window?