?
Solved

C# winform, How to register to events when other applications enter/exit full screen mode on my application screen (if multiscreens)

Posted on 2010-09-10
5
Medium Priority
?
800 Views
Last Modified: 2012-05-10
I have C# winforms application. It has to register to events when any other application enters or exits full-screen-mode, on same screen (if independent multi-screen, I dont care what occurs on the other screens).

URL http://www.richard-banks.org/2007/09/how-to-detect-if-another-application-is.html
presents an idea, but I am not expert to code it, and besides, it needs looping to sense, while I prefer to register to events.

I'd appreciate to get C# code for this.

With appreciation

Michael
0
Comment
Question by:michael-lev
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 

Author Comment

by:michael-lev
ID: 33647410
If ther are no adequate events, then I'd like to get method code for my application to sense whether some other application is running full screen on same screen, and I'll call it from time to time.
0
 

Author Comment

by:michael-lev
ID: 33647497
-- I mean detecting if the other application is in TRUE fullscreen (not only maximized).
-- some links are in URL:   http://stackoverflow.com/questions/3536373/detect-if-user-has-any-application-running-in-fullscreen
0
 
LVL 10

Accepted Solution

by:
james-ct16 earned 2000 total points
ID: 33661414
Good evening

There is no simple solution to this problem however this might get you headed in the correct direction.

The following code provides to examples the first should be sufficient to detect presentation mode.

To test this simply add a timer to an existing form with a message box and stick power point into presentation mode and message boxes will start appearing.

The next approach you can take to aid this is use the native GetWindowPlacement in user32 this provides the WindowPlacement structure which lets us detect window state (gets your maximized state) however more interestingly it also gets where the control is drawn so if the controls width and height is the size of the screen resolution you have a full screen app, try this with ie or chrome.  Second set of methods provide an example of this.

I suspect you are going to find cases where this doesnt always play fair and will have to deal with those on a case by case basis.

Hope that helps

James
[DllImport("kernel32.dll", SetLastError = true)]
static extern IntPtr OpenFileMapping(uint dwDesiredAccess, bool bInheritHandle, string lpName);

[Flags]
public enum FileMapAccess : uint
{
    FileMapCopy = 0x0001,
    FileMapWrite = 0x0002,
    FileMapRead = 0x0004,
    FileMapAllAccess = 0x001f,
    fileMapExecute = 0x0020,
}

[DllImport("kernel32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool CloseHandle(IntPtr hObject);

/// <summary>
/// Determines whether [is in presentation mode].
/// </summary>
/// <returns>
/// 	<c>true</c> if [is in presentation mode]; otherwise, <c>false</c>.
/// </returns>
public bool IsInPresentationMode()
{
    IntPtr hHandle;

    hHandle = OpenFileMapping((uint)FileMapAccess.FileMapRead, false, "Local\\FullScreenPresentationModeInfo");

    if (IntPtr.Zero == hHandle) 
    { 
        return false; 
    }

    CloseHandle(hHandle);
    return true;
}

// Second Example
        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        static extern bool GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);

        private struct WINDOWPLACEMENT
        {
            public int length;
            public int flags;
            public int showCmd;
            public System.Drawing.Point ptMinPosition;
            public System.Drawing.Point ptMaxPosition;
            public System.Drawing.Rectangle rcNormalPosition;
        }

        const UInt32 SW_HIDE = 0;
        const UInt32 SW_SHOWNORMAL = 1;
        const UInt32 SW_NORMAL = 1;
        const UInt32 SW_SHOWMINIMIZED = 2;
        const UInt32 SW_SHOWMAXIMIZED = 3;
        const UInt32 SW_MAXIMIZE = 3;
        const UInt32 SW_SHOWNOACTIVATE = 4;
        const UInt32 SW_SHOW = 5;
        const UInt32 SW_MINIMIZE = 6;
        const UInt32 SW_SHOWMINNOACTIVE = 7;
        const UInt32 SW_SHOWNA = 8;
        const UInt32 SW_RESTORE = 9;

        /// <summary>
        /// Determines whether [is window full screen] [the specified win handle].
        /// </summary>
        /// <param name="winHandle">The win handle.</param>
        /// <returns>
        /// 	<c>true</c> if [is window full screen] [the specified win handle]; otherwise, <c>false</c>.
        /// </returns>
        private bool IsWindowFullScreen(IntPtr winHandle)
        {
            WINDOWPLACEMENT placement = new WINDOWPLACEMENT();
            placement.length = Marshal.SizeOf(placement);
            GetWindowPlacement(winHandle, ref placement);
            // perform screen size calculation
            // screen calculation does not account for multi monitors when full screen left of primary display
            if (placement.rcNormalPosition.Width == Screen.FromHandle(winHandle).Bounds.Width
                && placement.rcNormalPosition.Height == Screen.FromHandle(winHandle).Bounds.Height)
            {
                return true;
            }

            return false;
        }

private void FindFullScreenWindows()
{foreach (Process p in Process.GetProcesses("."))
            {
                try
                {                   
                    if (p.MainWindowTitle.Length > 0 && IsWindowFullScreen(p.MainWindowHandle))
                    {
                        Debug.WriteLine("Full Screen Window Title:" + p.MainWindowTitle.ToString());
                    }
                }
                catch { }
            }
}

Open in new window

0
 
LVL 74

Expert Comment

by:Glen Knight
ID: 34850236
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows 10 Creator Update has just been released and I have it working very well on my laptop. Read below for issues, fixes and ideas.
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question