c# - WPF topmost option makes fullscreen app to escape -


i used small window tooltip shows "now playing" info in application. sure set topmost = "true" in window declaration , when new song starts play tooltip.show(). problem when have fullscreen application in focus (game example), .show() call makes fullscreen window became non-fullscreen, windowed, border , top bar (as if press alt + enter) , looks loses focus also. restore fullscreen need click in window focus , press alt-enter manually. showactivated set "false" already. so, see 3 solutions:

1) somehow make topmost option not cause steal focus on .show()

2) use workaround make tooltip window "always on top" without topmost option (i don't need popup tooltip on fullscreen application since can (and be) drawed via d3d or opengl)

3) detect if system has fullscreen window in focus , don't try show tooltip.

i have no clue how fix behavior of options, or maybe there more elegant?

so... in case interested, here "research".

solution 1) failed. found few discussion behavior , says it's bug , others it's feature, of them assumes cannot solved in managed code. tried attempt sheridan's answer no luck.

solution 2) failed. have experience p/invoke fail if goes wrong. in particular case tried use

this.handle = new windowinterophelper(this).handle; setwindowpos(this.handle, hwnd_topmost, 0, 0, 0, 0, swp_showwindow | swp_noactivate | swp_nomove | swp_nosize); 

as suggested across web. code not show window. tried show with

showwindow(this.handle, 4); // tried show_normal , few other flags 

but window still not visible

it becames visible if this.visibility = /*visible*/ or this.show(), , see window topmost, not solve issue , fullscreen escapes. if knows how .show() works internally , how can show wpf window p/invoke, please let me know.

solution 3) succeed. found working code little googling here , shortened it:

    internal class fullscreencheck     {         [structlayout(layoutkind.sequential)]         private struct rect         {             public int left;             public int top;             public int right;             public int bottom;         }          [dllimport("user32.dll")]         private static extern intptr getforegroundwindow();         [dllimport("user32.dll")]         private static extern intptr getdesktopwindow();         [dllimport("user32.dll")]         private static extern intptr getshellwindow();         [dllimport("user32.dll", setlasterror = true)]         private static extern int getwindowrect(intptr hwnd, out rect rc);          // hope handles never changes         private static intptr hndldesktop = getdesktopwindow();         private static intptr hndlshell   = getshellwindow();          public static bool isfullscreen()         {             var hndlforeground = getforegroundwindow();             if (hndlforeground == null || hndlforeground == intptr.zero || hndlforeground == hndldesktop || hndlforeground == hndlshell)             {                 return false;             }              rect appbounds;             getwindowrect(hndlforeground, out appbounds);             var screenbounds = system.windows.forms.screen.fromhandle(hndlforeground).bounds;              return ((appbounds.bottom - appbounds.top) == screenbounds.height && (appbounds.right - appbounds.left) == screenbounds.width);         } 

so last step not call .show() if isfullscreen() == true


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -