Skip to content

Commit 3d3451b

Browse files
committed
Initial repository population
Here goes the first version of TirtaWindows11ShowDesktopUtility !
1 parent 3082a1e commit 3d3451b

10 files changed

Lines changed: 341 additions & 0 deletions

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Delete the object folder
2+
obj/*
3+
4+
# Delete the binary folder
5+
bin/*
6+
7+
# Delete the Visual Studio files (./.vs)
8+
.vs/*

Program.cs

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Runtime.InteropServices;
6+
7+
8+
namespace TirtaWindows11ShowDesktopUtility
9+
{
10+
class Program
11+
{
12+
[DllImport("kernel32.dll")]
13+
static extern IntPtr GetConsoleWindow();
14+
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
15+
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
16+
[DllImport("user32.dll", EntryPoint = "SendMessage", SetLastError = true)]
17+
static extern IntPtr SendMessage(IntPtr hWnd, Int32 Msg, IntPtr wParam, IntPtr lParam);
18+
[DllImport("user32.dll")]
19+
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
20+
21+
/// <summary>
22+
/// Window Manager user32.dll IntPTR
23+
/// </summary>
24+
const int WM_COMMAND = 0x111;
25+
const int MIN_ALL = 419;
26+
const int MIN_ALL_UNDO = 416;
27+
28+
/// <summary>
29+
/// Hide selected window
30+
/// </summary>
31+
const int SW_HIDE = 0;
32+
33+
/// <summary>
34+
/// Show selected window
35+
/// </summary>
36+
const int SW_SHOW = 5;
37+
38+
/// <summary>
39+
/// String that will be written into the marker files, it's basically just a placeholder.
40+
/// </summary>
41+
const string StateMarkerContent = "Yo!";
42+
43+
/// <summary>
44+
/// Remmeber state in order to perform Show/Hide on the desktop.
45+
/// False = Hide Only, True = Hide and Show alternating.
46+
/// </summary>
47+
const Boolean RememberState = false;
48+
49+
/// <summary>
50+
/// Current Application directory.
51+
/// </summary>
52+
static string ApplicationPath = AppDomain.CurrentDomain.BaseDirectory;
53+
54+
static void Main(string[] args)
55+
{
56+
// Minimize the console app
57+
ShowWindow(GetConsoleWindow(), SW_HIDE);
58+
59+
if (args.Contains("--setup")) {
60+
// If there is a --setup argument
61+
62+
// Show the console app
63+
ShowWindow(GetConsoleWindow(), SW_SHOW);
64+
65+
// Make a marker that we are in setup mode
66+
try
67+
{
68+
// Create and Write a setup marker file
69+
System.IO.FileStream a = System.IO.File.Create(ApplicationPath + @"SetupMode.TW11SDU", Encoding.ASCII.GetByteCount(StateMarkerContent), System.IO.FileOptions.RandomAccess);
70+
a.Write(Encoding.ASCII.GetBytes(StateMarkerContent), 0, Encoding.ASCII.GetByteCount(StateMarkerContent));
71+
a.Flush();
72+
a.Dispose();
73+
}
74+
catch (Exception _)
75+
{
76+
Console.WriteLine("Got exception while trying to make setup marker, Exception message : " + _.Message);
77+
}
78+
79+
// Let user know the instructions
80+
Console.WriteLine("==== Currently Running in Setup Mode ====");
81+
Console.WriteLine("Setup Mode is unlocked, please re-run the exe by double-clicking.");
82+
Console.WriteLine("Don't forget to close this current instance, by pressing enter or clicking the 'X' button.");
83+
Console.WriteLine("\n\nAnother utility from 'TIRTAGT Developer' => https://github.com/TIRTAGT-DEV");
84+
Console.ReadLine();
85+
return;
86+
}
87+
else if (System.IO.File.Exists(ApplicationPath + @"SetupMode.TW11SDU"))
88+
{
89+
// Show the console app
90+
ShowWindow(GetConsoleWindow(), SW_SHOW);
91+
92+
// Delete the Setup marker, to avoid looping into the setup again and again.
93+
try
94+
{
95+
System.IO.File.Delete(ApplicationPath + @"SetupMode.TW11SDU");
96+
}
97+
catch (Exception _)
98+
{
99+
Console.WriteLine("Got exception while trying to delete setup marker, Exception message : " + _.Message);
100+
}
101+
Console.WriteLine("==== Currently Running in Setup Mode ====");
102+
Console.WriteLine("Please make a shortcut to run this app in order to minimize your window.");
103+
Console.WriteLine("After that, close this app by clicking the 'X' icon or pressing enter.");
104+
Console.WriteLine("\n\nAnother utility from 'TIRTAGT Developer' => https://github.com/TIRTAGT-DEV");
105+
Console.ReadLine();
106+
return;
107+
}
108+
109+
IntPtr lHwnd = FindWindow("Shell_TrayWnd", null);
110+
111+
// Check if the state marker file exist and we should Remember the state.
112+
if (System.IO.File.Exists(ApplicationPath + @"ReverseMode.TW11SDU") && RememberState)
113+
{
114+
// Instead of showing the desktop, show the foreground application application.
115+
SendMessage(lHwnd, WM_COMMAND, (IntPtr)MIN_ALL_UNDO, IntPtr.Zero);
116+
117+
// Delete the state marker, so that in the next execution, we will show the desktop.
118+
try
119+
{
120+
System.IO.File.Delete(ApplicationPath + @"ReverseMode.TW11SDU");
121+
}
122+
catch (Exception _)
123+
{
124+
Console.WriteLine("Got exception while trying to delete state marker, Exception message : " + _.Message);
125+
}
126+
// Quit the app instantly
127+
return;
128+
}
129+
else
130+
{
131+
// Show the desktop, and hide all current foreground application.
132+
SendMessage(lHwnd, WM_COMMAND, (IntPtr)MIN_ALL, IntPtr.Zero);
133+
134+
// If Remember state option was enabled.
135+
if (RememberState) {
136+
#pragma warning disable CS0162 // Ignore Unreachable code detected
137+
// Write a state marker so that in the next execution, we will bring all apps to foreground.
138+
try
139+
{
140+
System.IO.FileStream a = System.IO.File.Create(ApplicationPath + @"ReverseMode.TW11SDU", Encoding.ASCII.GetByteCount(StateMarkerContent), System.IO.FileOptions.RandomAccess);
141+
a.Write(Encoding.ASCII.GetBytes(StateMarkerContent), 0, Encoding.ASCII.GetByteCount(StateMarkerContent));
142+
a.Flush();
143+
a.Dispose();
144+
}
145+
catch (Exception _)
146+
{
147+
Console.WriteLine("Got exception while trying to create state marker, Exception message : " + _.Message);
148+
}
149+
#pragma warning restore CS0162 // Ignore Unreachable code detected
150+
}
151+
152+
// Quit the app instantly
153+
return;
154+
}
155+
}
156+
}
157+
}

Properties/AssemblyInfo.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("TirtaWindows11ShowDesktopUtility")]
9+
[assembly: AssemblyDescription("A simple Windows based utility to automatically close all foreground window app when executed.")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("TIRTAGT Developer")]
12+
[assembly: AssemblyProduct("TirtaWindows11ShowDesktopUtility")]
13+
[assembly: AssemblyCopyright("Copyright © 2021")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("501689be-7a9e-455a-98a6-cf66cddfa11f")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

README.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,57 @@
11
# TirtaWindows11ShowDesktopUtility
22
A simple Windows based utility to automatically close all foreground window app when executed.
3+
4+
----------
5+
6+
# Requirements
7+
- Visual C++ Redistributable (vcredist)
8+
- .NET Framework 4.0 or Higher.
9+
- atleast 20 KB of free disk space
10+
- atleast 10 MB of RAM free space
11+
12+
----------
13+
14+
# Releases :
15+
Per-version Source codes, Pre-built (ready to use) binary can be downloaded from the :
16+
[Github Releases](https://github.com/TIRTAGT-DEV/TirtaWindows11ShowDesktopUtility/releases)
17+
18+
----------
19+
20+
# Usage
21+
Show/Hide desktop via command prompt :
22+
`"X:/Path/To/The/Application/Show Desktop.exe"`
23+
24+
Show/Hide desktop via a shorcut :
25+
**Just double-click/click the shortcut.**
26+
27+
Show/Hide desktop by directly executing the app :
28+
**Double-click/click the "Show Desktop.exe"**
29+
30+
First setup, for creating shortcuts :
31+
`"X:/Path/To/The/Application/Show Desktop.exe" --setup`
32+
33+
----------
34+
35+
# First Setup guide
36+
1. Open up a command prompt and execute the app by :
37+
`"X:/Path/To/The/Application/Show Desktop.exe" --setup`
38+
39+
2. Close the command prompt by clicking the '**X**' or by pressing **Enter**.
40+
41+
3. Navigate to the application directory and manually run by double/single clicking it.
42+
43+
4. Right click the application in your taskbar, and select "**Pin to Taskbar**".
44+
45+
5. Close the current application by the '**X**' button or by pressing **Enter**.
46+
47+
6. Ready to use, the next execution to the app will show/hide the desktop !
48+
49+
----------
50+
51+
# First Setup Video Guide
52+
[Watch video on YouTube](https://www.youtube.com/watch?v=b8iH_F3YAXI)
53+
54+
----------
55+
56+
# Licenses
57+
[GNU General Public License v.3.0](https://github.com/TIRTAGT-DEV/TirtaWindows11ShowDesktopUtility/blob/production/LICENSE)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{501689BE-7A9E-455A-98A6-CF66CDDFA11F}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<RootNamespace>TirtaWindows11ShowDesktopUtility</RootNamespace>
10+
<AssemblyName>Show Desktop</AssemblyName>
11+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
12+
<FileAlignment>512</FileAlignment>
13+
<Deterministic>true</Deterministic>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<PlatformTarget>AnyCPU</PlatformTarget>
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<PlatformTarget>AnyCPU</PlatformTarget>
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<PropertyGroup>
35+
<StartupObject>TirtaWindows11ShowDesktopUtility.Program</StartupObject>
36+
</PropertyGroup>
37+
<PropertyGroup>
38+
<ApplicationIcon>win11_bg_dk.ico</ApplicationIcon>
39+
</PropertyGroup>
40+
<PropertyGroup>
41+
<NoWin32Manifest>true</NoWin32Manifest>
42+
</PropertyGroup>
43+
<ItemGroup>
44+
<Reference Include="System" />
45+
<Reference Include="System.Core" />
46+
<Reference Include="System.Xml.Linq" />
47+
<Reference Include="System.Data.DataSetExtensions" />
48+
<Reference Include="Microsoft.CSharp" />
49+
<Reference Include="System.Data" />
50+
<Reference Include="System.Xml" />
51+
</ItemGroup>
52+
<ItemGroup>
53+
<Compile Include="Program.cs" />
54+
<Compile Include="Properties\AssemblyInfo.cs" />
55+
</ItemGroup>
56+
<ItemGroup>
57+
<Content Include="win11_bg_dk.ico" />
58+
</ItemGroup>
59+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
60+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.31515.178
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TirtaWindows11ShowDesktopUtility", "TirtaWindows11ShowDesktopUtility.csproj", "{501689BE-7A9E-455A-98A6-CF66CDDFA11F}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{501689BE-7A9E-455A-98A6-CF66CDDFA11F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{501689BE-7A9E-455A-98A6-CF66CDDFA11F}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{501689BE-7A9E-455A-98A6-CF66CDDFA11F}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{501689BE-7A9E-455A-98A6-CF66CDDFA11F}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {ADA14699-DC4F-4D96-B122-0053EB056035}
24+
EndGlobalSection
25+
EndGlobal

icon/win11_bg_dk.ico

4.19 KB
Binary file not shown.

icon/win11_bg_dk.png

54.5 KB
Loading

icon/win11_bg_dk.psd

182 KB
Binary file not shown.

win11_bg_dk.ico

4.19 KB
Binary file not shown.

0 commit comments

Comments
 (0)