Processing Ajax...

Title

Message

Confirm

Confirm

Confirm

Confirm

Are you sure you want to delete this item?

Confirm

Are you sure you want to delete this item?

Toggle Borders and Caption From Window

Description
Toggles the borders and caption from a window on and off, and resizes the client window to the appropriate size.
Language
C#.net
Minimum Version
Created By
Thomas Malloch (BFS)
Contributors
enteleform
Date Created
Mar 18, 2015
Date Last Modified
Dec 4, 2017

Scripted Function (Macro) Code

//##  Default (DisplayFusion)  ##//
using System;
using System.Data;
using System.Drawing;
using System.Management;
using System.Web;
using System.Windows.Forms;
using System.Xml;

//##  Default  ##//
using System.Runtime.InteropServices;


public static class DisplayFusionFunction{

/*#####################################################################################################################################################################################################################################################################################################~{*/
/*//////|   Run   |////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////g2*/
/*#####################################################################################################################################################################################################################################################################################################~}*/

  public static void Run(IntPtr windowHandle){
    if(verify_IgnoredWindow(windowHandle))
      {return;}

    if(! verify_IgnoredStyleWindow(windowHandle)){
      remove_Border  (windowHandle);
      maximize_Window(windowHandle);
    }
    else
      {BFS.Window.Maximize(windowHandle);}

  }

/*#####################################################################################################################################################################################################################################################################################################~{*/
/*//////|   Ignored Windows   |/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////g2*/
/*#####################################################################################################################################################################################################################################################################################################~}*/

  static string[] IGNORED_WINDOW_CLASSES = new string[]{
    //##  System  ##//
    "MultitaskingViewFrame",        //  Windows Alt-Tab & Win-Tab Screens
    "Progman",                      //  Windows Desktop
    "WorkerW",                      //  Windows Desktop
    "ApplicationFrameWindow",       //  Windows Settings
    "Windows.UI.Core.CoreWindow",   //  Windows System Menus
    "NotifyIconOverflowWindow",     //  Windows System Tray
    "TaskManagerWindow",            //  Windows Task Manager
    "Shell_TrayWnd",                //  Windows Taskbar
    "TaskListThumbnailWnd",         //  Windows Taskbar Thumbnail
    //##  Apps  ##//
    "ClassicShell.CMenuContainer",  //  ClassicStart
    "ExplorerBrowserOwner",         //  Fences
    "WMP Skin Host",                //  Windows Media Player Visualizer
    "CWmpControlCntr",              //  Windows Media Player Visualizer (Full-Screen)
  };

  static string[] IGNORED_WINDOW_STYLE_CLASSES = new string[]{
    //##  System  ##//
    "CabinetWClass",       //  Windows File Explorer
    //##  Apps  ##//
    "GomPlayer1.x",        //  GOM Player
    "Chrome_WidgetWin_1",  //  Google Chrome
    "ThunderRT6Main",      //  XYplorer
    "ThunderRT6FormDC",    //  XYplorer
  };

/*#####################################################################################################################################################################################################################################################################################################~{*/
/*//////|   Utils   |////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////g2*/
/*#####################################################################################################################################################################################################################################################################################################~}*/

  static bool verify_IgnoredWindow(IntPtr windowHandle){
    string windowClass = BFS.Window.GetClass(windowHandle);
    return (Array.IndexOf(IGNORED_WINDOW_CLASSES, windowClass) >= 0);
  }

  static bool verify_IgnoredStyleWindow(IntPtr windowHandle){
    string windowClass = BFS.Window.GetClass(windowHandle);
    return (Array.IndexOf(IGNORED_WINDOW_STYLE_CLASSES, windowClass) >= 0);
  }

  static BFS.WindowEnum.WindowStyle[] borderedWindowStyles = new BFS.WindowEnum.WindowStyle[]{
    BFS.WindowEnum.WindowStyle.WS_CAPTION,
    BFS.WindowEnum.WindowStyle.WS_SYSMENU,
    BFS.WindowEnum.WindowStyle.WS_THICKFRAME__SIZEBOX,
    BFS.WindowEnum.WindowStyle.WS_MINIMIZEBOX,
    BFS.WindowEnum.WindowStyle.WS_MAXIMIZEBOX,
  };

  static void remove_Border(IntPtr windowHandle){
    BFS.WindowEnum.WindowStyle style = BFS.Window.GetWindowStyle(windowHandle);
    foreach(BFS.WindowEnum.WindowStyle subStyle in borderedWindowStyles)
      {style &= ~subStyle;}
    BFS.Window.SetWindowStyle(style, windowHandle);
  }

  static void maximize_Window(IntPtr windowHandle){
    Rectangle monitor = BFS.Monitor.GetMonitorBoundsByWindow(windowHandle);
    SetWindowPos(windowHandle, 0, monitor.X, monitor.Y, monitor.Width, monitor.Height, (SWP_NOZORDER | SWP_SHOWWINDOW));
  }

  [DllImport("user32.dll")]
  static extern IntPtr SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int cx, int cy, int wFlags);
  const short SWP_NOZORDER   = 0x4;
  const int   SWP_SHOWWINDOW = 0x0040;

}//  /DisplayFusionFunction