locked
Make for absolute on top, problem when running games in fullscreen RRS feed

  • Question

  • Hi!

    I've created an application that will count down time and when the time is all out it will display a form. This is for my kid so when the time is out he should turn off the computer.

     

    The problem is that the form that i want to display does not display on top any other application. Most noticable is when my son is running a game in fullscreen the form does not pop up in front of the game.

    But this i want!

    Ive tried

    popUpForm.TopMost=true

    popUpForm.BringToFront();

     

    and also found this code:

    [DllImport("user32.dll")]
        static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
    
        static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
        const UInt32 SWP_NOSIZE = 0x0001;
        const UInt32 SWP_NOMOVE = 0x0002;
        const UInt32 SWP_SHOWWINDOW = 0x0040;
    
        // Call this way:
    
        public BlockForm()
        {
          InitializeComponent();
         
        }
    
        private void BlockForm_Load(object sender, EventArgs e)
        {
          SetWindowPos(this.Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
        }
    


    But still the form does not show when running games in fullscreen mode...

    Any suggestions

    Friday, August 5, 2011 10:16 AM

Answers

  • You are running world of warcraft in windowmode there :/.. How about if you change settings for fullscreen (not window fullscreen). Does it still work?

    I remembered that skypes and msn notifications does something like this. How does these guys behave on fullscreen applications?


    If my post is helpful. Please mark it : )

    Thanks for your correction Marcus. That's my mistake.
    After I double checked previous sample, it really didn't work when the game was set as fullscreen. Honestly, if we want to place other windows on the top of fullscreen game, I think this question become more complex. I think we can hook the application and insert itself between application and Dx. This was a good pratice for this topic. http://www.gamedev.net/topic/359794-c-direct3d-hooking-sample/ This was also a good example. http://fraps.com/   But like you said, we can directly kill the game, but the drawback was we should know exactly what the process name of ganme was. Sound also was a good idea if he really plugged in the line. :D Anyway, I think this was out of the topic of technical, wasn't it? I think we can change this thread's type to general discussion to get more good and helpful ideas.

    Best Regards,


    Larcolais Gong[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, August 8, 2011 2:59 PM
  • Yes, as I mentioned in an earlier post you are back to two options; Host the form in the targeted application or write it on top of the application (the one you link for ).

    Both options will require dll injection.  If you want c# you will have to create a c++ .NET runtime loader boostrap. Or else all code have to be in c++. 


    If my post is helpful. Please mark it : )
    Tuesday, August 9, 2011 7:00 AM

All replies

  • You pretty much cant put any window on top of the game screen. The thing is that the game does not only have "TopMost = true", but also its focused when he plays.

    As faar as I know there isnt any smooth way of doing this, you will either have to run your form inside the game process or write your timer on the actual game screen. Both tasks are not very easy handled.


    If my post is helpful. Please mark it : )
    Friday, August 5, 2011 10:19 AM
  • Svensk? ;)

    Well, so any suggestions how i can make the program notify that the time is up?

    Sound? or anything else?

     

    Friday, August 5, 2011 10:22 AM
  • yep, Svenskt :D

    Well I guess sound works nice, probably the easiest solution aswel. You could also kill his game, guess he wouldnt be too happy about that one though :D..
    A popup on left side of the screen would be really neat, but I guess that only brings you back to square one :( 


    If my post is helpful. Please mark it : )
    Friday, August 5, 2011 10:26 AM
  • Well, yes i dont want to be that brutal to just kill the game, whatever he's playing. That would be to harsh....

     

    Damn I thought I had a great solution....

    I guess the problem would be the same with notification message from a notification icon in the system tray...

    Or is it possible to minimize the game from my application?

    Friday, August 5, 2011 10:34 AM
  • Yes I think it would be possible to minimize the game. Like minimize all running windows and put your alert visible.. or something in those lines?

    But I guess that could also be somewhat frustrating for him if he is just about to do something in the game : )
    If my post is helpful. Please mark it : )
    Friday, August 5, 2011 11:06 AM
  • Hello,

    Very interesting question. Like your said, I made a test on my side. It looks OK. The captured window was always shown at very top position. From the document, you can find the following description.

    Places the window above all non-topmost windows. The window maintains its topmost position even when it is deactivated.

    Here's my test code and screenshot. Hope this helps.

    [DllImport("user32.dll", SetLastError = true)]
    
    [return: MarshalAs(UnmanagedType.Bool)]
    
    private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);
    
    [DllImport("user32.dll", SetLastError = true)]
    
    static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
    
    
    
    public const int SWP_HIDEWINDOW = 0x0080;
    
    IntPtr HWND_TOPMOST = new IntPtr(-1);
    
    
    
    private void Form1_Load(object sender, EventArgs e)
    
    {
    
     IntPtr intPtr = new IntPtr(0);
    
     intPtr = FindWindow(null, "dat"); 
    
     if (intPtr != IntPtr.Zero)
    
     {
    
      SetWindowPos(intPtr, HWND_TOPMOST, 0, 0, 0, 0, SWP_HIDEWINDOW);
    
     }
    
    }
    
    

    Screenshot:

    Screenshot

    In addition, I also tested full screen on movie. It also looks OK.

    Best Regards,


    Larcolais Gong[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Sunday, August 7, 2011 5:58 AM
  • You are running world of warcraft in windowmode there :/.. How about if you change settings for fullscreen (not window fullscreen). Does it still work?

    I remembered that skypes and msn notifications does something like this. How does these guys behave on fullscreen applications?


    If my post is helpful. Please mark it : )
    Monday, August 8, 2011 6:52 AM
  • You are running world of warcraft in windowmode there :/.. How about if you change settings for fullscreen (not window fullscreen). Does it still work?

    I remembered that skypes and msn notifications does something like this. How does these guys behave on fullscreen applications?


    If my post is helpful. Please mark it : )

    Thanks for your correction Marcus. That's my mistake.
    After I double checked previous sample, it really didn't work when the game was set as fullscreen. Honestly, if we want to place other windows on the top of fullscreen game, I think this question become more complex. I think we can hook the application and insert itself between application and Dx. This was a good pratice for this topic. http://www.gamedev.net/topic/359794-c-direct3d-hooking-sample/ This was also a good example. http://fraps.com/   But like you said, we can directly kill the game, but the drawback was we should know exactly what the process name of ganme was. Sound also was a good idea if he really plugged in the line. :D Anyway, I think this was out of the topic of technical, wasn't it? I think we can change this thread's type to general discussion to get more good and helpful ideas.

    Best Regards,


    Larcolais Gong[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, August 8, 2011 2:59 PM
  • Yes, as I mentioned in an earlier post you are back to two options; Host the form in the targeted application or write it on top of the application (the one you link for ).

    Both options will require dll injection.  If you want c# you will have to create a c++ .NET runtime loader boostrap. Or else all code have to be in c++. 


    If my post is helpful. Please mark it : )
    Tuesday, August 9, 2011 7:00 AM