We help IT Professionals succeed at work.

bring form to top

negone
negone asked
on
Medium Priority
522 Views
Last Modified: 2008-02-01
I have a COM server that attempts a program login.  However, the login is a modal form, which appears behind the COM client.  How can I force the form above all other forms?
Comment
Watch Question

Commented:
Is the password dialog created from a standard Delphi form?  If som then set the form's Formstyle property to fsStayOnTop.  

You should be aware that Delphi warns against setting this property at runtime - it should be set only at design time.  

If you don't have access to the form's properties directly, it is possible to find the form's handle (FindWindow) and sending it a message to change its Z-order (SetWindowPOS), but it may be difficult or at least clumsy to determine (timers, loops, etc.) when to look for the handle.

SetWindowPos(

    HWND hWnd,     // handle of window
    HWND hWndInsertAfter,     // placement-order handle
    int X,     // horizontal position
    int Y,     // vertical position
    int cx,     // width
    int cy,     // height
    UINT uFlags      // window-positioning flags
   );    
 

Commented:
Also note that earlier v's of delphi (D3 & prior, i believe) wouldn't keep topMost forms topmost & you had to put a line like this in your application.OnDeactivate handler:

application.restoreTopMosts;

GL
Mike
Hi

Try this API call in your form's OnDeactivate event (or whenever you think it's necessary):

 ShowWindow(Form1.Handle, SW_SHOW);



  Filipe Correia

Explore More ContentExplore courses, solutions, and other research materials related to this topic.