Results 1 to 7 of 7

Thread: Always on top

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2000
    Location
    Antrim
    Posts
    80

    Question

    Hi,

    I'm building a one form application to work alongside a SCADA system.

    I need the for to remain on top of this SCADA system at all times (I don't want it to be modal as the users of the SCADA need to be able to perform functions), I just need it to sit on top of this other window.

    Does anyone know how to do this?

    Best Regards,

    Rob Brown.

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    'to make form stay topmost
    
    'put this in a bas module
    '
    Public Declare Function SetWindowPos Lib "user32" _
    (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
    ByVal x As Long, ByVal y As Long, ByVal cx As Long, _
    ByVal cy As Long, ByVal wFlags As Long) As Long
    
    Global Const SWP_NOMOVE = 2
    Global Const SWP_NOSIZE = 1
    Global Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
    Global Const HWND_TOPMOST = -1
    Global Const HWND_NOTOPMOST = -2
    
    '=============================================
    '
    'put this in events click or load or whatever
    'or hardcopy
    'To set Form1 as a TopMost form, do the following:
    
    res& = SetWindowPos (Form1.hWnd, HWND_TOPMOST, _
    0, 0, 0, 0, FLAGS) 
    'if res&=0, there is an error
    
    'To turn off topmost (make the form act normal again):
    
    res& = SetWindowPos (Form1.hWnd, HWND_NOTOPMOST, _
    0, 0, 0, 0, FLAGS)
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    Hyperactive Member
    Join Date
    May 2000
    Posts
    344

    Note:

    Just something to add to that, with some stayontop codes, alt + esc makes it loose priority. If yours does this can be a flaw like ive found out the hard way. To avoid that either set a loop or timer that everytime that form is visible to stayontop.
    -RaY
    VB .Net 2010 (Ultimate)

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    not so much a flaw as an override by windows..
    Alt/tab switches screens...yes this one falls to that as well.
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  5. #5
    Fanatic Member
    Join Date
    Jul 2000
    Location
    Manchester NH
    Posts
    833
    put the ontop statment if the form_activate sub
    Kurt Simons
    [I know I'm a hack but my clients don't!]

  6. #6

    Thread Starter
    Lively Member
    Join Date
    May 2000
    Location
    Antrim
    Posts
    80
    Thanks,

    the code keeps the window on top, however:

    The window is resized and part of it (title bar) is missing (off the top of the screen).

    I've tried playing around with the x,y,cx,cy co-ordinates but it makes no difference.

    Is there some way to set the Z-order without moving or sizing the window?

    Best regards,

    Rob Brown.

  7. #7
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    You might want to look up SetWindowPos in API functions and set your windows in compatible spaces.
    I've used it(don't fully understand it) by putting my app at top 0 left 0 (top right) and then position Notepad directly below it(bottom right)
    Maybe it might apply to your situtation.
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width