How do I disable edge gestures when my window is full screen?


A customer wanted to disable edge gestures when their program is running full screen. For example, you may want to do this if you are something like the Remote Desktop client, where you want all input (including the edge gestures) to be sent to the remote computer.

Fortunately, there's a property specifically designed for what you request. It goes by the devious name System.Edge­Gesture.Disable­Touch­When­Fullscreen.

Let's take it for a spin. Today's smart pointer library will be (rolls dice) Nothing! We're going with raw pointers today.

Start with the scratch program and make these changes:

#include <propsys.h>
#include <shellapi.h>
#include <propkey.h>
BOOL
OnCreate(HWND hwnd, LPCREATESTRUCT lpcs)
{
  SetTouchDisableProperty(hwnd, true);
  return 1;
}

This Set­Touch­Disable­Property helper function sets the property on the window's property store which says whether we want to disable touch edge gestures when the window is full screen. We set that property when we create the window.

void OnChar(HWND hwnd, TCHAR ch, int cRepeat)
{
  if (ch == '1') {
    HMONITOR hmon = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
    MONITORINFO mi = { sizeof(mi) };
    GetMonitorInfo(hmon, &mi);
    SetWindowLong(hwnd, GWL_STYLE, WS_POPUPWINDOW | WS_VISIBLE);
    SetWindowPos(hwnd, nullptr,
        mi.rcMonitor.left, mi.rcMonitor.top,
        mi.rcMonitor.right - mi.rcMonitor.left, mi.rcMonitor.bottom - mi.rcMonitor.top,
        SWP_FRAMECHANGED);
  }
}

  HANDLE_MSG(hwnd, WM_CHAR, OnChar);

When the user hits the 1 key, we go full screen by changing our style to WS_POPUP­WINDOW and changing our window size to match the monitor the window is on.

Okay, now take this program for a spin. It starts out in a normal non-fullscreen mode. Edge gestures are still active. Then press 1 to go full screen. Now edge gestures are inactive.

That's all.

Comments (5)
  1. skSdnW says:

    Missing include for tchar.h?

    You can close this window with Alt+F4 but I would prefer a full-screen toggle, something like this:

    void OnChar(HWND hwnd, TCHAR ch, int cRepeat)
    {
    if (ch == '1') {
    HMONITOR hmon = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST);
    MONITORINFO mi = { sizeof(mi) };
    GetMonitorInfo(hmon, &mi);
    static LONG orgStyle = ~0;
    static WINDOWPLACEMENT wp;
    wp.length = sizeof(wp);
    LONG style = GetWindowLong(hwnd, GWL_STYLE), fsStyle = WS_POPUPWINDOW | WS_VISIBLE;
    if (style & (orgStyle & ~(fsStyle|WS_CLIPSIBLINGS))) {
    orgStyle = style, GetWindowPlacement(hwnd, &wp);
    SetWindowLong(hwnd, GWL_STYLE, fsStyle);
    SetWindowPos(hwnd, nullptr,
    mi.rcMonitor.left, mi.rcMonitor.top,
    mi.rcMonitor.right - mi.rcMonitor.left, mi.rcMonitor.bottom - mi.rcMonitor.top,
    SWP_FRAMECHANGED);
    }
    else {
    SetWindowLong(hwnd, GWL_STYLE, orgStyle);
    SetWindowPlacement(hwnd, &wp);
    }
    }
    }

    1. Darran Rowe says:

      The header tchar.h isn't missing, TCHAR and TEXT are also defined in winnt.h, which is pulled in via windows.h.

      1. skSdnW says:

        I'm not sure this was always the case. windows.h would give you TEXT and LPTSTR and tchar.h has always given you TCHAR, _TEXT and _T.

        1. It's always been that way. Windows uses TCHAR, TEXT, LPTSTR. tchar.h uses _TCHAR, _TEXT, and _TCHAR*; it also defines other things like _TUCHAR and _TXCHAR. This makes sense because the C language standard reserves "underscore followed by capital letter" for the implementation, and tchar.h comes with the compiler.

  2. Neil says:

    Annoyingly you can't enjoy this article in a feed reader because you need to look up the linked helper function just to be able to understand the code.

Comments are closed.

Skip to main content