Researching my books and can't find an answer....

When I call a dialog from a menu selection, it appears in front of the main window, but when I call it directly from a function, it appears behind the main window.

The question is, how to insure it will appear in front of the main window when called from a function?