Use the Motif XmAddWMProtocolCallback() function to establish a callback procedure to be called when the application receives a WM_SAVE_YOURSELF client message:
XmAddWMProtocolCallback(toplevel, XaWmSaveYourself, SaveYourselfProc, toplevel);