locked
Make Window show above Windows 8 Store Apps RRS feed

  • Question

  • I am trying to make an app to display notifications which can display above windows store apps...it seems "Raptr" can do this as it shows the notification at the bottom right of the screen sometimes...

    How can I do the same thing for my app?  I can use "TopMost" property to make things show above other apps on the desktop, play a sound and bring up the notification, but my app fails to show it above the start menu and windows 8 apps...

    What should I be doing to make this work?

    Thursday, November 21, 2013 8:56 PM

Answers

  • Hi,

    For the usual winforms application, if we want a window in our application to always appear on top of a window of a different application, using WinAPI is a possible way:

    #SetWindowPos function
    http://msdn.microsoft.com/en-us/library/windows/desktop/ms633545(v=vs.85).aspx

    Private Const SWP_NOSIZE As Integer = &H1
        Private Const SWP_NOMOVE As Integer = &H2
    
        Private Shared ReadOnly HWND_TOPMOST As New IntPtr(-1)
        Private Shared ReadOnly HWND_NOTOPMOST As New IntPtr(-2)
    
        Public Sub MakeTopMost()
            SetWindowPos(Me.Handle(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
    End Sub

    For your requirement, as far as I know, this is impossible because Windows Desktop app runs in the environment different from Windows Store app. Windows Store app runs within "Sandbox" immersively.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, November 22, 2013 9:27 AM
  • Anyways, I am trying to do something just like you show and declaring SetWindowPos as so...but I can't get anything to work, even for the desktop...
    Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As IntPtr, ByVal hWndInsertAfter As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal uFlags As UInteger)

    What am I doing wrong?

    Option Strict On
    
    Imports System.Runtime.InteropServices
    
    Public Class Form1
    
        <DllImport("user32.dll", SetLastError:=True)> _
        Private Shared Function SetWindowPos(ByVal hWnd As IntPtr, ByVal hWndInsertAfter As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal uFlags As SetWindowPosFlags) As Boolean
        End Function
    
        Public Enum SpecialWindowHandles
            ' ReSharper disable InconsistentNaming
            ''' <summary>
            '''     Places the window at the bottom of the Z order. If the hWnd parameter identifies a topmost window, the window loses its topmost status and is placed at the bottom of all other windows.
            ''' </summary>
            HWND_TOP = 0
            ''' <summary>
            '''     Places the window above all non-topmost windows (that is, behind all topmost windows). This flag has no effect if the window is already a non-topmost window.
            ''' </summary>
            HWND_BOTTOM = 1
            ''' <summary>
            '''     Places the window at the top of the Z order.
            ''' </summary>
            HWND_TOPMOST = -1
            ''' <summary>
            '''     Places the window above all non-topmost windows. The window maintains its topmost position even when it is deactivated.
            ''' </summary>
            HWND_NOTOPMOST = -2
            ' ReSharper restore InconsistentNaming
        End Enum
    
        <Flags> _
        Public Enum SetWindowPosFlags As UInteger
            ' ReSharper disable InconsistentNaming
    
            ''' <summary>
            '''     If the calling thread and the thread that owns the window are attached to different input queues, the system posts the request to the thread that owns the window. This prevents the calling thread from blocking its execution while other threads process the request.
            ''' </summary>
            SWP_ASYNCWINDOWPOS = &H4000
    
            ''' <summary>
            '''     Prevents generation of the WM_SYNCPAINT message.
            ''' </summary>
            SWP_DEFERERASE = &H2000
    
            ''' <summary>
            '''     Draws a frame (defined in the window's class description) around the window.
            ''' </summary>
            SWP_DRAWFRAME = &H20
    
            ''' <summary>
            '''     Applies new frame styles set using the SetWindowLong function. Sends a WM_NCCALCSIZE message to the window, even if the window's size is not being changed. If this flag is not specified, WM_NCCALCSIZE is sent only when the window's size is being changed.
            ''' </summary>
            SWP_FRAMECHANGED = &H20
    
            ''' <summary>
            '''     Hides the window.
            ''' </summary>
            SWP_HIDEWINDOW = &H80
    
            ''' <summary>
            '''     Does not activate the window. If this flag is not set, the window is activated and moved to the top of either the topmost or non-topmost group (depending on the setting of the hWndInsertAfter parameter).
            ''' </summary>
            SWP_NOACTIVATE = &H10
    
            ''' <summary>
            '''     Discards the entire contents of the client area. If this flag is not specified, the valid contents of the client area are saved and copied back into the client area after the window is sized or repositioned.
            ''' </summary>
            SWP_NOCOPYBITS = &H100
    
            ''' <summary>
            '''     Retains the current position (ignores X and Y parameters).
            ''' </summary>
            SWP_NOMOVE = &H2
    
            ''' <summary>
            '''     Does not change the owner window's position in the Z order.
            ''' </summary>
            SWP_NOOWNERZORDER = &H200
    
            ''' <summary>
            '''     Does not redraw changes. If this flag is set, no repainting of any kind occurs. This applies to the client area, the nonclient area (including the title bar and scroll bars), and any part of the parent window uncovered as a result of the window being moved. When this flag is set, the application must explicitly invalidate or redraw any parts of the window and parent window that need redrawing.
            ''' </summary>
            SWP_NOREDRAW = &H8
    
            ''' <summary>
            '''     Same as the SWP_NOOWNERZORDER flag.
            ''' </summary>
            SWP_NOREPOSITION = &H200
    
            ''' <summary>
            '''     Prevents the window from receiving the WM_WINDOWPOSCHANGING message.
            ''' </summary>
            SWP_NOSENDCHANGING = &H400
    
            ''' <summary>
            '''     Retains the current size (ignores the cx and cy parameters).
            ''' </summary>
            SWP_NOSIZE = &H1
    
            ''' <summary>
            '''     Retains the current Z order (ignores the hWndInsertAfter parameter).
            ''' </summary>
            SWP_NOZORDER = &H4
    
            ''' <summary>
            '''     Displays the window.
            ''' </summary>
            SWP_SHOWWINDOW = &H40
    
            ' ReSharper restore InconsistentNaming
        End Enum
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.CenterToScreen()
            SetWindowPos(Me.Handle, CType(SpecialWindowHandles.HWND_TOPMOST, IntPtr), 500, 200, 0, 0, SetWindowPosFlags.SWP_NOSIZE)
        End Sub
    
    End Class
    


    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.

    Monday, November 25, 2013 2:24 AM

All replies

  • Hi,

    For the usual winforms application, if we want a window in our application to always appear on top of a window of a different application, using WinAPI is a possible way:

    #SetWindowPos function
    http://msdn.microsoft.com/en-us/library/windows/desktop/ms633545(v=vs.85).aspx

    Private Const SWP_NOSIZE As Integer = &H1
        Private Const SWP_NOMOVE As Integer = &H2
    
        Private Shared ReadOnly HWND_TOPMOST As New IntPtr(-1)
        Private Shared ReadOnly HWND_NOTOPMOST As New IntPtr(-2)
    
        Public Sub MakeTopMost()
            SetWindowPos(Me.Handle(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
    End Sub

    For your requirement, as far as I know, this is impossible because Windows Desktop app runs in the environment different from Windows Store app. Windows Store app runs within "Sandbox" immersively.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, November 22, 2013 9:27 AM
  • It shouldn't be impossible, as raptr can show above anything...and it's the desktop that is important for determining what can be done...windows store apps are basically blocked off from accessing the computer and other apps...but I think desktop apps have no limitations or almost none(assuming you run as administrator on the app)
    Monday, November 25, 2013 1:17 AM
  • Anyways, I am trying to do something just like you show and declaring SetWindowPos as so...but I can't get anything to work, even for the desktop...
    Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As IntPtr, ByVal hWndInsertAfter As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal uFlags As UInteger)

    What am I doing wrong?
    Monday, November 25, 2013 1:39 AM
  • I got SetWindowPos to work finally but it made no difference, it shows only above stuff on the desktop...maybe it would be possible to grab a handle for something higher than the desktop though and pass that in?

    Or another api of some sort or something?

    Monday, November 25, 2013 2:02 AM
  • Anyways, I am trying to do something just like you show and declaring SetWindowPos as so...but I can't get anything to work, even for the desktop...
    Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As IntPtr, ByVal hWndInsertAfter As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal uFlags As UInteger)

    What am I doing wrong?

    Option Strict On
    
    Imports System.Runtime.InteropServices
    
    Public Class Form1
    
        <DllImport("user32.dll", SetLastError:=True)> _
        Private Shared Function SetWindowPos(ByVal hWnd As IntPtr, ByVal hWndInsertAfter As IntPtr, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal uFlags As SetWindowPosFlags) As Boolean
        End Function
    
        Public Enum SpecialWindowHandles
            ' ReSharper disable InconsistentNaming
            ''' <summary>
            '''     Places the window at the bottom of the Z order. If the hWnd parameter identifies a topmost window, the window loses its topmost status and is placed at the bottom of all other windows.
            ''' </summary>
            HWND_TOP = 0
            ''' <summary>
            '''     Places the window above all non-topmost windows (that is, behind all topmost windows). This flag has no effect if the window is already a non-topmost window.
            ''' </summary>
            HWND_BOTTOM = 1
            ''' <summary>
            '''     Places the window at the top of the Z order.
            ''' </summary>
            HWND_TOPMOST = -1
            ''' <summary>
            '''     Places the window above all non-topmost windows. The window maintains its topmost position even when it is deactivated.
            ''' </summary>
            HWND_NOTOPMOST = -2
            ' ReSharper restore InconsistentNaming
        End Enum
    
        <Flags> _
        Public Enum SetWindowPosFlags As UInteger
            ' ReSharper disable InconsistentNaming
    
            ''' <summary>
            '''     If the calling thread and the thread that owns the window are attached to different input queues, the system posts the request to the thread that owns the window. This prevents the calling thread from blocking its execution while other threads process the request.
            ''' </summary>
            SWP_ASYNCWINDOWPOS = &H4000
    
            ''' <summary>
            '''     Prevents generation of the WM_SYNCPAINT message.
            ''' </summary>
            SWP_DEFERERASE = &H2000
    
            ''' <summary>
            '''     Draws a frame (defined in the window's class description) around the window.
            ''' </summary>
            SWP_DRAWFRAME = &H20
    
            ''' <summary>
            '''     Applies new frame styles set using the SetWindowLong function. Sends a WM_NCCALCSIZE message to the window, even if the window's size is not being changed. If this flag is not specified, WM_NCCALCSIZE is sent only when the window's size is being changed.
            ''' </summary>
            SWP_FRAMECHANGED = &H20
    
            ''' <summary>
            '''     Hides the window.
            ''' </summary>
            SWP_HIDEWINDOW = &H80
    
            ''' <summary>
            '''     Does not activate the window. If this flag is not set, the window is activated and moved to the top of either the topmost or non-topmost group (depending on the setting of the hWndInsertAfter parameter).
            ''' </summary>
            SWP_NOACTIVATE = &H10
    
            ''' <summary>
            '''     Discards the entire contents of the client area. If this flag is not specified, the valid contents of the client area are saved and copied back into the client area after the window is sized or repositioned.
            ''' </summary>
            SWP_NOCOPYBITS = &H100
    
            ''' <summary>
            '''     Retains the current position (ignores X and Y parameters).
            ''' </summary>
            SWP_NOMOVE = &H2
    
            ''' <summary>
            '''     Does not change the owner window's position in the Z order.
            ''' </summary>
            SWP_NOOWNERZORDER = &H200
    
            ''' <summary>
            '''     Does not redraw changes. If this flag is set, no repainting of any kind occurs. This applies to the client area, the nonclient area (including the title bar and scroll bars), and any part of the parent window uncovered as a result of the window being moved. When this flag is set, the application must explicitly invalidate or redraw any parts of the window and parent window that need redrawing.
            ''' </summary>
            SWP_NOREDRAW = &H8
    
            ''' <summary>
            '''     Same as the SWP_NOOWNERZORDER flag.
            ''' </summary>
            SWP_NOREPOSITION = &H200
    
            ''' <summary>
            '''     Prevents the window from receiving the WM_WINDOWPOSCHANGING message.
            ''' </summary>
            SWP_NOSENDCHANGING = &H400
    
            ''' <summary>
            '''     Retains the current size (ignores the cx and cy parameters).
            ''' </summary>
            SWP_NOSIZE = &H1
    
            ''' <summary>
            '''     Retains the current Z order (ignores the hWndInsertAfter parameter).
            ''' </summary>
            SWP_NOZORDER = &H4
    
            ''' <summary>
            '''     Displays the window.
            ''' </summary>
            SWP_SHOWWINDOW = &H40
    
            ' ReSharper restore InconsistentNaming
        End Enum
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.CenterToScreen()
            SetWindowPos(Me.Handle, CType(SpecialWindowHandles.HWND_TOPMOST, IntPtr), 500, 200, 0, 0, SetWindowPosFlags.SWP_NOSIZE)
        End Sub
    
    End Class
    


    Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.

    Monday, November 25, 2013 2:24 AM