Keeping form always on top of fullscreen game

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gobblegob
    New Member
    • Dec 2007
    • 133

    Keeping form always on top of fullscreen game

    hi guys ,
    i am making a screen capture program and i want my main form to stay on top
    so the user can take a screen shot of full screen games, i have found lots of stuff to keep it on top of all window but nothing works for full screen games

    Below is 1 i have tried

    Code:
    Private Const HWND_TOPMOST = -1
    Private Const HWND_NOTOPMOST = -2
    Private Const SWP_NOACTIVATE = &H10
    Private Const SWP_SHOWWINDOW = &H40
    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 Sub SetWindowOnTop(f As Form, bAlwaysOnTop As Boolean)
       Dim iFlag As Long
    
       iFlag = IIf(bAlwaysOnTop, HWND_TOPMOST, HWND_NOTOPMOST)
    
       SetWindowPos f.hwnd, iFlag, f.Left / Screen.TwipsPerPixelX, f.Top / Screen.TwipsPerPixelY, _
                    f.Width / Screen.TwipsPerPixelX, f.Height / Screen.TwipsPerPixelY, SWP_NOACTIVATE Or SWP_SHOWWINDOW
    End Sub
    Any help will be appreciated.
    <<<Gobble>>>
  • VBWheaties
    New Member
    • Feb 2008
    • 145

    #2
    Originally posted by gobblegob
    hi guys ,
    i am making a screen capture program and i want my main form to stay on top
    so the user can take a screen shot of full screen games, i have found lots of stuff to keep it on top of all window but nothing works for full screen games

    Below is 1 i have tried

    Code:
    Private Const HWND_TOPMOST = -1
    Private Const HWND_NOTOPMOST = -2
    Private Const SWP_NOACTIVATE = &H10
    Private Const SWP_SHOWWINDOW = &H40
    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 Sub SetWindowOnTop(f As Form, bAlwaysOnTop As Boolean)
       Dim iFlag As Long
    
       iFlag = IIf(bAlwaysOnTop, HWND_TOPMOST, HWND_NOTOPMOST)
    
       SetWindowPos f.hwnd, iFlag, f.Left / Screen.TwipsPerPixelX, f.Top / Screen.TwipsPerPixelY, _
                    f.Width / Screen.TwipsPerPixelX, f.Height / Screen.TwipsPerPixelY, SWP_NOACTIVATE Or SWP_SHOWWINDOW
    End Sub
    Any help will be appreciated.
    <<<Gobble>>>
    add a timer and call setwindowontop. make your interval like 500 (for half a second).
    other apps are probably calling setwindowontop as well, making your form go below theirs.
    however, if you notice it flickering, then that means the other apps are doing the same thing (calling setwindowontop in a timer event).

    Comment

    • Bullitt
      New Member
      • Dec 2007
      • 21

      #3
      Try this, I'm not sure it is working, because this comes from a program that I made a long time ago. It is programmed in vb 6. Let me know if it works.

      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 Const HWND_NOTOPMOST = -2
      
      Private Sub Form_Activate()
          SetOnTop (True)
      End Sub
      
      
      ' Make the form topmost or not.
      Private Sub SetOnTop(Optional ByVal on_top As Boolean = True)
          If on_top Then
              SetWindowPos hwnd, _
                  HWND_TOPMOST, 0, 0, 0, 0, _
                  SWP_NOMOVE + SWP_NOSIZE
          Else
              SetWindowPos hwnd, _
                  HWND_NOTOPMOST, 0, 0, 0, 0, _
                  SWP_NOMOVE + SWP_NOSIZE
          End If
      End Sub

      Comment

      • Killer42
        Recognized Expert Expert
        • Oct 2006
        • 8429

        #4
        I'll be really curious to see whether you manage to do this. But to be honest, I don't think it's possible.

        If by "full screen" you mean maximised, then obviously it's not a problem. But assuming you mean DirectX (or whatever the latest buzzword is) like games such as World of Warcraft use, I really doubt you'll be able to do so. They effectively take over the screen and push aside the usual windowing interface. So whatever you do with your window isn't likely to have much effect, unless you make it full-screen and push the game out of the way.

        Comment

        • gobblegob
          New Member
          • Dec 2007
          • 133

          #5
          Originally posted by VBWheaties
          add a timer and call setwindowontop. make your interval like 500 (for half a second).
          other apps are probably calling setwindowontop as well, making your form go below theirs.
          however, if you notice it flickering, then that means the other apps are doing the same thing (calling setwindowontop in a timer event).

          Good idea VBWheaties but yeah the games seem to be calling the same event because you can see the app flicker in the background.
          I wonder if there is a way of forcing a a game into windowed mode

          Thanks for the posts guys!!
          <<<Gobble>>>

          Comment

          Working...