Is there a way to detect when another app enters fullscreen?

Adam Gates 20 Reputation points
2024-01-29T04:34:29.49+00:00

I have an always on top application that I want to hide when another app enters fullscreen. Is there a way to detect this?

Windows development | Windows API - Win32
0 comments No comments
{count} votes

Accepted answer
  1. Gary Nebbett 6,216 Reputation points
    2024-01-30T14:48:06.3466667+00:00

    Hello Adam,

    Another technique might be to consume events generated by the Microsoft-Windows-Win32k provider in real-time, using a keyword filter such as UIUnresponsiveness or AutoRotation to reduce the number of irrelevant events reported. There are "Start" and "Stop" events for "ForegroundWindowFullScreen":

    User's image

    Update:

    Another option is to receive WM_SHELLHOOKMESSAGE messages (either by calling RegisterShellHookWindow or by hooking WH_SHELL messages); the HSHELL_ values for entering/leaving full screen appear to be 53/54 (undocumented values).

    User's image

    Gary

    1 person found this answer helpful.

4 additional answers

Sort by: Most helpful
  1. Jeanine Zhang-MSFT 11,356 Reputation points Microsoft External Staff
    2024-01-29T08:13:04.6+00:00

    Hello,

    Welcome to Microsoft Q&A!

    You could try to use SetWinEventHook function.

    In SetWinEventHook()’s callback, you could handle the EVENT_OBJECT_LOCATIONCHANGE event and check if the window is in maximized state by calling the GetWindowPlacement() function and comparing the showCmd property with the SW_SHOWMAXIMIZED constant.

    You could refer to the thread: https://stackoverflow.com/a/34549801

    Thank you.

    Jeanine


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

  2. RLWA32 49,551 Reputation points
    2024-01-29T16:41:23.17+00:00

    If you read Raymond Chen's article at How do I switch a window between normal and fullscreen? you can see that the procedure to switch a windows to Fullscreen does not maximize the window. Following images use Spy++ to demonstrate this - Maximized Window - Maximized

    Note that the taskbar is visible at the bottom of the screen and the window's caption bar is visible. Also, take a look at the various reported window rectangles. And now the same window switched to Fullscreen using as described in the article - FullScreen

    Note that the taskbar is not visible and the windows caption bar is not present. So it seems to me that you can use WinEvents to check if upon receiving EVENT_OBJECT_LOCATIONCHANGE the window's rectangle is identical to the dimensions of the monitor that is associated with the window. For the window discussed in the article you should also be able to check the window style to see that WS_OVERLAPPEDWINDOW is not present.

    0 comments No comments

  3. Olaf Helper 47,441 Reputation points
    2024-01-29T19:57:22.3366667+00:00

    I want to hide when another app enters fullscreen

    If an other application in fullscreen comes in focus, then it overlapp everything incl. your app; so what do you want to hide, no-one sees it anyway?


  4. Castorix31 90,686 Reputation points
    2024-01-30T07:32:29.9+00:00

    An old method is with DirectDraw (like the test I posted in this thread, mainly for DirectX app in Fullscreen : https://learn.microsoft.com/en-in/answers/questions/557345/determining-whether-game-mode-is-active) (not tested on Windows 11...)

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.