Results 1 to 6 of 6

Thread: Topmost window

  1. #1

    Thread Starter
    Hyperactive Member marnitzg's Avatar
    Join Date
    Oct 2000
    Location
    South Africa
    Posts
    372
    Ok. When my prog is minimized it sits in the taktray. When a user clicks the icon it restores to vbnormal. Now, I need this window to be seen (As in on top). My problem is, for some reason the forcewindowontop function isn't working?

    Code:
    Declare Function SetForegroundWindow Lib "user32.dll" (ByVal hwnd As Long) As Long
    Why?


  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    To make your Form TopMost use the SetWindowPos API with the HWND_TOPMOST constant, i.e.
    Code:
    Private 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
    Private Const SWP_NOMOVE = &H2
    Private Const SWP_NOSIZE = &H1
    Private Const HWND_TOPMOST = -1
    
    Private Sub Form_Activate()
        Call SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
    End Sub

  3. #3

    Thread Starter
    Hyperactive Member marnitzg's Avatar
    Join Date
    Oct 2000
    Location
    South Africa
    Posts
    372
    Tried that one already, also didn't work

  4. #4
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    It does work, but won't appear to work when run from within the VB IDE environment, compile the EXE and it's fine.

  5. #5

    Thread Starter
    Hyperactive Member marnitzg's Avatar
    Join Date
    Oct 2000
    Location
    South Africa
    Posts
    372
    I know, and have compiled. Still didn't work. Maybe I should say that I am running Win 2000 Server. It worked fine before on 98 and NT!

  6. #6

    Thread Starter
    Hyperactive Member marnitzg's Avatar
    Join Date
    Oct 2000
    Location
    South Africa
    Posts
    372
    Ok now this is weird. If I call both api functions the window comes to the top (even in the IDE) but not if I only call one.

    Can anyone explain or should I just blame this on Microsoft?

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