[HELP]How to determine whether a module exists?

I want to make some dynamic dialogs in my program. Sometimes they are shown and sometimes they are hidden or destroyed, while other widget may change resource by their existence.How to fulfill that function? I try to use PtWidgetIsRealized with failure when the dialogs are destroyed.
Can you help me how to determine the status of these dynamic dialogs? Thx a lot in advance!